Saturday, September 10, 2011

BOP Assignment

QUESTION1
a. 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”}

Ans.
import java.io.*;

import java.util.Scanner;

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”};

Scanner sr= new Scanner(System.in);

System.out.println("Enter a name to check");

String name=sr.nextLine();

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>java Program1

Enter a name to check

Sam

The Number of occurance of the Name is 2


(b) Improve the understandability of the below given code:
import java.util.*;
class problem3
{
int[] numArray = new int[10];
public static void incrementElements (int[] integerArray)
{
int arraylen = integerArray.length;
for (int i = 0; i < arraylen; i ++)
{
System.out.println(integerArray[i]);
}
for (int i = 0; i < arraylen; i ++)
{
integerArray[i] = integerArray[i] + 10;
}
for (int i=0; i < arraylen; i ++)
{
System.out.println(integerArray[i]);
}
}


ANSWER:

import java.util.*;    //importing the required packages
import java.io.*;

class Problem3     //creating a class
{
 public static void Increment(int[] arr)  //defining the 'increment()' method with one integer parameter
 {
  int len = arr.length;     // initializing a integer variable 'len' with the length, i.e. the no of elements in array
  System.out.println("\nBefore Increment, The Array was :");
  for (int i = 0; i < len; i ++)   //definition of 'for' loop to print the current values of array
  {
   System.out.print(arr[i]+"\t");
  }

  for (int i = 0; i < len; i ++)  //definition of 'for' loop to increment the current values of array
  {
  arr[i] = arr[i] + 10;    //add 10 to each value of array
  }
 
  System.out.println("\n\nAfter Increment, The Array is :");
  for (int i=0; i < len; i ++)  //definition of 'for' loop to print the updated values of array
  {
  System.out.print(arr[i]+"\t");
  }
 }          //method definition ends

 public static void main(String args[])  //definition of 'main' method starts..
 {
  int i,n;       
  Console con=System.console();   //creating an obect of console class
  System.out.print("\nEnter The Length of Array : ");
  n=Integer.parseInt(con.readLine());    //reading the value for no. of elements from console entered by user
  int[] a = new int[n];       //initializing the array
  System.out.println("\nEnter Array values :");
  
  for(i=0;i<n;i++)      //defining a 'for' loop to reading the values from console to be stored in array
  {
   a[i]=Integer.parseInt(con.readLine()); //reading user input from console
  }
  Increment(a);       // calling the method 'increment()' with the 'array a' as its parameter
 }           // main method ends
}            //class closes



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

Ans.

Program 2 finding GCD:

import java.io.*;

import java.util.Scanner;

class program2

{

public static void main(String args[])

{

Scanner sr= new Scanner(System.in);

System.out.println("Enter The number a");

int a=sr.nextInt();

System.out.println("Enter The number 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 two positive numbers " + a + " and " + b + " is " + gcd);

}

public static int findgcd(int c,int d)

{

if (d == 0)

return c;

return findgcd(d, c % d);

}


Output

C:\Program Files\Java\jdk1.6.0_22\bin>javac Program2.java


C:\Program Files\Java\jdk1.6.0_22\bin>java program2

Enter The number a

36

Enter The number b

24

The greatest common divisor of two positive numbers 36 and 24 is 12


(b) Improve the understandability of the below given code:
class 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()
{
int out, in;
for(out=nElems-1; out>1; out--)
for(in=0; in<out; in++)
if( a[in] > a[in+1] )
swap(in, in+1); }
public void swap(int one, int two)
{
long temp = a[one];
a[one] = a[two];
a[two] = temp;
}

ANSWER:

class Problem1  //creating a new class
{
 static int[] a;  //declaring a new integer variable 'a' of array type to store the numbers
 static int nElems; //declaring an integer variable to hold the value of ''element no.'' in the array
 public static void ArrayBub(int max) //defining a new parameterised method to initialize the array with 'max' as size of the array
 {
  a = new int[max];   
 }
 public static 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 static 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 adjecent values
    swap(in, in+1);    //swaping the two values in specified order
   }
  }
 }
 public static void swap(int one, int two) //defining 'swap' function to perform swapping of elements
 {
  int temp = a[one];      //interchanging the values
  a[one] = a[two];
  a[two] = temp;
 }
 public static void main(String args[])  //definition of main method
 {
  ArrayBub(3);    //calling the method 'arraybub() with 3 as parameter'
  insert(3);     //calling the method 'insert() with 3 as parameter'
  insert(6);     //calling the method 'insert() with 6 as parameter'
  insert(1);     //calling the method 'insert() with 1 as parameter'
  Sort();      // calling the 'sort()' method
  System.out.println(a[2]); //printing the current value of array at 3rd position
  swap(2,1);     //calling the swap function
  System.out.println(a[0]); //printing the current value of array at 1st position
 }   //main method ends here
}   // class definition ends
 
Know Your TCS Quiz

1. How many ISU are there in TCS?
      12 

2. Which service area generated the maximum revenue?
      ADM

3. Which of the following is not an ISU?
      ITIS

4. Which Geography gives the maximum revenue for TCS?
      North America

5. What is TCS revenue in FY 2010 in USD Billions?
       $ 6.3 billion 
Start Your Aspire

  1. After receiving both aspire mails(mail 1: General outlook on aspire and mail 2: Login Credentials for aspire portal and your group under which you should enroll for aspire activities) from TCS; Go to https://ilpcms.tcs.com/aspire/
  2. Click Login and login with your login credentials provided in the mail. ID should be your CT/DT reference number and Password should be your DOB in the format dd-mm-yy(eg: 01-01-88;include hyphens also)
  3. Then check your group described in your mail under which you should enroll to start learning. Please refrain from enrolling into other groups available there in the site and enroll only into the group which you are asked to do by TCS to avoid future problems.
  4. After enrolling into a course you should complete weekly activity tracker by giving your feedback. It's just a feedback slot and it's some kind of thing that tracks your activity in aspire, whether you are following the schedule or not !!
Aspire FAQs

1. What is Aspire?

Ans: Aspire is a pre-engagement program designed for associates joining TCS. This is a program designed to cover the basics of software engineering modules and soft skills which would be helpful when the associates joins TCS.

2. How do we learn in Aspire? 
Ans: In Aspire, we have courses covering various areas like Web Technologies, Unix, etc. The first step of learning would be to enroll for the courses. Each course would follow a weekly timeline. For each week, you will be given some learning objectives, learning activities and online learning materials. Participants are expected to cover the materials and activities and accomplish the learning objectives for the week. At the end of each week, you will need to update the activity tracker to record the progress of your learning.

3. Do we have evaluations on the topics covered in Aspire? 
Ans: We have some assessment modules designed for participants in Aspire. This would include online assignments and self evaluation quizzes. These assessment modules will be rolled out in due course of time.

4. Do we have any other assessments other than the online assessments? 
Ans: Yes. We may also conduct offline assessments for the participants who have undergone Aspire. This will be done once the participant formally joins TCS.

5. I was not able to complete a week's learning activity within the timeline. Will the material still be available?
Ans: Yes. The materials will still be available in the course page. However, we would be uploading more materials and activities for subsequent weeks. So, participant may need to spend some more time and complete the pending learning activities at the earliest to avoid back-lag.

  6. I have completed a week's activity in a shorter period. Can I go ahead with the next week's learning activities? 
Ans: Yes, upon earlier completion of a week's learning activities, participants may proceed with the next week's learning activities provided the subsequent activities have been opened in the system.

7. What is the advantage of completing the Aspire program?

Ans: On successful completion of Aspire, a participant would have a clear understanding on the basics of software engineering and soft skills. This would enable identifying the associate for a fast-track training program of a shorter duration than the regular training program. Moreover, Aspire would be a platform to prove that a participant can be a self-learner capable in addition to the traditional classroom training programs.

8. The city in my Profile is filled as TVM. Does it mean that I will be asked tojoin at TCS Trivandrum for the training? 
Ans: No. TVM is the default value given for the city while creating profiles inAspire. This need not mean that an associate will be posted at TCS Trivandrum for the training.

9. My friend has also got an offer letter from TCS but did not get the mail from Aspire. Why does it happen so? 
Ans: Aspire is a program which we roll out as batches. The invitation to Aspireis sent in batches and if your friend did not get an invitation, that would probably mean that he/she is not batched along with you.

10. Can I share my credentials for Aspire with my friend? 
Ans: No. TCS is a company where in we have strict Information Security policies and all the participants who access Aspire are expected to follow the same. You cannot share your credentials for Aspire with anyone else.

11. When do I get my joining letter from TCS?
Ans: You would get your joining letter soon as your batching is confirmed. You may expect a mail from TCS Talent Acquisition Group specifying the date and location for joining.

12. Do I not get the joining letter unless I complete Aspire? 
Ans: No. An associate who got an offer letter from TCS will get a joining letter as an when his batch is scheduled. If you successfully complete Aspire, you will be identified for a fast-track, shorter duration training program. Else, you will need to follow the regular duration training.

13. How do I list out the assignments for a course? 
Ans: You can locate an Activities tab in the course page. Under that, you will find a link Assignments if you have any assignments for the course. When the link isclicked, it will list all the assignments available for course. Similarly, you can also list out all the activity trackers also for a course by clicking the Feedback Activities link. You will also find a calendar on the right side of the Aspire homepage. Once logged in, it will highlight any assignment activities pending for the next 10 daysfor the courses you have enrolled for.

14. Do you have a toll free number in which I can call and clarify if I have any further queries? 
Ans: No. We do not have a toll free service available for Aspire now. Should you have any further queries, you can write to ilp.aspire@tcs.com