• Skip to main content
  • Skip to primary sidebar
  • Skip to footer
  • NCERT Solutions
    • NCERT Books Free Download
  • TS Grewal
    • TS Grewal Class 12 Accountancy Solutions
    • TS Grewal Class 11 Accountancy Solutions
  • CBSE Sample Papers
  • NCERT Exemplar Problems
  • English Grammar
    • Wordfeud Cheat
  • MCQ Questions

CBSE Tuts

CBSE Maths notes, CBSE physics notes, CBSE chemistry notes

Chapterwise Question Bank CBSE Class 12 Computer Science (C++) – C++ Revision Tour

Contents

  • 1 Chapterwise Question Bank CBSE Class 12 Computer Science (C++) – C++ Revision Tour
    • 1.1 Topic – 1 C++ Fundamentals
    • 1.2 Topic – 2 Flow of Control
    • 1.3 Topic – 3 Array and Function
    • 1.4 Topic – 4 Structure

Chapterwise Question Bank CBSE Class 12 Computer Science (C++) – C++ Revision Tour

Topic – 1
C++ Fundamentals

Exam Practice
Very Short Answer Type Questions [1 Mark]

Question 1:
Generally there are four data types, each of which can be signed or unsigned. Write names of all four data types.
Аnswer:
The four data types are : char, short, int and long.

Question 2:
Give the output of the following program:

int a = 44;
cout<<a++<<"\t"<<a<<"\n"<<++a; 
cout<<endl<<a<<endl;

Аnswer:
The output is as
45    45
45
46

Question 3:
Evaluate the following C++ expressions, where a, b and c are integers and d, f are floating point numbers. The values are: a = 5, b = 3 and d = 1.5
(i) c = a-(b + +)*(–d)
(ii) f=(+ + b)*b-a
Аnswer:

  1. 3
  2. 11

Question 4:
How ‘/’ operator is different from ‘%’ operator?
Аnswer:
‘/’ operator used to find the quotient, whereas ‘%’ operator used to find the remainder.

Question 5:
Write the difference between = and ==.
Аnswer:
= is a assignment operator, which assign a value while == is a relational operator, which test the equality.

Question 6:
What is wrong with the following C++ statement?
long float y;
Аnswer:
There is no data type as long float in C+ +. The double data type denotes the same, thus the statement should be double y;

Question 7: If v is an identifier of int type and is holding value 255. Is the following statement correct?
char code = v ;
Аnswer:
Yes, it is correct statement because a char can hold characters with equivalent ASCII values in the range 0-255.

Question 8:
Do you see any similarity between a typedef name and a reference name? If yes, what is it?
Аnswer:
Yes, there is a similarity between a typedef name and a reference name. A typedef name is an alias name of an already defined data type and a reference name is an alias name of an already defined variable.

Question 9:
Evaluate the following C++ expression for x = 10, y = 5 and z = 11 (x==y)\\ (!(z = y))&&(z < x)
Аnswer:

(x == y)||(!(z = y))&&(z<x)
= (10 = 5)||(!(11 = 5))&&(11<10)
= (10 = 5)||(1 && (11 < 10))
= (10 = 5)||(1 && 0)
= 0||0 
= 0

Question 10:
Which value ofx will be printed in following case and why?

int x = 9;
void main()
{
int x = 10; 
cout<<x;
}

Аnswer:
Value of x will be 10 because local variable hides global variable.

Question 11:
Differentiate between an identifier and keywords.
Аnswer:
An identifier is the name given by user for a unit of the program, e.g. CHK, Z2TOZ9, etc.
Keywords are the reserved words that convey a special meaning to the language compiler, e.g. auto, break, etc.

Question 12:
Show two different ways to declare as integer variable named intname and set its value to 15.
Аnswer:

  1. int intname;
    intname = 15;
  2. int intname =15;

Short Answer Type Questions [2 Marks]

Question 13:
An unsigned int can be twice as large as the signed int. Explain how?
Аnswer:
An unsigned int can represent 0 to 65536 values in total, whereas a signed int can represent – 32768 to 32767, i.e. 65536 values. The total numbers represented by both integers are the same but the range represented by unsigned int becomes double because in place of negative numbers positive values are represented thereby increasing the range by 32768 numbers as there are many negative values represented by signed int.

Question 14:
Given the following code fragment
int a = 5;
cout<<a<<++a<<a<<“\n”;

  1. What output does the above code fragment produce?
  2. What is the effect of replacing ++ a with o + 1?

Аnswer:

  1. 665
    This is because when multiple values are cascaded with cout, calculations take place from right to left but printing takes place from left to right.
  2. After replacing ++a with a +1, the output of the code will be:
    565

Question 15:
Give the difference between the type casting and automatic type conversion. Also, give a suitable C++ code to illustrate both.
All India 2012
Or
What is the difference between automatic conversion and type casting? Also, give a suitable C++ code to illustrate both.
Delhi 2008C
Аnswer:
Type casting It is used by the programmer to convert value of one type to another type. It is forced type conversion. It is done by putting the target datatype in parentheses before the data to be converted.
e.g. float X=(doubl e ) 15/6 ;
Automatic type conversion It is automatically done by the compiler itself wherever required. It is implicit type conversion.
e.g. float X=3;

Question 16:
What is the function of typedefin C++ Also, give a suitable C++ code to illustrate it.    Delhi 2011C
Or
What is the purpose of using a typedef command in C++. Explain with suitable example.    All India 2008
Аnswer:
typedef keyword is used to assign alternative names to existing data 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.

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

Question 17:
What is the difference between #define and const? Explain with suitable example.    Delhi 2008
Аnswer:
#define #define preprocessor directive is used to define a macro with some value/expression, which is substituted during compilation of program. Unlike variable, it does not occupy memory.

e.g.
#define Max 10 void main()
{
int arr[Max];
}

const It is used in declaration of a variable, it occupies memory to store a constant value, which once initialised cannot be changed, e.g. const int x=10;

Question 18:
Differentiate between a run-time error and syntax error. Also, give suitable examples of each in C++.
Аnswer:
Syntax error is that when statements are wrongly written violating rules of the programming language, e.g. Max + 2 = DMax is a syntax error as an expression cannot appear on the left side of an assignment operator. Runtime error occurs in a program during its execution. Program execution halts when such an error is encountered, e.g. division by zero, stack overflow, etc.

Question 19:
What is the function of#define keyword? Give an example to illustrate its use.    Delhi 2009C
Аnswer:
The #define preprocessor directive create symbolic constants. Constants are represented as symbols and macro operations. So, there is no data type checking for macros arguments.

e.g.
#include<iostream.h> 
#define pi 3.14159 
#define c_area(x) (pi*x*x) 
void main()
{
float area; 
int r;
cout<<"\nEnter the radius"; 
cin>>r;
area = c_area(r); 
cout<<"\nArea is:"<<area;
}

Output
Enter the radius 49
Area is: 7539.140137

Question 20:
Why main( ) function is important in C++? Give reason.
Аnswer:
C++ program is divided into several functions, out of them main( ) function is the most important one because without the main( ) function any program in C++ cannot execute. main( ) function is the entry point of any C+ + program, i.e. as soon as the program starts execution first function that is searched for execution is the main( ) function. So, every executable program of C + + must have exactly one main( ) function that is to be outside the class definition.

Question 21:
Write the output of the following program. All India 2002

void main()
{
int x=5, y=5;
cout<<x--; 
cout<<",";
cout<<--x; 
cout<<",";
cout<<y--<<","<<--y;
}

Аnswer:
The output is 5, 3, 4, 4

Question 22:
Find the output of the following program.

#include<iostream. h> 
void main()
{
int x = 5, y; 
y = x++ + ++x; 
cout<<++y<<" "<<y++;
}

Аnswer:
The output is 14 12

Question 23:
Differentiate between logical error and syntax error. Also, give suitable examples of each in C++.
Аnswer:
Logical error Wrong logic in the program causes a program to produce undesired output or no output. Such kind of errors are called logical errors. These errors depend on the logical explanation and are easy to detect, if we follow the line of execution and determine why the program takes that path of execution, e.g. if in place of \(a+\frac { b }{ 2 } \)  by mistake, \(a*\frac { b }{ 2 } \)  is written, it will be a logical error.
Syntax error A syntax error is the error that occurs when rules of C + + language are violated in the program, e.g. in statement cout<<“hello”.
∴ Statement(;) missing is a syntax error.

Question 24:
Identify the errors in the following code segment:

include<iostream.h>
Main();
{
Float x, y;
cout<"Enter two numbers"; 
cin>>a>>b
cout<<'The numbers in reverse order are'<<b,a;
}

Аnswer:

  1. # is missing.
  2. main should be in lower case, followed by no semicolon.
  3. float should be in lower case.
  4. Output operator should be <<.
  5. In place of a >> b, it should be x and y and semicolon is also missing.
  6. String should be enclosed in double quotes in place of single quotes and two numbers cannot be displayed as b, a, it shoulcfbe << in place of comma(,).

Question 25:
What output will the following code fragment produce?
int val, res, n = 1000;
cin>>val;
res = n + val > 1750 ? 400 : 200;
cout<<res;

  1. if the input is 2000
  2. if the input is 1000
  3. if the input is 500.

Аnswer:

  1. 400 because the arithmetic operator + has higher precedence than ? : operator, so the n+ val condition is taken as n+ val > 1750 = ( 1000 + 2000) > 1750 is true.
  2. 400 because (1000 +1000) > 1750 is true.
  3. 200 because (1000+ 500) > 1750 is false.

Question 26:
What is the difference between local variable and global variable?Also, give a suitable C++ code to illustrate both. Delhi 2011
Аnswer:
A global variable can be accessed by all functions. It is initialised at the beginning of the program and is deleted when program shuts down. A local variable is isolated in its function.
or
A variable which is declared within the body of a function and available only within the function is known as local variable. A variable which is declared outside any function and available to all functions in a program is known as global variable.
To illustrate this, below is 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;
cin>>b;
area = l*b;
cout<<area;
}
void main()
{
cirarea(); 
rectarea();
}

Question 27:
How precedence of assignment operators related to other operators? What is their associativity?
Аnswer:
The operators are hierarchically arranged according to their precedence or we can say according to the order of evaluation. Assignment operators like =, + =,-=,# =,/ =, etc., have a lower precedence than any of the other operators. Therefore, unary operations, arithmetic operations, relational operations, equality operations and logical operations are all carried out before assignment operations.
Associativity means the order in which consecutive operators within the same precedence group are carried out. The assignment operations have a right to left associativity, which means that the compiler starts on the right of the expression and works towards.

Question 28:
Why const keyword is mostly used rather than # define?
Аnswer:
const variable is a actual variable like other normal variable while #define is a preprocessor directive. Things define by #define are replaced by the preprocessor before compilation begins.
The main advantage of const over #define is type checking. We can also have pointers to const variables, we can pass them around, typecast them.
In case of const variable, We can control its scope by placing it either inside or outside a function, but in case of #define directive. Each time when preprocessor see the function or variable in the whole program, it inserts its definition is place of that function. Because the preprocessor runs before the compiler, the compiler never sees the constants, it sees only the variable or the definition of that function.

Question 29:
Differentiate between the post-increment and pre-increment operators. Also, give a suitable C++ code to illustrate both.
Аnswer:
When ++ operator is used after an operand to increment its value by 1. It is called a post-increment operator. By post-increment operator, the value of the operand is first used in the expression and then the operand’s value is incremented by 1.
When ++ operator is used before an operand to increment its value by 1. It is called a pre-increment operator. By pre-increment operator, the value of the operand is first incremented by 1 and then the operand’s value is used in the expression.
eg-

int a = 5, b = 5, c = 0, d = 0; 
c = c+ ++a ; 
d = d+b++; 
cout<<c<<a<<endl; 
cout<<d<<b;
The output is:
66
56

Topic – 2
Flow of Control

Exam Practice
Very Short Answer Type Questions [1 Mark]

Question 1:
How is an entry controlled loop different from exit controlled loop?
Аnswer:
In an entry controlled loop, the condition is evaluated at the entry point of the loop, e.g. for and while loop. While in an exit controlled loop, the condition is evaluated at the exit point of the loop, e.g. do-while loop.

Question 2:
What is the effect of absence of break in switch-case statement?
Аnswer:
In switch-case statement, when a match is found, the statement sequence associated with that case is executed until a break statement or the end of switch statement is reached. So, if break statement is missing, then the statement sequence is executed until the end of the switch-case statement is reached.

Question 3:
How many times is the loop executed?

int i=0, j=0; 
do 
{
i+=j;
}
whi1e(j<5);

Аnswer:
Infinite loop because the value of i and j is always equal to zero.

Question 4:
In the following program:

  1. How many times will the while loop run?
  2. What would be the last value of A displayed out?
#include<iostream.h> 
void main()
{
int A =10;
whi1e(++A<15)
{
cout<<A++;
}
}

Аnswer:

  1. 2 times the while loop will run.
  2. The last value of A displayed out is 13.

Question 5:
What will be the output of the following program?

#include<iostream.h> 
void main()
{
int ind;
for(ind=0;ind<=10;ind++) 
cout<<" "<<ind;
}

Аnswer:
The output is
0 1 2 3 4 5 6 78 9 10

Question 6:
Default clause is a good practice to give in the switch statement. Explain why?
Аnswer:
The default statement gives the switch construct or statement, a way to take action if the value of the switch variable does not match any of the case constants.

Short Answer Type Questions   [2 Marks]

Question 7:
Find the output of the following
program:    All India 2008

#include<iostream.h> 
void main()
{
int A = 5, B = 10; 
for(int I=1;I<=2;I++)
{
cout<<"Line 1="<<A++<<"&"<<B-2<<endl;
cout<<"Line 2="<<++B<<"&"<<A+3<<endl;
}
}

Аnswer:
Line 1 = 5&8
Line 2 = 11&9
Line 1=6&9
Line 2= 12&10

Question 8:
Find the output of the following program:    Delhi 2008C

#include<iostream.h> 
void main() 
{
int First = 25,Sec = 30;   
for(int I=1;I<=2;I++)
{
cout<<"0utput 1="<<First++<<"&"<<Sec+5<<endl;
cout<<"Output 2="<<—Sec<<"&"<<First-5<<endl;
}
}

Аnswer:
Output 1=25 & 35
Output 2=29 & 21
Output 1=26& 34
Output 2 =28&22

Question 9:
Find the output of the following program:

#include<iostream.h> 
void main()
{
long NUM = 1234543; 
int F = 0,S = 0; 
do
{
int Rem = NUM%10; 
if(Rem%2 !=0)
F += Rem; 
else
S += Rem;
NUM /= 10;
}
while(NUM>0); 
cout<<F-S;
}

Аnswer:
2

Question 10:
Rewrite the following program after removing the syntactical error(s), (if any). Underline each correction.

#include<iostream.h> 
const int Multiple 3; 
void main()
{
Value = 15;
for(int Counter=1;Counter=<5;Counter++,Value-=2) 
if(Va 1ue%Multipie == 0) 
cout<<Value*Multipie; 
cout<<endl; 
else
criut<<Value+Multipie<<endl;
}

Аnswer:

#include<iostream.h>
const int Multipie=3; //Correction 1 void main( )
{
int Value=l5;    //Correction 2
for(int Counter=l;Counter<=5;Counter++,Value-=2) //Correction 3
if(Value%Multipie == 0) 
{
cout<<Value*Multipie; 
cout<<endl;
}    //Correction 4
else
 cout<<Value+Multipie<<endl;
}

Correction 1 Multiple must be assigned a value.
Correction 2 Variable value must be declared with data type.
Correction 3 =< must be replace with < =.
Correction 4 Misplace else; so after if compound statement must be enclosed with {}.

Question 11:
Rewrite the following set ofif-else statement in terms of switch-case statement.

int num, val; 
cin>>num; 
if(num==5)
{
val=num*5; 
cout<<num + val; 
}
else if(num==10)
{
val=num*5;
cout<<val-num;
}

Аnswer:

int num, val; 
cin>>num; 
switch(num)
{
case 5: val = num*5;
cout<<num+val; 
break;
case 10: val = num*5;
cout<<val-num;
break;
}

Question 12:
Write a for loop for the following sequence of statements without effecting the output.

int Lvalue=9;
cout<<Lvalue<<endl;
cout<<Lvalue+l<<endl<<Lva1ue-l<<endl;
Lva1ue = Lvalue-3;

Аnswer:

for(int Lvalue=9;Lvalue =9;Lvalue -= 3)
{
cout<<Lvalue<<endl;
cout<<Lvalue+l<<endl<<Lvalue-l<<endl;
}

Question 13:
Will the following program execute successfully? If not, state the reason (s).

#include<stdio.h> 
void main()
{
int X, sum=0; 
cin<<n;
for(X=1,x<100,x+=2) 
if x%2==0 
sum +=x;
cout>>"sum=">>sum;
}

Аnswer:

The given program does not execute successfully because following errors are occurred during 
the execution:
#include<iostream.h> //required for cin and cout 
#include<stdio.h> 
void main()
{
int X, sum=0,n;   //n should be declared before use 
cin>>n;          /*Here should be input operator >> in place of output operator<<*/ 
for(X=1_L X<100_L X+=2)  /*Here should be(;) in place of(,) and X in place of x.*/ 
if(X%2==01)
sum+=X;      /*If expression should closed in brackets () and here, 
should be X in place of x*/ 
cout<<"sum="<<sum: /*Here should be output operator « in place of input operator >> */
}

Question 14:
What is wrong with the following while loop and how does the correct ones look like?

int c=1;
while(c<100) 
cout<<c<<"\n"; 
c++;

Аnswer:
In this loop, there are not brackets surrounding the code block of the while loop. Therefore, only the line immediately following the while statement repeats. Since, that line does not modify counter, its value will always be 1. Hence, it’s form infinite loop. To fix, we need to add grouping bracket around the lines after the while loop, i.e. whi1e(c<100)

{
cout<<c<<"\n";
c++;
}

Question 15:
What will be printed on the console by the code below?

#include<iostream.h>
#includeCconio. h> 
void main()
{
int x=9,y=7,z=2,k=0,j=0; 
double m=1.1; 
clrscr(); 
if(x>y)
{
if(y>z&&y>k)
{
m--;
}
else 
{
k++;
}
}
else 
{
J++;
}
cout<<"m="<<m<<endl;
cout<<"k="<<k<<endl; 
cout<<"j="<<j<<endl;
getch();
}

Аnswer:
m=o.1
k=0
j=0

Long Answer Type Questions [4 Marks]

Question 16:
Write a program in C++ to print first 10 multiples of an integer N, where N is to be entered by user:
Аnswer:

#include<iostream.h>
#include<conio.h> 
void main()
{
int n,i;
clrscr();
cout<<"Enter the number to find the multipie":
cin>>n;
for(i=1;i<=10;i++)
cout<<n<<"*"<<i<<"="<<n*i<<endl;
getch();
}

Question 17:
Write a program to print the following pyramid:
chapterwise-question-bank-cbse-class-12-computer-science-c-c-revision-tour-(23-1)
Аnswer:

#include<iostream.h>
#include<conio.h> 
void main()
{
int ch=65,j,m=2,n=1; 
char c; 
clrscr();
for(int i=1;i<=7;i++)
{
c=ch; 
if(i<=4)
{
for(j=3;j>=i;j--) 
cout<<" "<<'\t';
for(j=1;j<=i;j++)
{
cout<<c<<'\t'; 
c++;
}
c--;
for(j=1;j<=i-1;j++) 
{
c--;
cout<<c<<'\t';
else
{
for(j=1;j<=n;j++) 
cout<<" "<<'\t'; 
for(j=1;j<=i-m;j++) 
{
cout<<c<<'\t'; 
c++;
}
c--;
for(j=1;j<=i-m-1;j++) 
{
c--;
cout<<C<<'\t';
}
m=m+2; 
n=n+l;
}
cout<<endl<<endl;
}
getch();
}

Question 18:
Write a program to print the following output after inputing the value of n. The user should be prompted again for the value of n, if the inputted value does not lie between 1 to 6 do the inclusive.
chapterwise-question-bank-cbse-class-12-computer-science-c-c-revision-tour-(23-2)
Аnswer:

#include<iostream.h>
#include<conio.h> 
void main()
int a; 
do
{
cout<<"Enter a"; 
cin>>a;
}
whi1e((a<1)||(a<6)); 
for(int i=0;i<=a;i++)
{
for(int k=1;k<=(a-i);k++) 
cout<<" "<<" "; 
for(int j=1;j<=(2*i-1);j++) 
cout<<j<<" "<<" "; 
cout<<"\n";
}
getch();
}

Question 19:
Write a program to generate prime numbers upto N. Where, N is a user input more than 3. A wrong input should display proper error message.
Аnswer:

#include<iostream.h>
#include<stdio.h>
#include<conio.h> 
void main()
{
int N,i,f,j; 
clrscr();
cout<<"Enter any number "; 
cin>>N;
if(N<=3) 
{
cout<<"Input value is less than or equal to 3";
getch();
}
else
{
i=2,j=l;
cout<<"The prime numbers are;\n"; 
whi1e(j<=N)
{
f=0,i=2; 
whi1e(i<j)
{
if(j%1—0)
{
f=1;
break;
}
i++;
}
if(f==0)
cout<<j<<endl; 
j++;
}
}
getch();
}

Question 20:
Write a C++ program to generate and display all the armstrong numbers between 1 and 200.
Аnswer:

#include<iostream.h>
#include<conio.h> 
void main() 
{
int i,j,k,l; 
clrscr(); 
cout<<"The armstrong numbers in between 1 and 200 are"; 
for(i=1;i<=200;i++)
{
k=0,j-1; 
whi1e(j!=0)
{
l=j%10; 
k=k+l*l*l; 
j=j/10;
}
if(k==i)
cout<<"\n"<<i;
}
getch();
}

Question 21:
Write a program to accept a date (dd/mm/yyyy) and check the validity of date.
Аnswer:

#include<iostream.h>
#include<conio.h> 
void main()
{
int dd,mm,yy; 
clrscr() ;
cout<<"Enter the date"; 
cin>>dd>>mm>>yy;
if(mm=l||mm==3||mm==5||mm==7||mm==8||mm==10||mm==12)
{
if(dd <=31&&dd>0)
cout<<"Valid date"; 
else
cout<<"Invalid date";
}
else
{
if(mm==4||mm==6||mm==9||mm=11)
{
if(dd<=30&&dd>0)
cout<<"Valid date"; 
else
cout<<"Invalid date";
}
else if(mm==2)
{
if((yy%400==0)||(!yy% 100===0 )&&(yy%4==0))
{
if(dd>0&&dd<=29)
cout<<"Valid date”; 
else
cout<<"Invalid date";
}
else
if(dd>0&&dd<=28)
cout<<"Valid date"; 
else
cout<<"Invalid date";
}
else
cout<<"Invalid date";
}
getch();
}

Question 22:
List the output of the program below. In other words, everytime there is a cout statement, list the values that will appear on the screen.

#include<iostream.h>
#include<conio.h> 
void main()
{
clrscr();
for(int i=1;i<3;i++) 
for(int j=1;j<=5;j+=2)
 cout<<i<<"*"<<j<<"="<<i*j<<endl; 
double a=1; 
while(a<32) 
a *= 2;
cout<<"a="<<a<<endl; 
i=8,j=3; 
int k=i/j; 
double b=i/j;
double c=((double)i/(double)j); 
cout<<"Now k="<<k<<", b="<<b<<,c="<<c<<endl;
getch();
}

Аnswer:
Output
1 * 1=1
1 * 3 =3
1 * 5 =5
2 * 1 =2
2 * 3 =6
2 * 5 =10
a =32
Now k=2, b=2, c=2.666667

Topic – 3
Array and Function

Exam Practice
Very Short Answer Type Questions [1 Mark]

Question 1:
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. Delhi 2014

void main()
{
char Text[20],C; 
cin>>Text;
C=tolower(Text[0]); 
cout<<C<<"is the first char of"<<Text<<endl;
}

Аnswer:

iostream.h → cout, cin 
ctype.h → tolower()

Question 2:
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. Delhi 2013

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

Аnswer:

iostream.h → cin, cout 
math.h → abs()

Question 3:
Which C++ header file (s) are essentially required to be included to run/execute the following C++ source code? (Note: Do not include any header file, which is /are not required). Delhi 2012

void main()
{
char STRING[] = "SomeThing"; 
cout<<”Balance Characters:";
cout<<160-strlen(STRING)<<endl;
}

Аnswer:

#include<iostream.h> → cout
#include<string.h> → strlen()

Question 4:
Write the names of the header files, which is/are essentially required to run/execute the following C++ code.
All India 2011

void main()
{
char CH, Text[]="+ve Attitude";
for(int I=0;Text[I]!='\0';I++) 
if(Text[I]==' ') 
cout<<endl; 
else 
{
CH=toupper(Text[I]); 
cout<<CH;
}
}

Аnswer:

iostream.h → cout 
ctype.h → toupper()

Question 5:
Which C++ header file (s) will be essentially required to be included to run/execute the following C++ code? Delhi 2010

void main()
{
int Eno_123;
char EName[]="RehanSwarop"; 
cout<<setw(5)<<Eno_123<<setw(25)<<EName<<endl;
}

Аnswer:

#include<iostream.h> → cout 
#include<iomanip.h> → setw()

Question 6:
Write the names of the header files to which the following belong: Delhi 2009
(i) puts( )
(ii) sin( )
Аnswer:

(i) puts() belongs to #include<stdio.h>
(ii) sin() belongs to #include<math.h>

Question 7:
Is it necessary to include a header file in a program? If it is not done, what happens?
Аnswer:
If input/output processing or any functioning is required, then a header file appropriate for it must be included. In the absence of any header file, we can only declare variables and assign values to it but no input/output or specific functioning can take place.

Question 8:
How empty parentheses is important in a function declaration?
Аnswer:
Empty parentheses in a function declaration like void abc( ) means that the function does not pass any parameter.

Question 9:
When will you make a function inline?
Аnswer:
When the size of the code of a function is so small, that the overhead of the function call becomes prominent then the function should be declared as inline.

Question 10:
A function printing is defined as

void printing(char c = '*',int l = 40) 
{
for(int x=0;x<l;x++) 
cout<<c; 
cout<<endl;
}

How will you invoke the function printing for following output:
(i) to print ‘*’40 times
(ii) to print ‘=’ 30 times

Аnswer:

  1. printing( ) ;
  2. printing( ‘ = ‘ , 30) ;

Question 11:
What is the purpose of header files in a program?
Аnswer:
Header files provide function prototype declarations for library functions. Header files are also known as include files.

Question 12:
In an array declaration, there are two ways to specify the size of the array, one explicitly and one implicitly. Give examples of both.
Аnswer:
char A [ ] ={’a’, ‘ b ’. ‘ c ‘} :
This type is implicit because the size of the array (3) is inferred by the number of array elements, char A[3];
This is explicit because the 3-element array is always allocated, even though none of the element values are known.

Short Answer Type Questions [2 Marks]

Question 13:
What is the difference between actual and formal parameter? Give a suitable example to illustrate using a C++ code. Delhi 2014,2012; All India 2009
Аnswer:
Differences between actual and formal parameters are as follows:

Actual Parameter Formal Parameter
Parameters provided at the time of function calling are called actual parameters. Parameters provided at the time of function definition are called formal parameters.
These parameters contain actual values. These parameters are simple variable declarations, i.e. they do not contain actual values.

e.g. Program to swap the value of two numbers to show actual and formal parameters.

#include<iostream.h>
#include<conio.h> 
void swapCint n1, int n2) //Formal Parameters 
{
int temp = n1; 
n1 = n2; 
n2 = temp;
cout<<"Values of num1 and num2 after swapping; "; 
cout<<n1<<" "<<n2;
}
void main()
{
int numl, num2; 
clrscr();
cout<<"Enter two numbers: "; 
cin>>num1>>num2;
swap(num1,num2); //Actual parameters 
getch();
}

Question 14:
Rewrite the following C++ code after removing all the syntax error(s), if present in the code. Make sure that you underline each correction done by you in the code. Delhi 2014
Important Note

  • Assume that all the required header files are already included, which are essential to run this code.
  • The correction made by you do not change the logic of the program.
typedef char[50] STRING; 
void main()
{
City STRING; 
gets(City);
cout<<City[0]<<'\t<<City[2]; 
cout<<City<<endline;
}

Аnswer:

The corrected will be as follows:
typedef char STRINGf501: //Error 1 
void main()
{
STRING City;    //Error 2
gets(City);
cout<<City[0]<<'\t'<<Cit[2]; //Error 3
cout<<Citv<<endl;   //Error 4
}

Error 1 typedef keyword is used to give another name to a data type.
Error 2 While declaring a variable, first we have to write a data type and then variable name. Here, STRING is another name for char type array.
Error 3 Escape sequence \t must be enclosed in single quotes because it represents a tab space character.
Error 4 endl manipulator is used for ending a line and placing the cursor in new line.

Question 15:
Read the following C++ code carefully and find out, which out of the given options (i) to (iv) are the expected correct output(s) of it. Also, write the maximum and minimum value that can be assigned to the variable Taker used in the code. All India 2014

void main()
{
int GuessMe[4]={100, 50, 200, 20}; 
int Taker=random(2)+2; 
for(int Chance=0;Chance<Taker;Chance++) 
cout<<GuessMe[Chance]<<"#";
}
(i) 100#    
(ii) 50#200#
(iii) 100#50#200#   
(iv) 100#50#

Аnswer:
Correct output for the given code would be option
(iii) and (iv).
Minimum value of variable Taker=2
Maximum value of variable Taker=3

Question 16:
What is the benefit of using function prototype for a function? Give a suitable example to illustrate it using a C++ code. Delhi 2013
Аnswer:
The function prototype serves to ensure that calls to the function are made with the proper number and types of arguments. In the case of function overloading, the different prototypes serve to distinguish, which version of the function to call.
The compiler will complain with an error, if no function prototype is found for any particular call to a function.
e.g. Program to illustrate use of function prototyping.

#include<iostream.h>
int square(int); //Function prototype 
int main()
{
for(int x=1;x<=10;x++) 
cout<<square(x)<<" ";
cout<<endl; 
return 0;
}     //Function definition
int square(int y)
{
return(y*y);
}

Question 17:
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. Delhi 2013
Important Note

  • All the desired header files are already included, which are required to run the code.
  • Correction should not change the logic of the program.
#define Convert(P, Q) P+2*Q;
void main()
{
float A, B, Result; 
cin>>A>>B;
Result = Convert[A,B];
cout<<"Output:"<<Result<<endline;
}

Аnswer:

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

Question 18:
Find the output of the following program: Delhi 2010

#include<iostream.h>
#include<ctype.h>
void changelt(char Text[], char C)
{
for(int K=0;Text[K]!='\0';K++) 
{
if(Text[K]>='F' && Text[K]<='L') Text[K]=tolower(Text[K]); 
else
if(Text[K]=='E'||Text[K]=='e')Text[K]=C; 
else
if(K%2 == 0)
Text[K] = toupper(Text[K]); 
else
Text[K] = Text[K-1];
}
}
void main()
{
char OldTex[t] = "pOwERALone";
changeIt(oldText,'%');
cout<<"New Text:"<<oldText<<endl;
}

Аnswer:

New Text : PPW%RRllN%

Question 19:
Find out the expected correct output(s) from the options (i) to (iv) for the following C++ code. Also, find out the minimum and the maximum value that can be assigned to the variable stop used in the code. Delhi 2013C

void main()
{
int Begin=3, stop; 
for(int Run=1;Run<4;Run++)
{
stop=random(Begin)+6; 
cout<<Begin++<<stop<<"*";
}
}
(i) 36*46*59* 
(ii) 37*46*56*
(iii) 37*48*57*   
(iv) 35*45*57*

Аnswer:
Minimum value is 6
Maximum Value is 8
Expected output : (ii) and (iii)

Question 20:
Observe the following program and find out which output(s) out of(i) to (iv) will not be expected from the program ? What will be the minimum and the maximum value assigned to the variable chance? All India 2012

#include<iostream.h>
#include<stdlib.h> 
void mail()
{
randomize(); 
int Arr[]={9,6},N; 
int Chance=random(2)+10; 
for(int C=0;C<2;C++)
{
N=random(2);
cout<<Arr[N]+Chance<<"#";
}
}
(i) 9#6#   
(ii) 19#17#
(iii)19#16#)    
(iv) 20#16#

Аnswer:
(i), (ii) and (iv) will not be expected from the program.
Maximum value of chance =11
Minimum value of chance =10

Question 21:
Based on the following C++ code, find out the expected correct output(s) from the options (i) to
(iv). Also, find out the minimum and the maximum value that can be assigned to the variable Trick used in code at the time when value of Count is 3. Delhi 2013

#include<iostream.h>
#include<conio.h>
#include<stdlib.h> 
void main()
{
char Status[][10]={"EXCEL","GOOD","OK"};
int Turn=10, Trick;
for(int Count=l;Count<4;Count++)
{
Trick=random(Count); 
cout<<Turn-Trick<<Status[Trick]<<"#";
}
getch();
}
(i) 10EXCEL#10EXCEL#80K#
(ii) 10EXCEL#80K#9GOOD#
(iii) 10EXCEL#9GOOD#10EXCEL#
(iv) 10EXCEL#10GOOD#80K#

Аnswer:
(i) and (iii)
Minimum value 0 Maximum value = 2

Question 22:
Rewrite the following program after removing the syntactical errors (if any). Underline each correction. Delhi 2011

#include<iostream.h> 
typedef char Text(80); 
void main()
{
Text T="Indian";
int Count=strlen(T);
cout<<T<<'has'<<Count<<'characters'<<endl;
}

Аnswer:

#include<iostream.h>
#include<string.h>
typedef char Text[80];
void main()
{
Text T="Indian"; 
int Count=strlen(T);
cout<<T<<"has_"<<Count<<"characters"<<endk;
}

Question 23:
Go through the C++ code shown below and find out the possible output from the suggested output (i) to (iv). Also, write the least value and highest value, which can be assigned to the variable Guess. Delhi 2011

#includeCiostream.h>
#include<stdlib.h> 
void main()
{
randomize(); 
int Guess, High=4; 
Guess=random(High)+50; 
for(int C=Guess;C<=55;C++) 
cout<<C<<"#";
}
(i) 50#51#52#53#54#55# 
(ii) 53#53#54#55#
(iii) 53#54#    
(iv) 51#52#53#54#55

Аnswer:
Possible output is only (i) and (ii)
Least value of Guess = 50
Highest value of Guess = 53

Question 24:
The following code is from a game, which generates a set of 4 random numbers. Praful is playing this game, help him to identify the correct option (5) out of the four choices given below as the possible set of such numbers generated from the program code so that he wins the game. Justify your answer. All India 2010

#include<iostream.h>
#include<stdlib.h> 
const int L0W=25; 
void main()
{
randomize();
int POINT=5, Number;
for(int I=1;I<=4;I++)
{
Number=LOW+random(POINT); 
cout<<Number<<":";
POINT--;
}
}
(i) 29:26:25:28:
(ii) 24:28:25:26:
(iii) 29:26:24:28:
(iv) 29 :26:25:26:

Аnswer:

(iv) 29 ; 26 : 25 : 26:
because in
1st pass Number = 25 + random (5), i.e. 25 + 0 to 4 = 25 to 29
2nd pass Number = 25 + random(4), i.e 25 to 28
3rd pass Number = 25 + random(3), i.e. 25 to 27
4th pass Number = 25 + random(2), i.e 25 to 26

Question 25:
What is the difference between call by reference and call by value with respect to memory allocation? Give a suitable example to illustrate using C++ code. All India 2014
Аnswer:
Differences between call by value and call by reference are as follows:

Call by Value Call by Reference
In this method of passing arguments to the function while calling a function, actual values are passed and the called function creates a new copy of variables initialised with those passed values. In this method of passing arguments to the function, references of variables are passed as arguments to the called function and no new copy of the variables are created.
In the called function changes are made to that new copy of the variables while the original variable values remain unchanged. In the called function since no separate copy of variables is created hence, changes are done in the original copy itself.

Following illustrates the concept of call by value: #include<iostream.h>

#include<conio.h> 
void swap(int x,int y)
{
int temp = x; 
x = y; 
y = temp;
cout<<"After swapping\n"; 
cout<<"Inside swap"<<endl; 
cout<<"x: "<<x<<endl; 
cout<<"y: "<<y<<endl;
}
void main()
{
int x,y; 
clrscr();
cout<<"Enter two numbers\n"; 
cin>>x>>y; 
swap(x,y);
cout<<"After swapping\n"; 
cout<<"I nside main”<<endl; 
cout<<"x: "<<x<<endl; 
cout<<"y: "<<y; 
getch();
}
Following illustrates the concept of call by reference:
#include<iostream.h>
#include<conio.h> 
void swap(int *x,int *y)
int temp = *x;
*x = *y;
*y = temp;
cout<<"After swapping\n"; 
cout<<"Inside swap"<<endl;
cout<<"x: "<<*x<<endl; 
cout<<"y: "<<*y<<endl;
}
void main()
{
int x,y; 
clrscr();
cout<<"Enter two numbers\n"; 
cin>>x>>y; 
swap(&x,&y);
cout<<"After swapping\n"; 
cout<<"Inside main"<<endl; 
cout<<"x: "<<x<<endl; 
cout<<"y: "<<y; 
getch();
}

Question 26:

Study the folio wing program and select the possible output from it. Delhi 2009

#include<iostream.h>
#include<stdlib.h> 
const int LIMIT = 4; 
void main()
{
randomize(); 
int Points;
Points=100+random(LIMIT); 
for(int P=Points;P>=100;P--) 
cout<<P<<"#"; 
cout<<endl;
}
(i) 103#102#101#100#
(ii) 100#101#102#1103#
(iii) 100#101#l02#103#104#
(iv) 104#103#102#101#100#

Аnswer:
(i) 103#102#101#100#

Question 27:
Rewrite the following program after removing the syntactical error(s) (if any). Underline each correction. Delhi 2008

#include<iostream.h> 
void main()
{
First=10,Second=20;
Jumpto(First; Second);
Jumpto(Second);
}
void Jumpto(int N1,int N2=20)
{
N1 = N1+N2; 
cout<<N1>>N2;
}

Аnswer:

void Jumpto(int N1, int N2=20);
#include<iostream.h> 
void main() 
{
int First=10, Second=20;
Jumpto(First, Second);
Jumpto(Second);
}
void Jumpto(int N1, int N2)
{
N1 = N1+N2; 
cout<<N1<<N2;
}

Question 28:
What is the benefit of using default parameter/argument in a function? Give a suitable example to illustrate it using C++ code. All India 2013
Аnswer:
A default parameter is a function parameter that has a default value provided to it. If the user does not supply a value for this parameter, the default value will be used.
If the user does supply a value for the default parameter, the user-supplied value is used.
Consider the following program:

void PrintValues(int nValue1.int nValue2=10)
{
cout<<"1st value:"<<nValue1<<endl; 
cout<<"2nd value:"<<nValue2<<endl;
}
int main()
{
PrintValues(1); //nValue2 will use default parameter //of 10
PrintValues(3,4); //override default value for nValue2 return 0;
}
Output
1st value: 1 
2nd value: 10 
1st value: 3 
2nd value: 4

Question 29:
Find the output of the following program from the output(s) given: Delhi 2008

#include<stdlib.h>
#include<iostrearn.h> 
void main()
{
randomize();
char city[][10]={"DEL","CHN","KOL","BOM","BNG"};
int Fly;
for(int I=0;I<3;I++)
{
Fly=random(2)+1; 
cout<<city[Fly]<<":";
}
}
Output
(i) DEL: CHN: KOL:
(ii) CHN : KOL: CHN :
(iii) KOL : BOM : BNG :
(iv) KOL: CHN: KOL:

Аnswer:

(ii) CHN : KOL : CHN :
(iv) KOL : CHN : KOL :

Question 30:
Find the output of the following program: Delhi 2011

#include<iostrearn.h>
void ChangeArray(int Number,int ARR[],int Size)
{
for(int L=0;L<Size;L++) 
if(L<Number)
ARR[L] += L; 
else
ARR[L] *= L;
}
void Show(int ARR[],int size)
{
for(int L=0;L<size;L++)
(L%2 != 0)?cout<<ARR[L]<<"#":cout<<ARR[L]<<endl;
}
void main()
{
int Array[] = {30,20,40,10,60,50}; 
ChangeArray(3,Array,6);
Show(Array,6);
}

Аnswer:
The output will be:
30
21 #42
30#240
250#

Question 31:
Write definition for a function sumseries( ) in C++ with two arguments/parameters-double x and int n. The function should return a value of type double and it should perform sum of the following series:
X-X2/3! +X3 / 5!- X4 / 7! + X5 / 9!.. upto n terms.
Аnswer:

#include<iostream.h>
#include<conio.h>
double sumseries(double x, int n)
{
double series=0, pow, fact, term; 
int i,j,k;
for(i=1,k=1;i<=n;i++,k+=2) 
{
for(pow=1,j=1;j<=i;j++) 
pow*=x;
for(fact=1,j=1;j<=k;j++) 
fact*=j; 
term=pow/fact; 
if(i%2==0)
series -= term; 
else
series += term;
}
return series;
}

Question 32:
Write a C++ program to find sum of serieschapterwise-question-bank-cbse-class-12-computer-science-c-c-revision-tour-(31-1)
Аnswer:

#includeCiostream.h>
#include<conio.h>
#include<math.h> 
void main()
{
clrscr(); 
double sum=0,a; 
int n,i;
cout<<"1+1/2^2+1/3^3+.....+1/n^n";
cout<<"\nEnter value of n:"; 
cin>>n;
for(i=1;i<=n;++i)
{
a=1/pow(i,i); 
sum+=a;
}
cout<<"Sum="<<sum; 
getch();
}

Topic – 4
Structure

Exam Practice
Very Short Answer Type Questions [1 Mark]

Question 1:
What are nested structures? Give an example.
Аnswer:
A structure declared within another structure is called nested structure,
e.g.

struct Record
{
int rollno; 
struct student 
{
char fn[10]; 
char mn[10]; 
char ln[10];
};
char st_class; 
char section;
};

Question 2:
Declare a structure applicant to store the following data: Applicant name, Code number, Data of birth (day, month, year).
Аnswer:

struct dob 
{
int day; 
int month; 
int year;
};
struct applicant 
{
char name[30]; 
int code; 
dob date;
}

Short Answer Type Questions [2 Marks]

Question 3:
Find the output of the following program: Delhi 2011C

#include<iostream.h> 
struct Dress
{
int size,cost,Tax,Total_Cost;
};
void change(Dress &S,int Flag=l)
if(Flag == 1)
S.cost += 20;
S.Total_Cost=S.cost + S.cost*S.Tax/100;
}
void main()
{
Dress S1 = {40,580,8},S2 ={34, 550, 10}; 
change(S1);
cout<<S1.size<<','<<S1.cost<<','<<S2,Total_Cost<<endl;
change(S2,2);
cout<<S2.size<<','<<S2.cost<<','<<S2.Total_Cost<<endl;
}

Аnswer:
Output
40, 600, 0
34,550,605

Question 4:
Find the output of the following program:

#include<iostream.h> 
struct POINT
{
int x.y.z;
};
void Step In(POINT &P,int Step=1)
{
P.x += Step;
P.y -= Step;
P.z += Step;
}
void Step0ut(P0INT &P, int step=1)
{
P.x -= step;
P.y += step;
P.z -= step;
}
void main()
{
POINT P1 = {15, 25, 5}, P2 = {10, 30, 20};
StepIn(P1);
Stepout(P2,4);
cout<<P1.x<<','<<P1.y<<','<<P1.z<<endl;
cout<<P2.x<<','<< P2.y<<','<<P2.z<<endl;
Stepln(P2,12) ;
cout<<P2.x<<','<<P2.y<<','<<P2.z<<endl;
}

Аnswer:
Output
16, 24, 6 6, 34, 16 18, 22, 28

Question 5:
Rewrite the following program after removing the syntactical error(s), (if any). Underline each correction.

#include<iostream.h> 
void main()
{
struct movie 
{
char movie_name[20]; 
char movie_type; 
int ticket_cost=100;
}
MOVIE;
gets(movie_name); 
gets(movie_type);
}

Аnswer:

#include<iostream.h>
#include<stdio.h>    //Correction 1
void main()
{
struct movie 
{
char movie_name[20]; 
char movie_type;
int ticket_cost; //Correction 2 
}
MOVIE;
gets(MOVIE.movie_name); //Correction 3 
cin>>MOVIE.movie_type; //Correction 4 
}

Correction 1 stdio.h should be used for gets function.
Correction 2 Can’t assign here.
Correction 3 Object should be used with structure element.
Correction 4 cin >> is used for single character.

Question 6:
Find the output of the following program: All India 2010

#include<iostream.h> 
struct THREE_D 
{
int x,y,z;
};
void MoveIn(THREE_D &T, int Step=1)
{
T.x += Step;  
T.y -= Step;
T.z += Step; 
void MoveOut(THREE_D &T, int Step=l)
{
T.x -= Step;
T.y += Step;
T.z -= Step;
}
void main()
{
THREE_D T1=(10, 20, 5}, T2={30,10,40}; 
Moveln(T1) ;
Moveout(T2,5);
cout<<T1. x<<","<<T1,y<<","<<T1.z<<endl; 
cout<<T2.x<<","<<T2.y<<","<<T2.z<<endl; 
MoveIn(T2,10);
cout<<T2.x<<","<<T2.y<<",”<<T2.z<<endl;
}

Аnswer:
Output
11, 19, 6
25, 15, 35
35, 5, 45

Question 7:
Rewrite the corrected code for the following program. Underline each correction (if any).

#include<iostream.h> 
structure Supergym 
{
int membernumber; 
char membername[20]; 
char membertype[]="HIG”;
};
void main()
{
Supergym person1, person2; 
cin<<"Member Number:"; 
cin>>person1.membernumber; 
cout<<"Member Name:"; 
cin>>person1.membername; 
person1.membertype = "MIG"; 
person2=person1; 
cin<<"Member Number :"<<person2.membernumber; 
cin<<"Member Name :"<<person2.membername;
cin<<"Member Type :"<<person2.membertype;
}

Аnswer:

#include<iostream.h>
#include<string.h> 
struct Supergym 
{
int membernumber; 
char membername[20]; 
char membertype[4];
};
void main()
{
Supergym person1, person2; 
cout<<"Member Number :";
cin>>person1.membernumber; 
cout<<"Member Name :" 
cin>>person1.membername; 
strcpy(person1.membertype,"MIG"); 
person2 = person1; 
cout<<"Member Number :"<<person2.membernumber;
cout<<"Member Name :"<<person2.membername;
cout<<"Member Type :"<<person2.membertype;
}

Question 8:
Find the output of the following program:

#include<iostream.h> 
struct Package 
{
int Length, Breadth, Height;
};
void Occupies(Package M)
{
cout<<M.Length<<"X"<<M.Breadth<<"X"; 
cout<<M.Height<<endl;
}
void main()
{
Package P1={100,150,50}, P2, P3; 
++P1.Length;
Occupies(P1);
P3= P1;
++P3.Breadth;
P3.Breadth++;
Occupies(P3);
P2=P3;
P2.Breadth+=50;
P2.Height--;
Occupies(P2);
}

Аnswer:
Output
101X150X50
101X152X50
101X202X49

Question 9:
Rewrite the corrected code for the following program. Underline each correction (if any).

#include<iostream.h> 
structure Swimmingclub
{
int memnumber; 
char memname[20] 
char memtype[]="LIG”; 
}
void main()
{
Swimmingclub per1, per2; 
cout<<"Member Number:"; 
cin>>memnumber.per1; 
cout<<"Member Name:"; 
cin>>per1.membername; 
per1.memtype="HIG"; 
per2 = per1; 
cin<<"Member Number:"<<per2.memnumber;
cin<<"Member Name :"<<per2.memname; 
cin<<"Member Type :"<<per2.memtype;
}

Аnswer:

#include<iostream.h> 
#include<string.h> 
struct Swimmingclub 
{
int memnumber; 
char memname[20]; 
char memtype[4];
};
void main()
{
Swimmingclub per1, per2; 
cout<<"Member Number :";
cin>>per1.memnumber; 
cout<<"Member Name :";
cin>>per1.memname; 
strcpy(per1.memtype."HIG"); 
per2 = per1; 
cout<<"Member Number:"<<per2.memnumber; 
cout<<"Member Name:"<<per2.memname; 
cout<<"Member Type:"<<per2.memtype;
}

Question 10:
Find the output of the following program:

#include<iostream.h> 
struct MyBox 
{
int Length, Breadth, Height;
};
void Dimension(MyBox M) 
{
cout<<M.Length<<"x"<<M.Breadth<<"x"; 
cout<<M.Height<<endl;
}
void main()
{
MyBox B1={10,15,5}, B2, B3;
++B1.Height;
Dimension(B1);
B3=B1;
++B3.Length;
B3.Breadth++; 
Dimension(B3);
B2=B3;
B2.Height+=5;
B2.Length--;
Dimension(B2);
}

Аnswer:
Output
10X15X6
11X16X6
10X16X11

Question 11:
Find the output of the following program: Delhi 2009C

#include<iostrearn.h>
#include<conio.h> 
struct score 
{
int Year; 
float Topper;
};
void Change(score *s, int x=20)
{
s→Topper=(s→Topper+25)-x; 
s→Year++;
}
void main()
{
clrscr();
score Arr[] = {{2007,100},{2008,95}}; 
score *point=Arr;
Change(point,50);
cout<<Arr[0].Year<<'#'<<Arr[0].Topper<<endl;
Change(++point);
cout<<point→Year<<'#'<<point→Topper<<endl;
getch();
}

Аnswer:
Output
2008#75
2009# 100

Question 12:
Rewrite the following program after removing the syntactical error(s), if any. Underline each correction.

#include<iostream.h> 
void main()
{
struct STUDENT 
{
char stu_name[20]; 
char stu_sex; 
int stu_age = 17;
}
student; 
gets(stu_name); 
gets(stu_sex);
}

Аnswer:

#include<iostream.h>
#include<stdio.h> 
void main()
{
struct STUDENT
{
char stu_name[20]; 
char stu_sex; 
int stu_age;
}
student;
gets(student.stu_name);
cin>>(student.stu_sex);
}

Question 13:
Find the output of the following program:

#includeCiostream.h>
#1nclude<conio.h> 
struct land 
{
int length; 
int breadth; 
float area;
};
void calarea(and &P1, int y=10)
{
P1.area=P1.length*P1.breadth;
P1.area/=y;
P1.1ength++;
P1.breadth++;
}
void main()
{
land first={20,50},second={10,30}; 
calarea(first);
cout<<first.area<<'#'<<first.length<<'#'<<first.breadth;
cout<<endl;
calarea(second,5);
cout<<second.area<<'#'<<second.length<<'#'<<second.breadth;
getch();
}

Аnswer:
Output
100#21#51
60#11#31

Question 14:
What is the output of the following program?

#include<iostream.h>
#include<conio.h> 
void main()
{
struct point
{
int x,y;
}
polygon[]={{1,2},{1,4},{2,41.{2,2}};
point *a;
a=polygon;
a++;
a→x++;
cout<<polygon→x<<endl; 
getch();
}

Аnswer:
Output
1

Computer ScienceChapterwise Question Bank for Computer ScienceNCERT Solutions

Primary Sidebar

NCERT Exemplar problems With Solutions CBSE Previous Year Questions with Solutoins CBSE Sample Papers

Recent Posts

  • CBSE Revision Notes for Class 10 English Footprints Without Feet Chapter 6 The Making of a Scientist
  • NCERT Class 10 Maths Lab Manual – Probability
  • Paragraph, Notice, Message Writing Class 6 CBSE Questions And Answers – Short Compositions
  • Paragraph on Friendship in Hindi | मित्रता पर अनुच्छेद लेखन
  • NCERT Solutions for Class 12 Hindi Core – गद्य भाग-काले मेघा पानी दे
  • NCERT Solutions for Class 12 Chemistry Chapter 8 d-and f-Block Elements
  • Paragraph on Karat Karat Abhyas Jadmati Hot Sujan In Hindi | करत करत अभ्यास के जड़मति होत सुजान पर अनुच्छेद लेखन
  • NCERT Solutions for Class 12 English Flamingo Poem 1 My Mother at Sixty-six
  • NCERT Class 9 Science Lab Manual – Melting Point of Ice and Boiling Point of Water
  • NCERT Class 10 Maths Lab Manual – Area of Circle by Paper Cutting and Pasting Method
  • Paragraph on Sangharsh Hi Jeevan Hai in Hindi | संघर्ष ही जीवन है पर अनुच्छेद लेखन
  • Mijbil the Otter Extra Questions and Answers Class 10 English First Flight
  • NCERT Solutions for Class 8 English Honeydew Chapter 9 The Great Stone Face 1
  • NCERT Solutions for Class 12 English Flamingo Poem 6 Aunt Jennifer’s Tigers
  • Selina Concise Mathematics Class 8 ICSE Solutions Chapter 17 Special Types of Quadrilaterals

Footer

Maths NCERT Solutions

NCERT Solutions for Class 12 Maths
NCERT Solutions for Class 11 Maths
NCERT Solutions for Class 10 Maths
NCERT Solutions for Class 9 Maths
NCERT Solutions for Class 8 Maths
NCERT Solutions for Class 7 Maths
NCERT Solutions for Class 6 Maths

SCIENCE NCERT SOLUTIONS

NCERT Solutions for Class 12 Physics
NCERT Solutions for Class 12 Chemistry
NCERT Solutions for Class 11 Physics
NCERT Solutions for Class 11 Chemistry
NCERT Solutions for Class 10 Science
NCERT Solutions for Class 9 Science
NCERT Solutions for Class 7 Science
MCQ Questions NCERT Solutions
CBSE Sample Papers
NCERT Exemplar Solutions LCM and GCF Calculator
TS Grewal Accountancy Class 12 Solutions
TS Grewal Accountancy Class 11 Solutions