Ge C++
Ge C++
________________
Question 1 is compulsory. Attempt any five questions out of Q2 to Q8. Parts of a question
must be answered together.
(Note: The symbols (‘) and (“) used in the paper represent the single and double quotes as used in C++ compilers)
b) Write a function quad to read the values of variables a, b and c and display the value
of x, where x = √ (b2 – 4 * a * c). Give output of the program for a = 3, b
= 10, c = 3. (5)
Q4. a) Write a function GCD that accepts two numbers as arguments and returns their
greatest common divisor. (5)
b) Write a program to read ten integers and search for an integer value given by the user. (5)
Q5. Create a class Box in C++ having three data members: length, width and height. (2)
Define a default constructor for this class. (2)
Define appropriate functions to take input and display the volume of the objects of this
class. (4)
Create an object of this class and display its volume. (2)
Q6. a) Define a function power that accepts two integers x and y as arguments and returns yth
power of x that is xy. (4)
Define the function main( ) that calls the above function and displays results for the
following values: x = 2, y = 3. (2)
b) Write a program to generate and print first n terms of the Fibonacci Series.
(1, 1, 2, 3, 5, …) (4)
Q7. a) Which of the following array declarations are invalid? Give reasons for invalidity.
i) float [+10]; ii) char name[30]; iii) double[100]; iv) int score [15]; (4)
b) Write a program to read a 3 x 3 matrix, find its transpose, and display the transpose. (6)
Q8. a) Write a C++ Program to display the following pattern on the output screen. The
number of rows should be taken as an input from the user.
*****
****
***
**
* (6)
b) Find the error(s) in the following code. Give reasons for the error(s).
class A {
private : int x;
protected : int y;
public : int z;
};
class B : public A {
private : int i;
protected : int j;
public : int k;
};
int main ( ) {
A a ;
B b;
a.x = 1;
a.y = 2;
a.z = 3;
b.x = 5;
b.y = 6;
b.z = 7;
b.i = 10;
b.j = 20;
b.k = 30;
} (4)