compulsory questions xi cs
compulsory questions xi cs
MARCH 2019
1. Write a while loop that displays numbers 5, 10, 15........ 50. (Chapter–10)
Answer:
int i = 5;
while(i <= 50)
{
cout << i;
i = i + 5;
}
2. (Chapter–14)
Answer:
(i) Members of the class are m, n, add() and calc()
(ii) Size of the object x1 in memory is 8 bytes.
Size of the object x2 in memory is 8 bytes.
JUNE 2019
1. Write down the importance of Destructor.(Chapter–14)
The purpose of the destructor is to free the resources acquired by the object during its
lifetime.
A destructor function removes the memory of an object which was allocated by the
constructor at the time of creating an object.
1
MARCH 2020
1. (Chapter–14)
Answer:
1. The name of the class is product
2. Data members are code, quantity, price
3. Member functions are assigndata()andprint()
4. The memory size of the object p1 is 12 bytes
The memory size of the object p2 is 12 bytes
5. private
6. public
7. 2 objects are created. They are p1 and p2
(i) a&b
2
Answer:
65 10 = 10000012
15 10 = 11112
65 1 0 0 0 0 0 1
15 0 0 0 1 1 1 1
65& 15(AND) 0 0 0 0 0 0 1
Decimal 64 32 16 8 4 2 1
Decimal = 0 + 0 + 0 + 0 + 0 + 0 + 1 = 1
a & b = 65 & 15 =1 2=1 10
65 1 0 0 0 0 0 1
15 0 0 0 1 1 1 1
65^ 15(XOR) 1 0 0 1 1 1 0
Decimal 64 32 16 8 4 2 1
Decimal = 64 + 0 + 0 + 8 + 4 + 2 + 0 = 78
a ^ b = 65 ^ 15 = 1001110 2 = 7810
June 2020
(iii) (Chapter–16)
3
(a) Which type of inheritance is shown in the above snippet?
(b) Write the visibility mode of class marks and result.
(c) Name the base classes and derived classes in the above snippet.
Answer:
(a) Multi level inheritance
(b) The visibility mode of class marks is private
The visibility mode of class result is public
(c) The base classes are personal, marks
The derived classes are marks, result
MARCH 2022
1. What is the importance of void data type?(Chapter–11)
void type has two important purposes:
To indicate the function does not return a value
To declare a generic pointer.
2. Write a C++ program to sum the numbers from 1 to10 using ‘for’ loop.(Chapter –10)
#include <iostream>
using namespace std;
int main()
{
int i, sum;
sum = 0;
for(i = 1; i <= 10; i++)
{
sum = sum + i;
}
cout << sum;
return 0;
}
June 2022
1. What is an instruction set?(Chapter –3)
Basic set of machine level instructions executed by microprocessor is called as an instruction set.
4
2. Write a C++ program to display numbers from 1 to 10. Except 5 using for and continue statement.
(Chapter – 10)
Program:
#include <iostream>
using namespace std;
int main()
{
int i;
for(i = 1; i <=10;i++)
{
if (i ==5)
continue;
else
cout << i;
}
return 0;
}
June 2023
1. Convert the following if-else statement into conditional statement:(Chapter–10)
if (marks>= 60)
Grade=’A';
else
Grade=’B';
Answer:
Grade =(marks > = 60)?‘A’ :else ‘B’ ;
(ii) 245
421 421 421
2 4 5
010 100 101
2458= 0101001012
(iii) 472
421 421 421
4 7 2
100 111 010
4728=100111010 2
5
March 2024
1. Write the output of the following program
#include<iostream>
using namespace std;
int main( )
{
int i;
for(i = 0; i < 8; i++)
cout << i << endl;
return 0;
}
Output:
0
1
2
3
4
5
6
7
2. Write a C++ program to display numbers from 5 to 1 using do-while loop
Program:
#include<iostream>
using namespace std;
int main( )
{
int i = 5;
do
{
cout << i ;
i--;
} while ( i > = 1 ) ;
return 0;
}
June 2024
1. Write a while loop that displays numbers 2, 4, 6, 8, …. , 20
int i = 2;
while( i < = 20 )
{
cout << i;
i = i + 2;
}