0% found this document useful (0 votes)
34 views4 pages

Ge C++

This document contains a question paper for an Introduction to Programming course. It has 8 questions covering topics like basic C++ syntax, functions, classes, arrays, structures, inheritance. The questions are both conceptual, involving explanations and writing code snippets and programs to demonstrate understanding of the concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views4 pages

Ge C++

This document contains a question paper for an Introduction to Programming course. It has 8 questions covering topics like basic C++ syntax, functions, classes, arrays, structures, inheritance. The questions are both conceptual, involving explanations and writing code snippets and programs to demonstrate understanding of the concepts.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

This question paper contains 4 printed pages. Roll No.

________________

Sr. No. of Question Paper :


Unique Paper Code : 32345102
Name/Title of the paper : (GE) Introduction to Programming
Name of the Course : B.A.(H)/B.Com.(H)/B. Sc.(H) Generic Elective
Semester : I
Duration : 03 Hours
Maximum Marks : 75
(Write your Roll No. on the top immediately on receipt of this question paper.)

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)

Q1. a) What is wrong with the following code/ code segments:


i) if (x == 0) cout << x << “ = 0 “ << endl;
else cout << x << “ != 0 “ << endl;
else cout << “No error”; (1)
ii) void fun ( )
void fun ( ) {
cout << “ Hello “;
}
int main ( ) {
fun ( ) ;
return 0;
} (1)
iii) class One{
int p;
public:
void input (int q) { p = q ; }
void output ( ) { cout << p ; }
};
int main ( ) {
One b;
b.p = 10;
cout << b.p;
} (1)
b) Write the outputs of the following code/code fragments:
i) int main() {
int j = -7 / 2;
int k = -7 % 2;
cout << j <<“ “ << k;
} (3)
ii) int n, j = 100, k = 30;
n = (j % k ? k + 1 : k - 1);
cout << “ n = “ << n << “ k = “ << k << endl; (2)

iii) int array[ ] = {0, 2, 4, 6, 7, 5, 3};


int n, result = 0;
for (n = 0; n < 8; n++)
result += array[n];
cout << result; (2)

iv) int main ( ) {


int x = 10, y = 20;
cout << x << “ “ << y;
fun (x, x);
cout << x << “ “ << y;
return 0;
}
void fun (int x, int y) {
x = 20;
y = 10;
cout << x << “ “ << y;
} (3)
c) Write a C++ instruction to define a constant PI with value 3.141. (1)
d) Write a single C++ statement that prints “too many” if the variable count exceeds
100. (1)
e) Write logical expressions to represent each of the following conditions:
i) whether score is greater than 80 but less than or equal to 90
ii) whether ch is either lowercase or uppercase letter
iii) whether n is between 0 and 7 but not even (3)
f) Give the syntax of using a header file in a C++ program. (1)
g) Write a function in C++ that takes a number as input and returns the sum of its digits. (6)
Q2. a) What would be the output of the following C++ code snippets?
i) int main( ) {
int a = 5, b ;
b = -3 - - (- 3) ;
cout << “ b = “ << b ;
b = a++;
cout << “ a = “ << a << “ b = “ << b ;
} (3)

ii) char ch = ‘g’;


switch (ch) {
case ‘g’ : cout << “ Good “;
case ‘b’ : cout << “ Bad “;
break;
case ‘e’ : cout << “ Excellent “;
break;
default : cout << “ Wrong choice”;
} (2)

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)

Q3. Write C++ statements for the following tasks: (2 x 5)


a) Write a for loop to display all perfect squares till 100.
b) Write a prototype of a function func that accepts two arguments- an integer and a
float; and returns a double.
c) Create a structure Employee having elements name, age and salary.
d) Swap two integers and print the new values.
e) Create a class Day with data members day_of_the_week and month using appropriate
data types and access specifiers.

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)

You might also like