Showing posts with label Aspire assignment. Show all posts
Showing posts with label Aspire assignment. Show all posts

Tuesday, 22 November 2011

TCS ASPIRE JAVA ASSIGNMENT - ANSWERS


1.
Program:

import java.io.*;
importjava.util.Scanner;
class Difference
{
publicstaticvoid main(String args[]) throwsIOException
{
Scanner s=newScanner(System.in);
System.out.println("Enter the value of n: ");
int n=s.nextInt();
int a[]=newint[n];
int i, sqr, diff, sum=0, add=0;
System.out.print("The "+n);
System.out.println(" numbers are : ");
for(i=0;i<n;i++)
{
a[i]=s.nextInt();
sum+=(a[i]*a[i]);
add+=a[i];
}
sqr=add*add;
diff=sqr-sum;
System.out.println("");
System.out.print("Sum of Squares of given "+n);
System.out.println(" numbers is : "+sum);
System.out.print("Squares of Sum of given "+n);
System.out.println(" numbers is : "+sqr);
System.out.println("");
System.out.println("Difference between sum of the squares and the square of the sum of given "+n);
System.out.print(" numbers is : "+diff);
System.out.println("");
}
}
Out put:

Enter the value of n:
3
The 3 numbers are :
2
3
4



Sum of Squares of given 4 numbers is : 29
Squares of Sum of given 4 numbers is : 81

Difference between sum of the squares and the square of the sum of given 4
numbers is : 52










2.
Program:

importjava.util.Scanner;


publicclassCalculateSquarePeri
{

/**
* @paramargs
*/
publicstaticvoid main(String[] args)
{

Scanner s=newScanner(System.in);
System.out.println("Area of Square : ");
double a=s.nextDouble();
double p=4*Math.sqrt(a);
System.out.println("");
System.out.print("Perimeter of the Square : "+p);
System.out.println("");
}


}


Output:

Enter the area:
23
Perimeter of the square is: 19.183326093250876











3.
Program:

import java.io.*;
importjava.util.Scanner;
classcalculateCylinderVolume
{
publicstaticvoid main(String args[]) throwsIOException
{
Scanner s=newScanner(System.in);
System.out.println("Enter the radius : ");
double rad=s.nextDouble();
System.out.println("Enter the height : ");
doubleht=s.nextDouble();
doublevol=Math.PI*rad*rad*ht;
System.out.println("");
System.out.println("Volume of the cylinder is : " + vol);
}
}


Output:

Enter the radius :
12
Enter the height :
13

Volume of the cylinder is : 5881.061447520093



4.
Program:

importjava.util.Scanner;


publicclasscalculateTax {

/**
* @paramargs
*/
publicstaticvoid main(String[] args)
{
Scanner s=newScanner(System.in);
System.out.println("Enter the no. of working days in the year : ");
int d=s.nextInt();
System.out.println("Enter the no. of working hours in a day : ");
int h=s.nextInt();
System.out.println("Enter the no. of hours worked in over time : ");
intot=s.nextInt();
System.out.println("Enter the no. of hours took leave : ");
int l=s.nextInt();
double gross=((d*h)+ot-l)*12;
double tax= gross*0.15;
double net=gross-tax;
System.out.println("");
System.out.println("Gross Pay (in $) : "+gross);
System.out.println("Tax (in $) : "+tax);
System.out.println("Net Pay (in $) : "+net);

}


}



Output:

Days worked by employer in a year :
300
Enter the no. of working hours in a day :
6
Enter the no. of hours worked in over time :
1
Enter the no. of hours took leave :
1560

Gross Pay (in $) : 2892.0
Tax (in $) : 433.8
Net Pay (in $) : 2458.2






5.


Program:
importjava.util.Scanner;


publicclasscalculateTotalProfit
{

/**
* @paramargs
*/
publicstaticvoid main(String[] args)
{
Scanner s = newScanner(System.in);
System.out.println("Enter the no. of attendees of a show : ");
int n=s.nextInt();
double profit = (n*5)-(20+(n*0.5));
System.out.println("");
System.out.println("Total Profit of the theater per show (in $) is : " + profit);
}


}
Output:
Enter the no. of attendees per show :
50

Total Profit of the theater per show (in $) is : 205.0







6.
Program:

importjava.util.Scanner;


publicclasscalculateCylinderArea
{

/**
* @paramargs
*/
publicstaticvoid main(String[] args)
{
Scanner s=newScanner(System.in);
System.out.println("Enter the base radius : ");
double rad=s.nextDouble();
System.out.println("Enter the height : ");
doubleht=s.nextDouble();
double area=2*Math.PI*rad*(rad+ht);
System.out.println("");
System.out.println("Surface Area of the cylinder is : " + area);
}

}


Output:

Enter the base radius :
12
Enter the height :
13

Surface Area of the cylinder is : 1884.9555921538758




7.

Program:

importjava.util.Scanner;


publicclasscalculatePipeArea
{

/**
* @paramargs
*/
publicstaticvoid main(String[] args)
{
Scanner s=newScanner(System.in);
System.out.println("Enter the inner radius : ");
double rad=s.nextDouble();
System.out.println("Enter the length : ");
doublelen=s.nextDouble();
System.out.println("Enter the thickness : ");
double thick=s.nextDouble();
double area=2*Math.PI*(rad+thick)*len;
System.out.println("");
System.out.println("Surface Area of the pipe is : " + area);

}


}


Output:

Enter the inner radius :
13
Enter the length :
20
Enter the thickness :
5

Surface Area of the pipe is : 2261.946710584651 




8.
importjava.util.Scanner;


publicclasscalculateHeight {

/**
* @paramargs
*/
publicstaticvoid main(String[] args) {
Scanner s=newScanner(System.in);
System.out.println("Enter the time (in seconds) : ");
double t=s.nextDouble();
double v=9.8*t;
double height=0.5*v*t;
System.out.println("");
System.out.println("Height reached (in meters) is : " + height);


}

}


Output:

Enter the time (in seconds) :
300

Height reached (in meters) is : 441000.0





9.
importjava.util.Scanner;


publicclassBoatDistance
{

/**
* @paramargs
*/
publicstaticvoid main(String[] args)
{
Scanner s= newScanner(System.in);
System.out.println("Enter the width of the river (in meters) : ");
doublerw=s.nextDouble();
System.out.println("Enter the river's speed (in meter/sec) : ");
doublers=s.nextDouble();
System.out.println("Enter the boat's speed (in meter/sec) : ");
doublebs=s.nextDouble();
double time=rw/bs; //time takes to travel from shore to shore straight by the boat
double w2=time*rs; //distance due to down stream
doublebd=Math.sqrt((rw*rw)+(w2*w2));
System.out.println("");
System.out.println("The distance travelled by boat (in meters) is : "+bd);
}


}


Output:

Enter the width of the river (in meters) :
15
Enter the river's speed (in meter/sec) :
200
Enter the boat's speed (in meter/sec) :
250

The distance travelled by boat (in meters) is : 19.209372712298546



10.
Program:

importjava.util.Scanner;


publicclasscalculateBalance {

/**
* @paramargs
*/
publicstaticvoid main(String[] args)
{
Scanner s=newScanner(System.in);
System.out.println("Enter the principal amount : ");
double p=s.nextDouble();
System.out.println("Enter the annual interest rate : ");
double r=s.nextDouble();
System.out.println("Enter the no. of months : ");
double m=s.nextDouble();
doublesi=(p*(m/12)*r)/100;
doublebal=p+si;
System.out.println("");
System.out.print("Balance after " +(int)m);
System.out.println(" month(s) is : "+bal);
}


}

Output:

Enter the principal amount :
15000
Enter the annual interest rate :
12
Enter the no. of months :
24

Balance after 24 month(s) is : 18600.0






You may also like this :

TCS ILP JAVA QUIZ ANSWERS


Saturday, 5 November 2011

communication quiz vocabulary activity- TCS pre - ilp Aspire assignment


communication quiz answers - TCS pre - ilp Aspire assignment

These are the communication quizzes answers.I hope you can crack it by your own.Its just for your reference.Thanks to my friend and ilp community for this.

























DBMS TCS pre-ilp Assignment




My friend was preparing for his aspire assignments , he informed me that this materials would help many students.Thanks to my friend and ilp community.This material i hope will inculcate a good idea for creating your own answers.The material provided is only for idea gathering purpose only.Please dont try to mimic the answers,because  i believe you can come with with even more efficient answers.




Question 1:
Provide the create table syntax to Create a Table Employee whose details are as below.Employee(EmployeeID,
LastName, FirstName, Address, DateHired)

Ans: create table Employee(  EmployeeID int(6) primary key,LastName varchar(20),FirstName varchar(20),Address varchar2(50),datehired date );


Question 2:
Provide the INSERT query to be used in Employee Table to fill the Details.
ANS: Insert into Employee values( 100,'gourav','kishan','hyderabad','15-aug-45');



Question 3:
When we give SELECT * FROM EMPLOYEE .How does it Respond?
Ans: when we type the following query of select * from employee it returns all the data present that is all the columns in employee table. In this case it shows the above value in the insert statement.


Question 4:
 Create a Table CLIENT whose details are as below.
 Client(ClientID, LastName, FirstName, Balance, EmployeeID)
 ANS:create table Client(ClientID int(6), LastName varchar(20), FirstName varchar(20), Balance float(10) , EmployeeID foreign key references Employee(EmployeeID));
  NOTE: INCASE IF WE USE BOTH EMP AND CLIENT TABLE IN 1 DB..OR HAS A RELATION FOREIGN KEY OR NOT NULL AND REFERENCES ARE REQUIRED ELSE NO NEEDED.



Question 5:
Provide the INSERT query to be used in CLIENT Table to fill the Details.
 ANS:INSERT INTO Client
      values(&ClientID,'&LastName','&FirstName','&Address', &EmployeeId);


Question 6:
When we give SELECT * FROM CLIENT .How does it Respond?
ANS: It returns all the rows and columns present in the client table . that is it shows all the field data of client table.


Question 7: Choose the correct answer. The SQL command to create a table is:

 a. Make Table

 b. Alter Table
  c. Define Table

 d. Create Table

Ans : D


Question 8:
Choose the correct answer. The DROP TABLE statement:

 a. deletes the table structure only

 b. deletes the table structure along with the table data

 c. works whether or not referential integrity constraints would be violated

 d. is not an SQL statement

 ANS: b


Question 9:
What are the different data types available in SQL server?
Ans:
    1) Numeric        : Stores numeric values.
    2) Monetary       : It stores numeric values with decimal
                     places. It is used specially for currency values.
    3) Date and Time  : It stores date and time information.
    4) Character      : It supports character based values of
                                   varying lengths.
    5) Binary         : It stores data in strict binary (0 or 1)
                               representation.
    6) Special purpose: SQL Server contains Complex data
        types to handle the XML Documents,Globally unique
        identifiers etc.


Question 10:
Which is the subset of SQL commands used to manipulate Oracle Database structures, including tables?
 ANS: DDL( Data Deifinition Language).



Question 11:
What operator performs pattern matching?

ANS: LIKE Operator.


Question 12:
What operator tests column for the absence of data?
 ANS: IS NULL Operator.


Question 13:
Which command executes the contents of a specified file?
  ANS: START or @ command.


Question 14:
What is the parameter substitution symbol used with INSERT INTO command?
 ANS: '&' commonly known as amperescent operator.


Question 15:
Which command displays the SQL command in the SQL buffer, and then executes it?
  ANS: RUN.


 Question 16:
 What are the wildcards used for pattern Matching?
  ANS: _ and %
   _  = single character substitution .
   % = multiple character substitution.
[CHARLIST] = any single charecter in CHARLIST
^[CHARLIST] = any single charecter NOT in CHARLIST


 Question 17: State whether true or false.

 EXISTS, SOME, ANY are operators in SQL.
   ANS: TRUE.


 Question 18: State whether true or false.

 !=, <>, ^= all denote the same operation.
  ANS: TRUE.


Question 19: What are the privileges that can be granted on a table by a user to others?
 Ans: Insert, update, delete, select, references, index, execute, alter, all


Question 20:
What command is used to get back the privileges offered by the GRANT command?
 ANS: REVOKE.


Question 21:
Which system tables contain information on privileges granted and privileges obtained?
 ANS : USER_TAB_PRIVS_MADE,
           USER_TAB_PRIVS_RECD .


Question 22:
Which system table contains information on constraints on all the tables created?
 ANS: USER_CONSTRAINTS.


Question 23:
What is the difference between TRUNCATE and DELETE commands?
 ANS:  1.Delete is a DML command and Truncate is a
              DDL  command.
           2.Where clause can be used with delete only.
           3.THE Delete operation can be rolled back, Truncate operation cant be rolled back again that is it is a permanent delete.


Question 24:
What command is used to create a table by copying the structure of another table?

ANS: CREATE TABLE .. AS SELECT command



Basics of programming - Aspire Assignment


My friend was preparing for his aspire assignments , he informed me that this materials would help many students.Thanks to my friend and ilp community.This material i hope will inculcate a good idea for creating your own program.The material provided is only for idea gathering purpose only.Please dont try to mimic the programs,because  i believe you can write even more efficient programs.


QUESTION 1:NAME FINDING PROGRAM


Search for a name

Write a program to accept an array of names and a name and check whether the

name is present in the array. Return the count of occurrence. Use the following

array as input

{“Dave”, “Ann”, “George”, “Sam”, “Ted”, “Gag”, “Saj”, “Agati”, “Mary”, “Sam”,

“Ayan”, “Dev”, “Kity”, “Meery”, “Smith”, “Johnson”, “Bill”, “Williams”, “Jones”,

“Brown”, “Davis”, “Miller”, “Wilson”, “Moore”, “Taylor, “Anderson”, “Thomas”,

“Jackson”}



import java.io.*;
import java.util.StringTokenizer;
public class namefinding
{
 public static void main(String args[])throws Exception
{
 InputStreamReader isr=new InputStreamReader(System.in);
 BufferedReader br=new BufferedReader(isr);
System.out.println(".........................WELCOME TO THE NAME FINDING PROGRAM.......................");
System.out.println("enter names by using space inbetween:");
String arrNames=br.readLine();
StringTokenizer st1=new StringTokenizer(arrNames);
System.out.println("enter the name to be searched:");
String name=br.readLine();
int countNoOccurance=0;
while(st1.hasMoreTokens())
{
if(name.equalsIgnoreCase(st1.nextToken()))
{
countNoOccurance++;
}
}
System.out.println("THE NAME "+name+" HAS APPEARED "+countNoOccurance+" TIMES");
}
}



IMPROVE UNDERSTANDABILITY OF THE BELOW GIVEN CODE:


import java.util.*;

class problem3
{

int[] numArray=new int[10];  //an array named numarray is assigned containing 10 elements

public static void incrementElements (int[] integerArray) //the function is static it can be activated either by using class name or by an object. Passing array of integers as an argument

{
int arraylen = integerArray.length;//the array length is calculated using integerArray.length

for (int i = 0; i < arraylen; i ++)

{

System.out.println(integerArray[i]);

}

for (int i = 0; i < arraylen; i ++)//Using for loop we set a loop from 0 to the obtained length of the array

{

integerArray[i] = integerArray[i] + 10;//The present integer value is incremented, by a value of 10

}

for (int i=0; i < arraylen; i ++) // result is displayed using an array


{


System.out.println(integerArray[i]);


}


}







QUESTION 2:


Greatest common divisor

Calculate the greatest common divisor of two positive numbers a and b.

gcd(a,b) is recursively defined as

gcd(a,b) = a if a =b

gcd(a,b) = gcd(a-b, b) if a >b

gcd(a,b) = gcd(a, b-a) if b > a


import java.io.*;
import java.util.Scanner;
class gcdfinder
{
 public static void main(String args[])
   {
Scanner sr= new Scanner(System.in);
System.out.println("................welcome to the gcd finder program...................................");
     System.out.println("Enter the value for a");
     int a=sr.nextInt();
  System.out.println("Enter the value for b");
  int b=sr.nextInt();
  int gcd;
  if(a==b)
     gcd=a;
  else if(a>b)
     gcd=findgcd(a-b,b);
  else
     gcd=findgcd(b,b-a);
  System.out.println("The greatest common divisor of numbers " + a + " and " + b + " is " + gcd);
System.out.println("Thanks for executing the program");
    }
 public static int findgcd(int c,int d)
  {
  if (d == 0)
     return c;
  return findgcd(d, c % d);
  }
  }




IMPROVE UNDERSTANDABILITY:



class Problem1 //class name is problem1

{

int[] a;

int nElems;

public ArrayBub(int max)

{

a = new int[max];

}

public void insert(int value)

{

a[nElems] = value;

nElems++;

}

public void Sort() //sorting is done like bubble sort algorithm

{

int out, in;

for(out=nElems-1; out>1; out--)

for(in=0; in<out; in++)

if( a[in] > a[in+1] ) // comparing  one number with another.

swap(in, in+1); }

public void swap(int one, int two) //swapping takes place

{

long temp = a[one];

a[one] = a[two];

a[two] = temp;

}


Related Posts Plugin for WordPress, Blogger...