Subject

Computer and Communication Technology

Class

CBSE Class 12

Pre Boards

Practice to excel and get familiar with the paper pattern and the type of questions. Check you answers with answer keys provided.

Sample Papers

Download the PDF Sample Papers Free for off line practice and view the Solutions online.
Advertisement

 Multiple Choice QuestionsShort Answer Type

1.

Out of the following, find those identifiers, which cannot be used for naming Variable, Constants or Functions in a C++ program:

_Cost, Price*Qty, float, Switch,
Address One, Delete, Number12, do

223 Views

2.

Jayapriya has started learning C++ and has typed the following program. When she compiled the following code written by her, she discovered that she needs to include some header files to successfully compile and execute it. Write the names of those header files, which are required to be included in the code.

void main()
{
    float A,Number,Outcome;
    cin>>A>>Number;
    Outcome=pow(A,Number);
    cout<<Outcome<<endl;
}
91 Views

3.

Rewrite the following C++ code after removing any/all syntactical errors with each correction underlined.
Note: Assume all required header files are already being included in the program.

#define Equation(p,q) = p+2*q
void main()
{
	float A=3.2;B=4.1;
	C=Equation(A,B);
	cout<<'Output='<<C<<endl;
}
104 Views

4.

Find and write the output of the following C++ program code:
Note: Assume all required header files are already included in the program.

typedef char STRING[80];

void MIXITNOW(STRING S)
{
	int Size=strlen(S);
	for (int I=0;I<Size1;I+=2)
	{
		char WS=S[I];
		S[I]=S[I+1];
		S[I+1]=WS;
	}
	for (I=1;I<Size;I+=2){
		if (S[I]>='M' && S[I]<='U'){
			S[I]='@';
		}
	}

	void main()
	{
		STRING Word='CRACKAJACK';
		MIXITNOW(Word);
		cout<<Word<<endl;
	}
}
143 Views

Advertisement
5.

Find and write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program.

class Stock
{
	long int ID;
	float Rate; int Date;
public:
	Stock(){ID=1001;Rate=200;Date=1;}
	void RegCode(long int I,float R)
	{
		ID=I; Rate=R;
	}
	void Change(int New,int DT)
	{
		Rate+=New; Date=DT;
	}
	void Show()
	{
		cout<<"Date :"<<Date<<endl;
		cout<<ID<<"#"<<Rate<<endl;
	}
};

void main()
{
	Stock A,B,C;
	A.RegCode(1024,150);
	B.RegCode(2015,300);
	B.Change(100,29);
	C.Change(20,20)
	;
	A.Show();
	B.Show();
	C.Show();
}

79 Views

6.

Look at the following C++ code and find the possible output(s) from the options (i) to (iv) following it. Also, write the maximum and the minimum values that can be assigned to the variable CHANGER.
Note:
● Assume all the required header files are already being included in the code.
● The function random(n) generates an integer between 0 and n‐1.

void main()
{
	randomize();
	int CHANGER;
	CHANGER=random(3);
	char CITY[][25]={"DELHI","MUMBAI","KOLKATA","CHENNAI"};
	for(int I=0;I<=CHANGER;I++)
	{
		for(int J=0;J<=I;J++){
			cout<<CITY[J];
		}
		cout<<endl;
	}
}
(i) (ii)
DELHI
DELHIMUMABAI
DELHIMUMABAIKOLKATA
DELHI
DELHIMUMABAI
DELHIMUMABAIKOLKATA
DELHIMUMABAIKOLKATACHENNAI
(iii) (iv)
MUMABAI
MUMABAIKOLKATA
MUMABAIKOLKATACHENNAI
KOLKATA
KOLKATACHENNAI
88 Views

Advertisement

7.

Differentiate between Constructor and Destructor functions giving suitable example using a class in C++. When does each of them execute?


 

Constructor

Destructor

Purpose

Constructor is used to initialize the instance of a class.

Destructor destroys the objects when they are no longer needed.

When Called

Constructor is Called when new instance of a class is created.

Destructor is called when instance of a class is deleted or released.

Memory Management

Constructor allocates the memory.

Destructor releases the memory.

Arguments

Constructors can have arguments.

Destructor can not have any arguments.

Overloading

Overloading of constructor is possible.

Overloading of Destructor is not possible.

Name

Constructor has the same name as class name.

Destructor also has the same name as class name but with (~) tiled operator.

Syntex

ClassName(Arguments)
{
//Body of Constructor
}

~ ClassName()
{
}

Example:
Class Exam
{
int Eno; float Marks;
public:
Exam() //Constructor
{
Eno=1; Marks = 100;
cout<<'Constructor executed...'<<endl;
}
void Show()
{
cout<<Eno<<'#'<<Marks<<endl;
}
~Exam() //Destructor
{
cout<<'Exam Over'<<endl;
}

void main()
{
Exam E; //Executes constructor
E.Show();
} //Executes Destructor
63 Views

Advertisement
8.

Observe the following C++ code and answer the questions (i) and (ii). Assume all necessary files are included:

class FICTION
{
	long FCode;
	char FTitle[20];
	float FPrice;
public:
FICTION() //Member Function 1
{
	cout<<"Bought"<<endl;
	FCode=100;strcpy(FTitle,"Noname");FPrice=50;
}
FICTION(int C,char T[],float P) //Member Function 2
{
	FCode=C;
	strcpy(FTitle,T);
	FPrice=P;
}
void Increase(float P) //Member Function 3
{
	FPrice+=P;
}
void Show() //Member Function 4
{
	cout<<FCode<<":"<<FTitle<<":"<<FPrice<<endl;
}
~FICTION() //Member Function 5
{
	cout<<"Fiction removed!"<<end1;
}
};
void main()	 //Line 1
{               //Line 2
FICTION F1,F2(101,"Dare",75); 	//Line 3
for (int I=0;I<4;I++) 		//Line 4
{    //Line 5
	F1.Increase(20);F2.Increase(15); 	//Line 6
	F1.Show();F2.Show();  	//Line 7
}		//Line 8
}		//Line 9

Which specific concept of object-oriented programming out of the following is illustrated by Member Function 1 and Member Function 2 combined together?

  1. Data Encapsulation
  2. Data Hiding
  3. Polymorphism
  4. Inheritance
64 Views

Advertisement
9.

Observe the following C++ code and answer the questions (i) and (ii). Assume all necessary files are included:

class FICTION
{
	long FCode;
	char FTitle[20];
	float FPrice;
public:
FICTION()         //Member Function 1
{
	cout<<"Bought"<<endl;
	FCode=100;strcpy(FTitle,"Noname");FPrice=50;
}
FICTION(int C,char T[],float P) //Member Function 2
{
	FCode=C;
	strcpy(FTitle,T);
	FPrice=P;
}
void Increase(float P) //Member Function 3
{
	FPrice+=P;
}
void Show() //Member Function 4
{
	cout<<FCode<<":"<<FTitle<<":"<<FPrice<<endl;
}
~FICTION() //Member Function 5
{
	cout<<"Fiction removed!"<<end1;
}
};
void main() //Line 1
{               //Line 2
FICTION F1,F2(101,"Dare",75); //Line 3
for (int I=0;I<4;I++)                //Line 4
{                                             //Line 5
F1.Increase(20);F2.Increase(15); //Line 6
F1.Show();F2.Show();     //Line 7
}     //Line 8
}      //Line 9

How many times the message "Fiction removed!" will be displayed after executing the above C++ code? Out of Line 1 to Line 9, which line is responsible to display the message "Fiction removed!"?

58 Views

10.

Write the definition of a class METROPOLIS in C++ with the following description:

Private Members

-Mcode       //Data member for Code (an integer)
-MName    //Data member for Name (a string)
-MPop      //Data member for Population (a long int)
-Area      //Data member for Area Coverage (a float)
-PopDens //Data member for Population Density (a float)
CalDen()//A member function to calculate
           //Density as PopDens/Area

Public Members

-Enter() //A function to allow user to enter values of
            //Mcode,MName,MPop,Area and call CalDen()
           //function
-ViewALL()//A function to display all the data members
               //also display a message ”Highly Populated Area”
             //if the Density is more than 12000

102 Views

Advertisement