Showing posts with label aspire assignments. Show all posts
Showing posts with label aspire assignments. Show all posts

Monday, 28 May 2012

WEB TECHNOLOGY ASSIGNMENT 1


Create a free account in www.4shared.com and download the file from the below mentioned link and upload it in Aspire portal :-)

The link for online shopping portal http://www.4shared.com/file/iiTMJTtk/online_shopping_portal_windows.html

Friends, if u cant able to download from the above link ,try with this https://sites.google.com/site/tcsassignmentsgcek/webtecassignment/Shopping_portal.zip?attredirects=0&d=1
Put the above link in your address bar and press enter.. hope u ll get 

Saturday, 5 May 2012

INTRODUCTION TO JAVA BASICS -ASSIGNMENT 1


1. Write a program to find the difference between sum of the squares and the square of the sums of n numbers?
Solution:
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("");
}
}
Output:
Enter the value of n: 4
The 4 numbers are :
2
3
4
5
Sum of Squares of given 4 numbers is : 54
Squares of Sum of given 4 numbers is : 196
Difference between sum of the squares and the square of the sum of given 4
numbers is : 142


2. Develop a program that accepts the area of a square and will calculate its perimeter.
Solution:
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. Develop the program calculate Cylinder Volume., which accepts radius of a cylinder's base disk and its height and computes the volume of the cylinder.
Solution:
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. Utopias tax accountants always use programs that compute income taxes even though the tax rate is a solid, never-changing 15%. Define the program calculateTax which determines the tax on the gross pay. Define calculateNetPay that determines the net pay of an employee from the number of hours worked. Assume an hourly rate of $12.
Solution:
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. An old-style movie theater has a simple profit program. Each customer pays $5 per ticket. Every performance costs the theater $20, plus $.50 per attendee. Develop the program calculateTotalProfit that consumes the number of attendees (of a show) and calculates how much income the show earns.
Solution:
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. Develop the program calculateCylinderArea, which accepts radius of the cylinder's base disk and
its height and computes surface area of the cylinder.


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. Develop the program calculatePipeArea. It computes the surface area of a pipe, which is an open cylinder. The program accpets three values: the pipes inner radius, its length, and the thickness of its wall.
Solution:
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. Develop the program calculateHeight, which computes the height that a rocket reaches in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g • t in t time units and a height of 1/2 * v * t where v is the speed at t.
Solution:
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. Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time, and the Pythagorean Theorem is c2 = a2 + b2.
Solution:
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. Develop a program that accepts an initial amount of money (called the principal), a simple annual interest rate, and a number of months will compute the balance at the end of that time. Assume thatno additional deposits or withdrawals are made and that a month is 1/12 of a year. Total interest is the product of the principal, the annual interest rate expressed as a decimal, and the number of years.
Solution:
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

BASICS OF PROGRAMMING ASSIGNMENT 1


Question 1a
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”}

SOLUTION:
import java.io.*;
class program1
 {
 public static void main(String args[])
 {
 String[] names={“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”};
System.out.println("Enter a name to check");
InputStreamReader Inp=new InputStreamReader(System.in);
BufferedReader Br=new BufferedReader(Inp);
String name=Br.readLine();
 int count=0;
 for(int i=0;i<names.length;i++)
 {
 if(names[i].equals(name))
 count++;
 }
 if(count!=0)
 System.out.println("The Number of occurance of the Name is " + count );
 else
 System.out.println("Word not Found");
 }
 }
Output :
C:\Program Files\Java\jdk1.6.0_22\bin>javac program1.java
C:\Program Files\Java\jdk1.6.0_22\bin>java program1
 Enter a name to check
 Sam
The Number of occurance of the Name is 2


Question 1 b
Improve the understandability of the below given code:
The code below takes an array of 10 integer values as an argument,prints its values,increments it by 10 and again prints the incremented value
import java.util.*; 
        //importing the required packages
class problem3 
       //creating a class
{
int[] numArray = new int[10];
       // allocating memory to 10 integer elements in an array named 'numArray'
public static void incrementElements (int[] integerArray) 
      //defining the 'incrementElements()' method with one integer type array 'integerArray' as the parameter
{
int arraylen = integerArray.length;
      // initializing an integer variable 'arraylen' with the length, i.e. the no of elements in array
for (int i = 0; i < arraylen; i ++)
      //definition of 'for' loop to print the current values of array
{
System.out.println(integerArray[i]);
}
for (int i = 0; i < arraylen; i ++)
        //definition of 'for' loop to increment the current values of array
{
integerArray[i] = integerArray[i] + 10; //add 10 to each value of array
}
for (int i=0; i < arraylen; i ++)
      //definition of 'for' loop to print the updated values of array
{
System.out.println(integerArray[i]);
}
}  //class closes


Question 2a
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


Solution :
import java.io.*;
class findgcd
{ 
 int gcd(int a,int b)
 { 
            if(a==b)
             return a;
          else if(a>b)
           return(gcd(a-b,b));
           else
           return(gcd(a,b-a));
       }
  }
 class gcdtest1
  {
 public static void main(String arr[]) throws IOException
      {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
         System.out.println("Enter a::");
         int a=Integer.parseInt(br.readLine());
         System.out.println("Enter b::");
         int b=Integer.parseInt(br.readLine());
          findgcd g=new findgcd();
          System.out.println("Gcd of a and b is::"+g.gcd(a,b));
}
  }

Output:
C:\Program Files\Java\jdk1.6.0_22\bin>javac gcdtest1.java
C:\Program Files\Java\jdk1.6.0_22\bin>java gcdtest1
 Enter a::
 36
 Enter b::
 24
 Gcd of a and b is:: 12


Question 2b
Improve the understandability of the below given code:
The code explains BUBBLE SORT implentation.
class Problem1
     //creating a new class
{
int[] a; //declaring a new array 'a' of integer type to store the numbers
int nElems; //declaring an integer variable 'nElems' to hold no of elements in the array
public ArrayBub(int max) 
       //defining a new parameterised method to initialize the array with 'max' as size of the array
  {
   a = new int[max];
  }
public void insert(int value)  //defining  the insert method to insert values in the array
{
a[nElems] = value;  //assigning the value to array at current position
nElems++; //incrementing the position counter
}
public void Sort()   //defining the method to sort the array
{
int out, in;  // declaring two integer variables 'out' & 'in'
for(out=nElems-1; out>1; out--) //outer loop
for(in=0; in<out; in++) //inner loop
if( a[in] > a[in+1] ) //conditional statement to compare the adjacent values
swap(in, in+1); //swaping the two values by calling the 'swap()' function
}
public void swap(int one, int two)   //defining 'swap' function to perform swapping of elements
{
//interchanging the values
long temp = a[one];
a[one] = a[two];
a[two] = temp;
}
}
// class definition ends

Friday, 4 May 2012

UNIX ASSIGNMENT 2

1. Create a tree structure named ‘training’ in which there are 3 subdirectories – ‘level 1’,’ level2’ and ‘cep’. Each one is again further divided into 3. The ‘level 1’ is divided into ‘sdp’, ‘re’ and ‘se’. From the subdirectory ‘se’ how can one reach the home directory in one step and also how to navigate to the subdirectory ‘sdp’ in one step? Give the commands, which do the above actions?
Ans : To navigate from 'se' to home directory,in one step,the command is : cd
          To navigate from 'se' to 'sdp',in one step,the command is : cd ../b

2. How will you copy a directory structure dir1 to dir2 ? (with all the subdirectories)
Ans : cp –R dir1 dir2

3. How can you find out if you have the permission to send a message?
Ans : ls -l ( To check access permissions)

4. Find the space occupied ( in Bytes) by the /home directory including all its subdirectories.
Ans : du -s -b


5. What is the command for printing the current time in 24-hour format?
Ans : date +%T

6. What is the command for printing the year, month, and date with a horizontal tab between the fields?
Ans : date +%Y%t%B%t%e

7. Create the following files: chapa, chapb, chapc, chapd, chape, chapA, chapB, chapC, chapD, chapE, chap01, chap02, chap03, chap04, chap05, chap11, chap12, chap13, chap14, and chap15.
Ans :The general syntax is :
   cat > filename
    Type the contents of file
    Press Ctrl+D

1.      cat > chapa
           Type the contents of file
            Ctrl+D

2.        Cat > chapb
             Type the contents of file
             Ctrl+D


3.       Cat > chapc
         Type the contents of file
          Ctrl+D

4.      Cat > chapd
Type the contents of file
Ctrl+D

5.     Cat > chape
Type the contents of file
Ctrl+D

6.     Cat > chapA
Type the contents of file
Ctrl+D

7.     Cat > chapB
Type the contents of file
Ctrl+D

8.     Cat > chapC
Type the contents of file
Ctrl+D

9.     Cat > chapD
Type the contents of file
Ctrl+D

10.                         Cat > chapE
Type the contents of file
Ctrl+D

11.                         Cat > chap01
Type the contents of file
Ctrl+D

12.                          Cat > chap02
Type the contents of file
Ctrl+D

13.                         Cat > chap03
Type the contents of file
Ctrl+D



14.                         Cat > chap04
 Type the contents of file
Ctrl+D

15.                         Cat > chap05
Type the contents of file
Ctrl+D

16.                         Cat > chap11
Type the contents of file
Ctrl+D

17.                        Cat > chap12
Type the contents of file
Ctrl+D

18.                         Cat > chap13
Type the contents of file
Ctrl+D

19.                        Cat > chap14
Type the contents of file
Ctrl+D

20.                         Cat> chap15
Type the contents of file
Ctrl+D


8. With reference to question 7, What is the command for listing all files ending in small letters?
Ans : find –name “*[a-z].*”

9. With reference to question 7, What is the command for listing all files ending in capitals?
Ans : find –name “*[A-Z].*”

10. With reference to question 7, What is the command for listing all files whose last but one character is 0?
Ans : find –name “*0?.*”

11. With reference to question 7, What is the command for listing all files which end in small letters but not ‘a’ and ‘c’?
Ans: find –name “*[b d-z].*”

12. In an organisation one wants to know how many programmers are there. The employee data is stored in a file called ‘personnel’ with one record per employee. Every record has field for designation. How can grep be used for this purpose?
Ans : grep -c "programmers" personnel

13. In the organisation mentioned in question 12 how can sed be used to print only the records of all employees who are programmers.
Ans : sed -n /programmers/p personnel

14. In the organisation mentioned in question 12 how can sed be used to change the designation ‘programmer’ to ‘software professional’ every where in the ‘personnel’ file
Ans :  sed 's/programmer/software professional/g' personnel

15. Find out about the sleep command and start five jobs in the background, each one sleeping for 10 minutes.
Ans :sleep 10m & sleep 10m & sleep 10m & sleep 10m & sleep 10m &

16. How do you get the status of all the processes running on the system? i.e. using what option?
Ans : ps -e