# Tutor profile: Mehak G.

## Questions

### Subject: Java Programming

Explain the code: class Box { float width, height, depth; Box(float w, float h, float d) { width = w; height = h; depth = d; } Box() { width = height = depth = 0; } Box(float len) { width = height = depth = len; } double volume() { return width * height * depth; } } public class Test { public static void main(String args[]) { Box mybox1 = new Box(10.0, 20.0, 15.0); Box mybox2 = new Box(); Box mycube = new Box(7.0); double vol; vol = mybox1.volume(); System.out.println(" Volume of mybox1 is " + vol); vol = mybox2.volume(); System.out.println(" Volume of mybox2 is " + vol); vol = mycube.volume(); System.out.println(" Volume of mycube is " + vol); } }

// The given program shows how Constructor Overloading works in Java class Box { float width, height, depth; //Here, Box is the parameterized constructor used when three parameters are passed and contains float value and passed argument Box(float w, float h, float d) { //parameters are intialized to their respective values width = w; height = h; depth = d; } // Here, Box is overloaded constructor used when no dimensions are specified and variables are initialized inside the constructor Box() { //parameters are intialized to 0 width = height = depth = 0; } //Here, Box is overloaded constructor used when length is passed as parameter and cube is created Box(float len) { width = height = depth = len; } // calculates the volumeof cube and returns it double volume() { return width * height * depth; } } // driver code //class is made public to make it visible to other classes so that any other class can access its public field or method //class contain the main function is always made public in java public class Test { //the main function is made static because static allows main() to be called before an object of the class has been created. public static void main(String args[]) { // create boxes using the various //references or objects of Box constructor is created //makes a call to 1st parameterized constructor of Box since in it, 3 arguments are passed and all are float values Box mybox1 = new Box(10.0, 20.0, 15.0); //makes a call to 2nd parameterized constructor of Box since in it, no argument is passed Box mybox2 = new Box(); //makes a call to the 3rd parameterized constructor of Box since in it, one float value is passed Box mycube = new Box(7.0); double vol; //call to volume function is made with the help of object of constructor1 and the volume of the first box is computed vol = mybox1.volume(); //volume of the first box is printed //Volume of mybox1 is 3000.0 will be printed System.out.println(" Volume of mybox1 is " + vol); //call to volume function is made with the help of object of constructor2 and volume of first box is computed vol = mybox2.volume(); //volume of second box is printed //Volume of mybox2 is 0.0 will be printed System.out.println(" Volume of mybox2 is " + vol); // //call to volume function is made with the help of object of constructor3 and volume of first box is computed vol = mycube.volume(); //volume of third box is printed //volume of third box is 343.0 will be printed System.out.println(" Volume of mycube is " + vol); }//endofmain }

### Subject: Trigonometry

Find the value: cos 24° + cos 5° + cos 175° + cos 204° + cos 300°=

Since, cos(180°-θ)= -cosθ ∴cos175°= cos(180°-5°) = -cos5° Now, cos(180°+θ)= -cosθ ∴cos204° = cos(180°+24°) = -cos24° cos(270°+θ)= sinθ ∴cos300° = cos(270°+30°) = sin30° Substitute the values, we get: cos24°+cos5°+cos175°+cos204°+cos300° cos24°+cos5°-cos5°-cos24°+sin30° sin30°= 1/2 = 0.5 The value of cos24°+cos5°+cos175°+cos204°+cos300°=0.5

### Subject: C Programming

Explain the code: # include<stdio.h> int findSum(int n) { int sum = 0; while (n != 0) { sum = sum + n % 10; n = n/10; } return sum; } int main() { int n = 687; printf(" %d ", findSum(n)); return 0; }

// C program computes the sum of digits of number n // number. //stdio.h is the header file used for standard input and output # include<stdio.h> /* Function to compute the sum of digits */ int findSum(int n) { // sum is initiliased to 0 to replace the garbage value contain in sum with 0 int sum = 0; //while loop runs till n is not equal to 0 i.e. from the last digit of the number to the first digit till all the digits of the number are traversed and added while (n != 0) { //value of sum is overwritten by the new sum //n%10 performs the mod // n%10 gives the remainder obtained when n is divided by 10 //The previous value of sum is added to n%10 //variable sum stores addition of all the digits sum = sum + n % 10; //variable n divides n by 10 and quotient is stored in n i.e. n now contains the digits of number yet left to be added in sum n = n/10; } //endofwhile return sum; } //driver code int main() { int n ; //taking input number n from the user printf("enter the number\n"); scanf("%d", &n); printing the sum of digits //Call to findSum() function is made //getSum calculates the sum of digits of a number //n is the argument passed to the findSum() printf(" %d ", findSum(n)); return 0; } /*Dry run //Suppose n=123 /*During iteration 1, n=123 n%10=3 sum=0+3=3 n=123/10=12 Iteration 2, n=12 n%10=2 sum=2+3=5 n=12/10=1 Iteration 3, n=1 n%10=0 sum=5+1=6 n=1/10=0 Since the value of n becomes 0, the program terminates The program returns the value of sum i.e. 6 to the function findSum() */

### Subject: Java Programming

Explain the code: class Box { float width, height, depth; Box(float w, float h, float d) { width = w; height = h; depth = d; } Box() { width = height = depth = 0; } Box(float len) { width = height = depth = len; } double volume() { return width * height * depth; } } public class Test { public static void main(String args[]) { Box mybox1 = new Box(10.0, 20.0, 15.0); Box mybox2 = new Box(); Box mycube = new Box(7.0); double vol; vol = mybox1.volume(); System.out.println(" Volume of mybox1 is " + vol); vol = mybox2.volume(); System.out.println(" Volume of mybox2 is " + vol); vol = mycube.volume(); System.out.println(" Volume of mycube is " + vol); } }

// The given program shows how Constructor Overloading works in Java class Box { float width, height, depth; //Here, Box is the parameterized constructor used when three parameters are passed and contains float value and passed argument Box(float w, float h, float d) { //parameters are intialized to their respective values width = w; height = h; depth = d; } // Here, Box is overloaded constructor used when no dimensions are specified and variables are initialized inside the constructor Box() { //parameters are intialized to 0 width = height = depth = 0; } //Here, Box is overloaded constructor used when length is passed as parameter and cube is created Box(float len) { width = height = depth = len; } // calculates the volumeof cube and returns it double volume() { return width * height * depth; } } // driver code //class is made public to make it visible to other classes so that any other class can access its public field or method //class contain the main function is always made public in java public class Test { //the main function is made static because static allows main() to be called before an object of the class has been created. public static void main(String args[]) { // create boxes using the various //references or objects of Box constructor is created //makes a call to 1st parameterized constructor of Box since in it, 3 arguments are passed and all are float values Box mybox1 = new Box(10.0, 20.0, 15.0); //makes a call to 2nd parameterized constructor of Box since in it, no argument is passed Box mybox2 = new Box(); //makes a call to the 3rd parameterized constructor of Box since in it, one float value is passed Box mycube = new Box(7.0); double vol; //call to volume function is made with the help of object of constructor1 and the volume of the first box is computed vol = mybox1.volume(); //volume of the first box is printed //Volume of mybox1 is 3000.0 will be printed System.out.println(" Volume of mybox1 is " + vol); //call to volume function is made with the help of object of constructor2 and volume of first box is computed vol = mybox2.volume(); //volume of second box is printed //Volume of mybox2 is 0.0 will be printed System.out.println(" Volume of mybox2 is " + vol); // //call to volume function is made with the help of object of constructor3 and volume of first box is computed vol = mycube.volume(); //volume of third box is printed //Volume of mycube is 343.0 will be printed System.out.println(" Volume of mycube is " + vol); }//endofmain }

### Subject: Trigonometry

Find the value: cos 24° + cos 5° + cos 175° + cos 204° + cos 300°=

Since, cos(180°-θ)= -cosθ ∴cos175°= cos(180°-5°) = -cos5° Now, cos(180°+θ)= -cosθ ∴cos204° = cos(180°+24°) = -cos24° cos(270°+θ)= sinθ ∴cos300° = cos(270°+30°) = sin30° Substitute the values, we get: cos24°+cos5°+cos175°+cos204°+cos300° cos24°+cos5°-cos5°-cos24°+sin30° sin30°= 1/2 = 0.5 The value of cos24°+cos5°+cos175°+cos204°+cos300°=0.5

### Subject: C Programming

Explain the code: # include<stdio.h> int findSum(int n) { int sum = 0; while (n != 0) { sum = sum + n % 10; n = n/10; } return sum; } int main() { int n = 687; printf(" %d ", findSum(n)); return 0; }

// C program computes the sum of digits of number n // number. //stdio.h is the header file used for standard input and output # include<stdio.h> /* Function to compute the sum of digits */ int findSum(int n) { // sum is initiliased to 0 to replace the garbage value contain in sum with 0 int sum = 0; //while loop runs till n is not equal to 0 i.e. from the last digit of the number to the first digit till all the digits of the number are traversed and added while (n != 0) { //value of sum is overwritten by the new sum //n%10 performs the mod // n%10 gives the remainder obtained when n is divided by 10 //The previous value of sum is added to n%10 //variable sum stores addition of all the digits sum = sum + n % 10; //variable n divides n by 10 and quotient is stored in n i.e. n now contains the digits of number yet left to be added in sum n = n/10; } //endofwhile return sum; } //driver code int main() { int n ; //taking input number n from the user printf("enter the number\n"); scanf("%d", &n); printing the sum of digits //Call to findSum() function is made //getSum calculates the sum of digits of a number //n is the argument passed to the findSum() printf(" %d ", findSum(n)); return 0; } /*Dry run //Suppose n=123 /*During iteration 1, n=123 n%10=3 sum=0+3=3 n=123/10=12 Iteration 2, n=12 n%10=2 sum=2+3=5 n=12/10=1 Iteration 3, n=1 n%10=0 sum=5+1=6 n=1/10=0 Since the value of n becomes 0, the program terminates The program returns the value of sum i.e. 6 to the function findSum() */

## Contact tutor

needs and Mehak will reply soon.