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


0 comments:

Post a Comment

Thanks for leaving a comment. As soon as it's approved, it will appear.