Computer Science Important Question For Class 12 C++
Computer Science Important Question For Class 12 C++
1. What is the difference between Run Type error and Syntax error? Give one example of each.
2. When will you make function inline and why?
3. What do you mean by free store with reference to memory allocation in c++?
4. What is the meaning of * * x? Give an example for alias in pointers .
5. Why does an array always start with an index 0 in C++?
6. What is the difference between get ( ) and getline ( ) functions.
7. What are actual arguments and formal arguments in C++? Explain with example
8. Differentiate between call by reference and call by value, with example?
9. What is the difference between Global Variable and Local Variable? Also, give a suitable C++ code to
illustrate both.
10. What is difference between Actual parameter and Formal parameter? Give an example in C++ to
illustrate both type of parameters.
11. Illustrate the use of #define in C++ to define a macro.
12. What do you mean by a reference of a variable in C++? Explain how is it created with suitable
example?
13. Write two major differences between procedural programming and object oriented programming.
14. What is the difference between implicit data casting and explicit data casting?
15. What is cascading in C++? Define with e.g.
16. What is the difference between while and do while loop?
17. What is alias or reference variable? Define with e.g.
18. What is scope resolution operator? Define with e.g.
19. What is shorthand notation? Define with e.g.
20. When will you make function inline and why?
21. How array is differ from structure?
22. What is nested structure? How data is accessed in nested structure?
23. Distinguish between object and class.
24. Reusability is one of the major properties of OOPS. How it is implemented in C++?
25. Why main function is special? Give two reasons.
26. Write two advantages of using include compiler directive?
27. What is the effect of absence of break statement in switch-case?
28. Name the header files associated with following functions
i). frexp() ii) toupper() iii) getc() iv) strcat () v) setw()
vi) exp() vii) isdigit() viii) puts() ix) scanf() x) getchar()
xi) clrscr() xii) gets() xiii) isalnum() xiv) fabs() xv) slrlen()
xvi) random() xvii) gotoxy()
29. Which C++ header file(s) will be essentially required to be included to run /execute the following C++
code:
void main()
{
char Msg[ ]="Sunset Gardens";
for (int I=5;I<strlen(Msg);I++)
puts(Msg);
}
30. Name the header files, to which following built-in functions belongs:
(i) isalnum() (ii) exit() (iii) ceil() (iv) fabs()
31. What do you mean by free store with reference to memory allocation in c++?
Category B:- Output and Error Questions ( 2 and 3 Marks in CBSE Board)
{ char ch='A';
int L,M,N;
for(L=0;L<str[L]!='\0';L++);
for(M=0;M<=L;M++)
if(str[M]=='-')
{ for(N=M;N<=L;N++)
str[N]=str[N+1];
}
else
if(isdigit(str[M])) str[M]=ch++;
}
void main( )
{ char STD[ ]="The-STD-code--is-0542";
PACK(STD);
cout<<STD<<endl;
getch();
}
2. int Pos=3;
3. #include<iostream.h>
#include<stdlib.h>
#include<conio.h>
void main()
{ randomize( );
int A[]={4,5,6,7,8,9,10,11};
int N=5;
int num=random(A[N]);
for(int i=num;i>=1;i--)
{ cout<<i;
if(i!=1)
cout<<','; }
}
4. #include<iostream.h>
void main()
{ int Numbers[] = {2,4,8,10};
int *ptr = Numbers;
5. for (int C = 0; C<=3; C++)
{
cout<< *ptr << “@”;
ptr++;
}
cout<<endl;
ptr=Numbers;
for(C = 0; C<4; C++)
{
(*ptr)*=2;
++ptr;
}
for(C = 0; C<4; C++)
cout<< Numbers [C]<< “#”;
cout<<endl;
}
6). #include<iostream.h>
void Indirect(int Temp=20)
{
for (int 1=10; I<=Temp; I+=5)
cout<<I<<” , “ ;
cout<<endl;
}
void Direct (int &Num)
{
Num+=10;
Indirect(Num);
}
void main()
{
int Number=20;
Direct(Number) ;
Indirect();
cout<< “ Number=” <<Number<<endl ;
}
7). #include<iostream.h>
int a=10;
void main()
{
void demo(int &,int,int*);
int a=20,b=5;
demo(::a,a,&b);
cout<<::a<<a<<b<<endl;
}
void demo(int &x,int y,int *z)
{
a+=x;
y*=a;
*z=a+y;
cout<<x<<y<<*z<<endl;
}
8). # include<iostream.h>
#include<ctype.h>
#include<conio.h>
#include<string.h>
void NewText(char str[ ], int & pos)
{
char * p = str;
int length = strlen(p);
for( ; pos < length - 2; pos += 2 , p++)
{
*(p + pos) = toupper(*(p+pos)-1);
}
cout<<str;
}
void main( )
{
clrscr( );
NewText(“Good Morning”, 0) ;
}
9). //program RANDNUM.CPP
#include<iostream.h>
#include<stdlib.h>
#include<time.h>
void main()
{
randomize();
int VAL, Rnd; int n=1;
cin>>VAL;
Rnd=8 + random(VAL) * 1;
while(n<=Rnd)
{
cout<<n<< “\t”;
n++;
}
}
output options:
i) 1 2 3 4 5 6 7 8 9 10 11 12 13
ii) 0 1 2 3
iii) 1 2 3 4 5
iv) 1 2 3 4 5 6 7 8
10).
#include<iostream.h>
void main()
{
int *queen, Moves[ ] = { 11, 22, 33, 44 };
Queen = Moves;
Moves[2] + = 22;
cout<<”Queen @”<<*Queen<<endl;
*Queen - =11;
Queen + = 2;
cout<<”Now @”<<*Queen<<endl;
Queen++;
cout<<”Finally @”<<*Queen<<endl;
cout<<”New Origin @”<<Moves[0]<<endl;
}
11). Find the output of the following program;
#include<iostream.h>
#include<ctype.h>
void main( )
{
char TEXT1[ ] = “December@TEST!”;
for(int I=0; TEXT1 [I]!=’\0’;I++)
{
if(!isalpha(TEXT1[I]))
TEXT1[I]=’*’;
else if(isupper(TEXT1 [I]))
TEXT1[I]=TEXT1[I]+1;
else TEXT1[I] = TEXT1[I+1];
}
cout<<TEXT1;
}
12). Find out the errors in the following program. Underline each correction if any.
#include [iostream.h]
class MEMBER
{
static int C;
int Mno =0; float Fees;
PUBLIC:
void MEMBER (int i, float j;) { Mno=i; float Fees = j; }
void Register() { cin>>Mno>>Fees; C++;}
void Display { cout<<Mno<<" : "<<Fees<<endl<<”Total”<<C; }
};
void main()
{ MEMBER M;
Register();
M.Display();
}
#include<iostream.h>
#include<ctype.h>
void Encript ( char T[ ])
{
for( int i=0 ; T[i] != ‘ \0’ ; i += 2)
if( T[i] = = ‘A’ || T[i] = = ‘E’ )
T[i] = ‘#’ ;
else if (islower (T[i] ))
T[i] = toupper(T[i]);
else
T[i] = ‘@’;
}
void main()
{
char text [ ] = “SaVE EArTh in 2012”;
encrypt(text);
cout<<text<<endl;
}
14). Write the minimum and maximum output possible from the following code, if 7 is entered in N:
void main( )
{
int N, Guessme;
randomize( );
cin>>N;
Guessme=random(N)+10;
cout<<Guessme<<endl;
}
#include<iostream.h>
void main( )
{
int A=5,B=10;
for(int x=1;x<=2;x++)
{
cout<<++A<<”\t”<<B-- <<endl;
cout<<--B<<”\t”<<A++<<endl;
}
}
16). What will be the output of the following code fragment .Explain.
void main( )
{
clrscr( );
int x[ ] = {10,20,30,40,50};
int *p, **q, *t;
p = x;
t= x + 1;
q = &t;
cout<<*p<<’\t’<<**q<<’\t’<<*t++;
}
17). Name the header files that shall be needed for the successfully execution of following code:
void main()
{
char Word[]=”Exam”;
cout<<setw(20)<<Word;
}
18). In the following program, find the correct possible output(s) from the options:
#include<stdlib.h>
#include<iostream.h>
void main( )
{
randomize( );
char Area[ ][10]={“Physics”,”Computer”,”Maths”,”Hindi”};
int A;
for(int I=0; I<3;I++)
{
A=random(2) + 1;
cout<<Area[A]<<”:”;
}
19). Rewrite the following program after removing syntactical error(s) if any. Underline each correction.
#include “iostream.h”
Class MEMBER
{
int Mno;
float Fees;
PUBLIC:
void Register ( )
{cin>>Mno>>Fees;}
void Display( )
{cout<<Mno<<" : "<<Fees<<endl;}
};
void main()
{
MEMBER delete;
Register();
delete.Display();
}
20). Give the output of the following program segment (Assuming all required header files are included
in the program):
void main()
{
char *NAME=”a ProFiLe!”;
for(int x=0;x<strlen(NAME);x++)
if(islower(NAME[x]))
NAME[x]=toupper(NAME[x]);
else
if(isupper(NAME[x]))
if(x%2!=0)
NAME[x]=tolower(NAME[x-1]);
else
NAME[x]--;
cout<<NAME<<endl;
}
21). Find the output of the following program.
#include<iostream.h>
void Withdef(int HisNum=30)
{
for(int I=20;I<=HisNum;I+=5)
cout<<I<<”,”;
cout<<endl;
}
void Control(int &MyNum)
{
MyNum+=10;
Withdef(MyNum);
}
void main()
{
int YourNum=20;
Control(YourNum);
Withdef();
cout<<”Number=”<<YourNum<<endl;
}
22). In the following program, find the correct possible output(s) from the options. Justify your answer.
#include<iostream.h>
#include<stdlib.h>
void main( )
{
randomize( );
int p=99,q=999;
int x=random(3)+4;
int y=random(2)+2;
for(int i=0;i<x;i++)
cout<<’#’;
cout<<p<<’-’;
for(i=0;i<y;i++)
cout<<’@’;
cout<<q<<endl;
}
i. ##99-@999
ii. ##99-@@999
iii. ######99-@@999
iv. ####99-@@@
Private Members:
Event_no integer
Description char(30)
Score integer
Qualified char
Award(int) To award qualified as ‘Y’, if score is more than the cut off score passed as
argument to the function else ‘N’.
Public Members:
A constructor to assign initial values Event_No as 101, Description as “State level”, Score is 50 and
Qualified as ‘N’ through parameters.
Input(), To take the input for Event_no, Description and Score and call the function Award().
Show(), To display all the details.
Public Members:
A constructor to assign all values with 0 and null respectively
A function Buy( ) to allow user to enter values for ICode, Item, Price, Qty and call function
FindDisc( ) to calculate the discount.
A Function ShowAll( ) to allow userto view the content of all the data members.
15. Define a class ELECTION with the following specifications . Write a suitable main ( ) function also to
declare 3 objects of ELECTION type and find the winner and display the details .
Private members :
Data : candidate_name , party , vote_received
Public members :
Functions :
1. enterdetails ( ) – to input data
2. Display ( ) – to display the details of the winner
3. Winner ( ) – To return the details of the winner through the object after comparing the votes
received by three candidates.
class TEST
{ private:
char subj[30];
int no_of_cand,roomno;
public:
TEST(char *,int,int); //constructor 1
TEST(TEST &T); // constructor 2
};
i) Write a statement that will invoke constructor 1.
ii) Write complete definition of constructor 2.
4. How does invoking of constructor differ in inheritance and containership? Give example
5. What is constructor? What is its need? Explain with the help of e.g.
6. Answer the following questions (i to ii) after going through the following class:
class Inter
{
int m;
public:
Inter( int Y ) { m = y; } // Function 1
Inter ( Inter & t ); // Function 2
~Inter() { } // Function 3
};
class alpha
{
int a
float b;
char c;
public:
----------- //constructor definition
…... };
class beta : public alpha
{ int x;
public:
……………..//constructor definition
};
14. What is default constructor? How it is different from other member function?
15. Answer the questions (i) and (ii) after going through the following class:
class WORK
{
int WorkID;
char WorkType;
public:
~WORK( ) // Function 1
{
cout<<”Un-Allocated”<<endl;
}
void status( ) // Function 2
{
cout<<WorkID<<”;”<<WorkType<<endl;
}
WORK( ) // Function 3
{
WorkID=10;
WorkType=’T’;
}
WORK(WORK &W) // Function 4
{
WorkID=W.WorkID+12;
WorkType=W.WorkType+1;
}
};
(i) Which member function out of function1, function2, function3 and function4 shown in the above
example of class WORK is called automatically, when the scope of an object gets over? Is it known
as Constructor OR Destructor OR Overloaded Function OR Copy Constructor?
(ii) WORK W; //Statement 1
WORK Y (W); //Statement 2
(iii) Which member function out of Function1, Function2, Function3 and Function4 shown in above
definition of class WORK will be called on execution of statement written as Statement 2? What is
this function specifically known as out of Destructor or Copy Constructor or Parameterized
Constructor?
16. Consider the following and answer the questions given below:
class CEO
{
double Turnover;
protected:
int Noofcomp;
public:
CEO();
void INPUT(int);
void OUTPUT();
};
class Director : public CEO
{
int Noofemp;
public:
Director ();
void Indata();
void Outdata();
protected:
float Funds;
};
class Manager : public Director
{
float Expenses;
public:
void Display();
Manager();
}
a) Which constructor will be called first at the time of declaration of an object of class Manager?
b) How many bytes will an object belonging to class Manager require?
c) Name the member function(s), which are directly accessible from the object of class Manager.
d) Is the data member Funds accessible by the object of the class Manager and why?
e) If the class Manager is derived in protected mode in place of public then, give the names of
inherited members in the protected section only?
Assuming the above shown file write a function showfile( ) to read all the records present in already
Existing binary file “SPEED.DAT” and display them on screen, also count the number of records
Present in the file.
21. Assuming the class Employee given below, write function in C++ to perform the following
a. Write the objects of Employee to the binary file.
b. Read the objects from the binary file and display them on the screen.
Class Employee
{
int ENO;
char Ename[20];
public:
void getit();
void showit();
}
22. Write a program to display the size of a file in bytes.
CHAPTER 7 : ARRAY
1. Differentiate between data type and data structure.
2. What is meant by base address in the array?
3. How is computer memory allotted for a two – dimensional array?
4. An array A [-2...5] [-4...1] is stored in the memory with each element occupying 4 bytes of space.
Assuming the address of A [0] [-1] is 1000 then compute the base address of A and also the address of
A [4] [1], when the array is stored as row wise.
5. An array T[15][10] is stored in the memory with each element requiring 2 bytes of storage. If the base
address of T is 2000, determine the location of T[7][8] when it is stored by
a. Row wise b. column wise
6. The array A[20][10] is stored in the memory with each element requiring one byte of storage if the
base address of A is C0. Determine C0 when the location of A[10][15] is 2000.
7. Write a function to add elements of rows in a matrix.
8. Write a function to transpose a matrix.
9. Write a function to add two matrix in c++.
10. Write a function to add elements of diagonals of matrix.
11. Use inserting sort for sorting following series in ascending order
12, 9, 4, 11, 15, 18
12. Use bubble sort for sorting following series in ascending order
42, 29, 74, 11, 65, 58
13. Each element of an array D[1……10][1…….10] requires 8 bytes of storage. If the base address of array
of D is 2000, determine the location of D[4][5] , when the array is stored as
a) Row wise b) column wise
14. Write a program to search a number in array by using binary search.
15. Write a function in C++ which accepts an array of integer type and its size as arguments and rearrange
the array in following order.
For example:
If array contents: 1, 3, 5, 7, 9 ,11, 13, 15, 17, 19
Array after rearrangement: 11, 13, 15, 17, 19, 1, 3, 5, 7, 9
16. An array T[50][20] is stored in the memory along the column with each element occupying 4 bytes.
Find out the base address and address of element T[30[15], if an element T[25][10] is stored at the
memory location 9800.
17. Write a function SORTSCORE() in C++ to sort an array of structure Examinee in descending order of
Score using Bubble Sort
17. Convert the following infix expression to its equivalent postfix expression Showing stack contents for
the conversion:
(A+B)*(C^(D-E)+F)-G
18. Evaluate the following postfix notation of expression:
(Show status of stack after each operation)
Table: Consumer
13. Consider the following WORKERS and DESIG. Write SQL commands for the statements (i) to (iv) and
give outputs for SQL queries (v) to (vi)
WORKERS
DESIG
(i) To display the content of workers table in ascending order of first name.
(ii) To display the FIRSTNAME, CITY and TOTAL SALARY of all Clerks from the tables workers and design,
where TOTAL SALARY = SALARY + BENEFITS.
(iii) To display the minimum SALARY among Managers and Clerks from the table DESIG.
(iv) Increase the BENEFITS of all Salesmen by 10% in table DESIG.
(v) SELECT FIRSTNAME, SALARY FROM WORKERS, DESIG WHERE DESIGNATION = ‘Manager’
AND WORKERS.W_ID = DESIG.W_ID;
(vi) SELECT DESIGNATION, SUM(SALARY) FROM DESIG
GROUP BY DESIGNATION HAVING COUNT(*)>=2 ;
2. Draw a logical Circuit Diagram for the following Boolean Expression: A.(B+C’)
3. Write the equivalent Canonical Sum of Product for the following Product of Sum
Expression: F(X,Y,Z)= (1,3,6,7)
4. If F(a,b,c,d) =(0,1,3,4,5,7,8,9,11,12,13,15), obtain the simplified form using K-Map.
5. State and verify De-Morgan’s Theorem in Boolean algebra, algebraically. 2
6. Reduce the following Boolean expression using K-map:
F(A,B,C,D)=(0,1,2,4,5,8,9,10,11) 3
7. Convert the following into SOP form: 2
(P+Q+R) (P’+Q+R) (P’+Q’+R) (P+Q+R’).
9. Draw the logic circuit diagram for the Boolean equation: (A+B’)(A’+B+C’)(A’+C’) (
10. Write the Sum of Product form of the function H (U, V, W). Truth table representation of the function
H is as follows:
U V W H
0 0 0 0
0 0 1 0
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 1
1 1 1 1
11. Minimize the following function using K- map and find out the expression
Main Resource
Building Building
Accounts
Training
Building
Building
5. Center to center distances between various buildings as per architectural drawings (in m) is as follows:
Main Building 15
Resource Building 25
Accounts Building 10
“Kanganalay Cosmetics” is planning to start their offices in four major cities in Uttar Pradesh to provide
cosmetic product support in its retail fields. The company has planned to set up their offices in Lucknow
at three different locations and have named them as “Head office”, “Sales office”, & “Prod office”. The
company’s regional offices are located at Varanasi, Kanpur & Saharanpur. A rough layout of the same is as
follows :
Approximate distances between these offices as per network survey team is as follows :