Wednesday

Control Flow and Functions Control Flow Question Answers

 

Topic – 2
Control Flow and Functions Control Flow

1 Mark Questions

Question 1:
Ronica Jose 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() 
double X,Times,Result; 
cin>>X>>Times;
Result=pow(X,Times); 
cout<<Result<<endl ;

All India 2016
Аnswer:

Ciostream. h>→cout, cin
<math. h>→pow()

Question 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 this code.

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

Аnswer:
<iostream.h>→cout, cin
<math.h>→pow( )

Question 3:
Ahmad has started learning C++ and has typed the following program. When he compiled the following code written by him, he discovered that he 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 Radians,Value; 
cin>>Radians;
Value=sin(Radians); 
cout<<value<<endl;
} All India 2016C

Аnswer:
<iostream.h>→cout, cin
<math.h>→sin( )

Question 4:
Observe the following C ++ code and write the name(s) of the header file(s), which will be essentially required to run it in a C ++ compiler.

void main()
{
float Area,Side;
cin>>Area;
Side=sqrt(Area);
cout<<"0ne Side of the Square:"<<Side<<endl;
} All India 2013

Аnswer:
<iostream.h>→ cout,cin
<math.h> →sqrt( )

Question 5 :
Observe the following C ++ code and write the name(s) of the header file(s), which will be essentially required to run it in a C++ compiler.

void main()
{
int Number;
cin>>Number;
if(abs(Number) == Number); 
cout<<"Positive"<<endl;
} Delhi 2013

Аnswer:
<iostream.h>→ cout, cin
<math.h>→abs( )

Question 6:
Name the header file(s), which are essentially required to run the following program segment.

void main()
}
char A='K',B;
if(islower(A))
B=toupper(A);
else
B='*';
cout<<A<<"turned to"<<B<<endl:
} Delhi 2013C

Аnswer:
<iostream.h>→cout,cin
<ctype.h>→ islower( ); i supper( )

Question 7:
Write the names of the header files to which the following belong:

  1. puts( )
  2. sin( ) Delhi2009

Аnswer:
puts( )→<stdio.h>
sin( )→<math.h>

Question 8:
Write the names of the header files to which the following belong:

  1. setw( )
  2. sart( ) All India 2009

Аnswer:
setw( )→<iomanip.h>
sqrt( )→<math.h>

Question 9:
Write the names of the header files to which the following belong:

  1. puts( )
  2. randomizer( ) Delhi2009c

Аnswer:
puts( )→<stdio.h>
randomize( )→<stdlib.h>

 

2 Marks Questions

Question 10:
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.

void main()
{
cout<<"Enter an Alphabet:"; 
cin>>CH ;
switch(CH) 
case 'A' cout<<"Ant";Break; 
case ’B' cout<<"Bear”;Break;
} All India 2017

Аnswer:

The correct code is:
void main()
{
char CH:
cout<<”Enter an Alphabet:";
cin>>CH ;
switch(CH)
{
case 'A': cout«"Ant"; break:
case 'B'x cout<<"Bear"; break:
}
}

Tuesday

Important Question - Class 12- C++

 Question 7:

Find the correct identifiers Out of the following, which can be used for naming Variable, Constants or Functions in a C ++ program: Delhi 2015
While, for, Float, new, 2ndName, A%B, Amountl2, _Counter
Аnswer:
The correct identifiers are as follows:
While, Float, Amount 12 and_Counter

Question 8:
Find the correct identifiers out of the following, which can be used for naming Variables, Constants or Functions in a C++
For, while, INT, NeW, delete, 1stName, Add+Subtract, name1
Аnswer:
The correct identifiers are as follows:
For, INT, NeW and name1

Question 9:
Observe the following C++ code carefully and rewrite the same after removing all the syntax error(s) present in the code. Ensure that you underline each correction in the code. All India 2013
Important Note:
(i) All the desired header files are already included, which are required to run the code.
(ii) Correction should not change the logic of the program.

//define Change(A,B)2*A+B; 
void maint()
{
Float X,Y,F; 
cin>>X>>Y ;
F=Change[X,Y]; 
cout<<"Result:"<<F<endline;
}

Аnswer:

The correct code is:
#define Change (A.B)(2*A+B) 
void main() 
{
float X.Y.F: 
cin>>X>>Y;
F=Chanae(X.Y):
cout<<"Result:”<<F<<end1:
}

Question 10:
Observe the following OH- code carefully and rewrite the same after removing all the syntax error(s) present in the code. Ensure that you underline each correction in the code.
Important Note:
(i) All the desired header files are already included, which are required to run the code.
(ii) Correction should not change the logic of the program. Delhi 2013

//define Convert(P,Q)P+2*Q; 
void main()
{
Float A,B,Result: 
cin>>A>>B;
Result=Convert[A,B]; 
cout<<"Output:"<<Result<endl:
}

Аnswer:

The correct code is:
#define Convert(P,Q)(P+2*Q) 
void main()
{
float A,B,Result; 
cin >>A>>B;
Result=Convert(A.B): 
cout<<"0utput"<<Result<<endl:
)

Question 11:
Give the difference between the type casting and automatic type conversion. Also, give a suitable C++ code to illustrate both. All India 2012,2011 Delhi 2010
Аnswer:
Type casting It is used by the programmer to convert the value of one type to another type,
e.g. float X=(float) 15/6:
Automatic type conversion It is automatically done by the compiler itself wherever required.
e.g. float X=3;

Question 12:
What is the difference between local variable and global variable? Also, give a suitable C++ code to illustrate both. Delhi 2011
Аnswer:
A variable which is declared within the body of a function and accessible only within the function is known as local variable.
A variable which is declared outside any function and accessible to all functions in a program is known as global variable.
To illustrate this, below is given programming example:

#include<iostream.h>
float area;     //Global variable
void cirarea()
{
float r;   //Local variable
cin>>r
area=3.14*r*r; 
cout<<area; 
}
void rectarea()
{
float l,b; //Local variables
cin>>l>>b;
area=l*b;
cout<<area;
}
void main()
{
cirarea(); 
rectarea();
}

Question 13:
What is the function of typedef in C++? Also, give a suitable C++ code to illustrate it. Delhi 2011C
Аnswer:
typedef keyword is used to assign alternative names to existing types.
e.g. typedef int in;
Now, whenever we want to declare a variable of type integer, rather than using int we can use ‘in’
keyword in place of int.
e.g.

void main()
{
typedef int in;
//in is an alternative name to int in a=10;
//a is of type integer cout<<a;
}

Question 14:
What is the function of #define keyword? Give an example to illustrate its use. Delhi 2009C
Аnswer:
#define keyword is a preprocessor directive that is used to define a macro or a symbolic constant.
Syntax
#define macroname expression
or
#define symbolic constant-value
e.g.
#define Area(R) 3.14*R*R
#define Max 100


Wednesday

Important Questions for Class 12 Computer Science (C++) – C++ Revision Tour

 

Topic – 1
Fundamentals

Previous Years Examination & Important Questions
2 Marks Questions

Question 1:
Write the type of C++ tokens (keywords and user defined identifiers) from the following: All Indio 2017

  1. new
  2. While
  3. case
  4. Num_2

Аnswer:

  1. new → keyword
  2. While → user defined identifier
  3. case → keyword
  4. Num_2 → user defined identifier

Question 2:
Out of the following, find those identifiers, which cannot be used for naming Variable, Constants or Functions in a C++ program: Delhi 2016
Cost, Price*Qty, float, Switch, Address One. Delete, Number12, do
Аnswer:
Price*Qty, float, do and Address One cannot be used for naming variables, constants or functions in a C++ program.

Question 3:
Rewrite the following C++ code after removing any/all syntactical errors with each correction underlined. Delhi 2016
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;
}

Аnswer:

The correct code is:
#define Equation(p,q)(P+2*Q)
void main()
{
float A=3.2,B=4.1; 
float C=Equation(A,B); 
cout<<"0utput ="<<C<<endl;
}

Question 4:
Out of the following, find those identifiers, which cannot be used for naming Variables, Constants or Functions in a C++ program: All India 2016
Fatal*Tax, double, Case, My Name, NeW, switch, Column31,_Amount
Аnswer:
Fatal*Tax, double, My Name, switch cannot be used for naming variables, constants or functions in a C++program.

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

#define Formula(a,b)=2*a+b 
void main()
{
float X=3.2;Y=4.1;
Z=Formula(X,Y);
cout<<'Result='<<Z<<endl;
}

Аnswer:

The correct code is:
#define Formula(a.b)(2*a+b)
void main()
{
float X=3.2.Y=4.1: 
float Z=Forinula(X.Y): 
cout<<"Result="<<Z<<endl:
}

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

define formula(a,b,c)a+2*b+3*c; 
void main()
{
int L=1,M=2,N=3,
J=Formula(L,M,N); 
cout<<'output ='<<J<<endl;
}

Аnswer:

The correct code is:
#define Formula(a,b,c)a+2*b+3*c 
void main()
{
int L=1,M=2,N=3:
int J=formula(L,M,N);
cout<<"0utput="<<j<<endl;
}

Tuesday

Class 12 - Computer Science with C++ Question Answers Chapter -OBJECT ORIENTED PROGRAMMING

 

1. What are programming paradigms? Give names of some popular programming paradigms.

Ans:

Programming Paradigm: A Programming Paradigm defines the methodology of designing and implementing programs using the key features and building blocks of a programming language. Following are the different programming paradigms: (i) Procedural Programming (ii) Object Based Programming (iii) Object Oriented Programming


2. Write a short note on OO programming.

Ans:

OOP stands for Object Oriented Programming. In, Object-Oriented Programming (OOP), the program is organized around the data being operated upon rather than the operations performed. The basic idea behind OOP is to combine both, data and its functions that operate on the data into a single unit called object. Following are the basic OOP concepts: 1. Data Abstraction 2. Data Encapsulation 3. Modularity 4. Inheritance 5. Polymorphism


3. Write a short note on inheritance.

Ans:

Inheritance enables us to create new classes that reuse, extend, and modify the behavior that is defined in other classes. The class whose members are inherited is called the base class, and the class that inherits those members is called the derived class. A derived class can have only one direct base class. Inheritance is transitive. When we define a class to derive from another class, the derived class implicitly gains all the members of the base class, except for its constructors and destructors.

4. What is the significance of private, protected and public specifiers in a class?

Ans:

A class groups its members into three sections: private, protected, and public. The private and protected members remain hidden from outside world. Thus through private and protected members, a class enforces data-hiding. The public members are accessible everywhere in a program.

5. Encapsulation is one of the major properties of OOP. How is it implemented in C++?

Ans:

A class binds together data and its associated functions under one unit thereby enforcing encapsulation as encapsulation means wrapping up data and associated functions together into a single unit. While implementing encapsulation, following things are taken care of: (i) Anything that an object does not know or cannot do is excluded from the objects. (ii) Encapsulation is used to hide unimportant implementation details from other objects. (iii) The data and associated functions are wrapped up in one unit called class. Through encapsulation, an interface is made available to world through which users can use the class.