Chapterwise Question&answer
Chapterwise Question&answer
Chapterwise Question&answer
else
1. C++ REVISION TOUR Txt[Count++]=’#’ ;
MODEL WISE QUESTION & ANSWERS puts (Txt) ;
Note: This material is prepared for thorough practice }
of important models from old questions and thereby A) ctype.h, stdio.h (2015 OD)
getting good marks and student is advised to prepared 4) Observe the following C++ code and write the name(s)
all the syllabus given by CBSE. of the header file(s), which will be essentially required to
run it in a C++ compiler: 1
MODEL1: Valid/Invalid Identifiers. 2 Marks
void main( )
1. Out of the following, find those identifiers, which can not { char CH,STR[20];
be used for naming Variable, Constants or Functions in a cin>>STR;
C++ program: (2016 OD) 2 CH=toupper(STR[0]);
Total*Tax, double, Case, My Name, cout<<STR<<”start with”<<CH<<endl;
NeW, switch, Column31, _Amount }
A) Total*Tax,double,My Name,switch A) iostream.h and ctype.h (2014 OD)
2. Find the correct identifiers out of the following, which 5) Observe the following C++ code and write the name(s)
can be used for naming Variable, Constants or Functions in of the header file(s), which will be essentially required to
a C++ program: (2015 OD) 2 run it in a C++ compiler: 1
For, while, INT, NeW, delete, 1stName, Add+Subtract, name1 void main( )
A) For, INT, NeW, name1 { int Number;
MODEL 2a) Which C++ header file(s) are cin>>Number;
essentially required to be included to if (abs(Number)= = Number);
run/execute the following C++ code: 1 Mark cout<<”Positive”<<endl;
}
1.b) Which C++ header file(s) are essentially required to be
A) iostream.h, math.h (2013 D)
included to run/execute the following C++ code : 1
void main() 6) 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
char *word1="Hello",*word2="Friends"; required): 1
strcat(word1,word2); cout<<word1; void main( )
{ char TEXT[ ]=”SomeThing”;
}
cout<<”Remaining SMS Chars:”<<
A) iostream.h string.h (2017MP)
160-strlen(TEXT)<<endl;
2) 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 Ans: iostream.h (for cout)
some header files to successfully compile and execute it. string.h (for strlen( )); (2012)
Write the names of those header files, which are required to (7)Write the names of the header files, which is/are
be included in the code. 1 essentially required to run/execute the 1ollowing++code:1
void main ( )
void main()
{ char C, String [ ] = “Excellence Overload”;
{
double X,Times,Result; for (int I=0; String [ I ] ! = ‘\ 0’; I ++ )
cin>>X>>Times; if (String [I] ==’ ‘)
Result=pow(X,Times); cout<<end1;
cout<<Result<<endl; else
} { C=toupper(String[I]);
A) ● iostream.h OR iomanip.h cout<<C ;
● math.h (2016 OD) }
}
3) Observe the following program very carefully and write
Ans: iostream.h ctype.h (2011 D)
the name of those header file (s), which are essentially
needed to compile and execute the following program (8) Write the names of the header files, which is/are
successfully: essentially required to run/execute the following c++ code:
typedef char STRING[80]; void main ( )
void main() { char CH,Text[ ] =”+ve Attitude”;
{ for (int I=0 ; Text[I] ! =’\0’ ;I++)
STRING Txt[] = “We love Peace”; if (Text[I]== ‘ ‘)
int Count=0; cout<<end1;
while (Txt[Count]!=’\0’) else
if (isalpha(Txt[Count])) { CH=toupper (Text [I]) ;
cout<<CH;
XII Computer Chap1 to 3 1
} for(int C=9;C<=Last;C++)
} cout<<C<<”:”<<sqrtI<<endl;
Ans: iostream.h, ctype.h (2011 OD) }
Ans:
(9) Which C++ header file(s) will be essentially required to (i)iostream.h (for cout)
be included to run/ execute the following C++ code? 1 void (ii) math.h (for sqrt( ))
main( ) MODEL 2b): Write the names of the header
{
int Eno=123, char Ename[ ]=”Rehan Swamp”; files to which the following belongs to : 1 Mark
cout<<setw(5)<<Eno<<setw(25)<<Ename<<endl; 1) Write the names of the header files to which the
} Ans. (i) iostream.h (ii) iomanip.h (2010 D) following belong: 1
(10) Which C++ header file(s) will be essentially required (i) puts ( ) (ii) sin ( )
to be included to run/execute the following C++ code: 1 Ans (i) stdio.h (ii) math. h (2009 D)
void main() 2) Write the names of the header files to which the
{ following belong: 1
int Rno=24; char Name [] =” Amen Singhania”; (i) setw( ) (ii) sqrt( )
cout<<setw(lO)<<Rno<<setw(20)<<Name<<endl; Ans (i) iomanip.h (ii) math.h (2009 OD)
} Ans. iostream.h, iomanip.h (2010 OD) 3 Name the header file to which the following below:
11)Name the header files that shall be needed for the (i) abs( ) (ii) isupper( ) 1
following code: 1 Ans) (i) abs( ) - math.h, stdlib.h, complex.h
void main( ) (ii)isupper( ) - ctype.h (2006 D)
{ char String[ ] = “Peace”; 4) Name the header file to which the following belong:
cout << setw(2)<<String; (i) pow ( ) (ii)random( ) 1
} Ans) iomanip.h, iostream.h (2008 D) Ans:
12) Name the header files that shall be needed for the (i) abs( ) - math.h, stdlib.h, complex.h
following code: 1 (ii)random( ) - stdlib.h (2006 OD)
void main( ) 5) Name the header files to which the following belong: (i)
{ char word[]=”Exam”; abs( ) (ii) strcmp( ) 1
cout<<setw(20)<<word; Ans) (i) abs( ) - stdlib.h, math.h, complex.h
} (ii) strcmp( ) - string.h (2005 D)
Ans: iostream.h, iomanip.h (2008 OD) 6) Name the header files to which the following belong: (i)
13) Name the header file(s) that shall be needed for puts( ) (ii)isalnum( ) 1
successful compilation of the following C++ code. 1 Ans)(i) puts( ) - stdio.h
void main( ) (ii)isalnum( ) - ctype.h (2005 OD)
{ char String[20]; 7) Write the names of the header files to which
gets(String); the following belong:
strcat(String,”CBSE”); (i) gets( ) (ii) strcmp( ) (iii)abs( ) (iv)isalnum( )
puts(String); Ans: (i)gets( ) - stdio.h
} (ii)strcmp( ) - string.h
Ans) stdio.h string.h (2007 D) (iii)abs( ) - math.h, stdlib.h,complex.h
14) Name the header file(s) that shall be needed for (iv)isalnum( ) - ctype.h (2004)
successful compilation of the following C++ code. 1 void 8) Name the header file, to which the following built-
main( ) in function belongs:
{ char Text[40]; (i) strcmp( ) (ii)getc( ) 1
strcpy(Text,”AISSCE”); Ans: (i) strcmp( ) - string.h
puts(Text); (ii) getc( ) - stdio.h (2003)
} 9)Name the header files of C++ to which the following
Ans:string.h, stdio.h (2007 OD) functions belong: 2
15) Which C++ header file(s) will be essentially required to (i)get( ) (ii)open( )
be included to run /execute the following C++ code:1 (iii)abs( ) (iv)strcat( )
void main() (2009-10 MP1) Ans: (i)get( ) - iostream.h
{char Msg[ ]=”Sunset Gardens”; for (ii)open( ) - fstream.h
(int I=5;I<strlen(Msg);I++) (iii)abs( ) - math.h, stdlib.h
puts(Msg); (iv)strcat( ) - string.h (2002)
} 10) Name the header file to be included for the use of
A) (i) string.h (ii) stdio.h the following built in functions:
16) Which C++ header file(s) will be essentially required to (i)getc( ) (ii)strcat() 1
be included to run/ execute the following C++ code: 1 Ans: (i) getc( ) - stdio.h
void main( ) (2011-12 MP1) (ii)strcat( ) - string.h (2001)
{ int Last=25;
XII Computer Chap1 to 3 2
11) Name the header file, to which following built in float Z=Formula(X,Y);
function belong: 2 cout<< ”Result=” <<Z<<endl;
(i) isupper( ) ( ii)setw() }
(iii)exp( ) (iv)strcmp( ) (2000) 2) Observe the following C++ code very carefully and
Ans) (i) isupper( ) - ctype.h (ii)setw( )- iomanip.h rewrite it after removing any/all syntactical errors with each
(iii)exp( ) - math.h (iv)strcmp( ) - string.h correction underlined. 2
12) Name the header file of C++ to which following Note: Assume all required header files are already being
functions belong. (i)strcat( ) included in the program. (2015)
(ii) scanf( ) (iii) getchar( ) (iv)clrscr( ) #Define float MaxSpeed=60.5;
Ans: (i)strcat( ) - string.h void main()
(ii)scanf( ) - stdio.h {
(iii)getchar( ) - stdio.h int MySpeed
(iv)clrscr( ) - conio.h (1999) char Alert=’N’ ;
13)Name the header files, to which the following built in cin»MySpeed;
functions belongs to: if MySpeed>MaxSpeed
(i)cos( ) (ii)setw( ) (iii)toupper( ) (iv)strcpy( ) Alert=’Y’ ;
Ans: (i) cos( ) - math.h cout<<Alert<<endline;
(ii) setw( ) - iomanip.h }
(iii) toupper( ) - ctype.h A)
(iv) strcpy( ) - string.h (1998) #define float MaxSpeed 60.5 ; //Error 1,2,3
14)Write the names of the header files to which the void main()
following belong: (2008-09 MP1) 1 {
(i) strcmp() (ii) fabs() int MySpeed ; //Error 4
Answer: (i)string.h (ii) math.h char Alert=’N’;
15)Write the names of the header files to which the cin>>MySpeed;
following belong: (2008-09 MP2) 1 if (MySpeed>MaxSpeed) //Error 5
(i) frexp() (ii) isalnum() Alert=’Y’;
Answer: cout<<Alert<< endl; //Error 6
(i) math.h (ii) ctype.h }
16) Write the names of the header files to which the 3) Rewrite the following C++ code after removing all the
following belong: (2009-10 MP2) 1 syntax error(s), if present in the code. Make sure t hat you
(i) frexp() (ii) isalnum() underline each correction done by you in the code. 2
A) (i) math.h (ii) ctype.h Important Note: (2014)
-Assume that all the required header files are already
included, which are essential to run this code.
-The correctons made by you do not change the logic of
MODEL 3a): Observe the following C++ code the program.
very carefully and rewrite it after removing Typedef char[80] STR;
any/all syntactical errors with each correction void main( )
underlined. Note: Assume all required header {
files are already being included in the program. Txt STR;
gets(Txt);
2 Marks cout<<Txt[0]<<’\t’<<Txt[2];
cout<<Txt<<endline;
1) Rewrite the following C++ code after removing any/all }
syntactical errors with each correction underlined. A)
Note: Assume all required header files are already being Typedef char[80] STR;
included in the program. (2016) 2 void main( )
#define Formula(a,b) = 2*a+b {
void main() STR Txt;
{ gets(Txt);
float X=3.2;Y=4.1; cout<<Txt[0]<<”\t”<<Txt[2];
Z=Formula(X,Y);
cout<<Txt<<endl;
cout<<’Result=’<<Z<<endl;
}
}
4) Observe the following C++ code carefully and rewrite
A)
the same after removing all the syntax error(s) present in
#define Formula(a,b) 2*a+b the code. Ensure that you underline each correction in the
void main() code. 2
{
Important Note: (2013)
float X=3.2 , Y=4.1;
-All the desired header files are already included,
XII Computer Chap1 to 3 3
which are required to run the code. 7) Rewrite the following program after removing the
-Correction should not change the logic of the program syntactical error(s) if any.Underline each correction.2
#define Convert (P,Q) P+2*Q; void main( ) #include<iostream.h>
const int Max 10;
{ void main()
Float A,B, Result; { int Numbers[Max]; Numbers =
cin>>A>>B; {20,50,10,30,40};
Result=Convert [A,B]; for(Loc=Max-1;Loc>=10;Loc--)
cout<<”Output:”<<Result<<endline; cout>>Numbers[Loc];
} }
A) Ans) (2007 D)
#define Convert(P,Q) P+2*Q #include<iostream.h>
//No semicolon, and space between Covert and (P,Q) const int Max=10;//Constant Variable ‘Max’ must be
void main( ) // initialized.Declaration Syntax Error
{ void main( )
float A, B, Result; //keywords should be in small case { int Numbers[Max]={20,50,10,30,40};
cin>>A>>B; for(Loc=Max-1;Loc>=0;Loc--)
Result=Convert(A,B); //(A,B) instead of [A,B] cout>>Numbers[Loc];
cout<<”Output:”<<Result<<end; }
//end instead of endline; 8) Rewrite the following program after removing the
} syntactical error(s), if any. Underline each correction.
5) Rewrite the following program after removing the 2 #include<iostream.h>
syntactical errors (if any).Underlineeachcorrection. 2 const int Size
#include[iostream.h] (2011 D) 5; void main( )
typedef char Text(80) ; { int Array[Size];
void main ( ) Array={50,40,30,20,10};
{ for(Ctr=0;Ctr<Size;Ctr++)
Text T= “Indian”; cout>>Array[Ctr];
int Count=strlen(T) ; }
cout<<T<<’has’<<Count<<’characters’<<end1; Ans) (2007 OD)
} #include<iostream.h>
Ans: const int Size=5;
#include<iostream.h> void main( )
#include<string.h> { int Array[Size];
typedef char Text [80]; Array={50,40,30,20,10};
void main ( ) for(Ctr=0;Ctr<Size;Ctr++)
{ cout<<Array[Ctr];
Text T= “Indian”; }
int Count=str1en(T); 9) Rewrite the following program after removing the
cout<<T<< “has” <<Count<< “cbaracters”<<end1; syntactical error(s), if any.Underline each correction. 2
} #include<iostream.h>
6) Rewrite the following program after removing the void main( ) (2006 D)
syntactical errors (if any).Underline each correction. 2 { struct STUDENT
include<iostream.h> {
typedef char [80] String; char stu_name[20];
void main ( ) char stu_sex;
{ String S= “Peace”; int stu_age=17;
int L=strlen(S) ; }student;
cout<<S<< ‘has’<<L<< ‘characters’<<end1; gets(stu_name);
} gets(stu_sex);
Ans: (2011 OD) }
#include<string.h> Ans:
#include<iostream.h> #include<iostream.h>
typedef char String [80]; #include<stdio.h>
void main ( ) void main( )
{ { struct STUDENT
String S = “Peace”; { char stu_name[20];
int L= strlen(S) ; char stu_sex;
cout<<S<< “has” << L << int stu_age;
“characters”<<end1; } //Initialization of variables inside a structure is not allowed.
XII Computer Chap1 to 3 4
}student; void main( )
gets(student.stu_name); { Number = 15;
cin>>student.stu_sex); for(int Count=1;Count=<5;Count++,Number -= 3)
//A single character cannot be read using gets if(Number % dividor = = 0)
} cout<<Number / Dividor;
10) Rewrite the following program after removing the cout<<endl;
syntactical error(s), if any.Underline each correction.2 else
#include<iostream.h> cout<<Number + Dividor <<endl;
void main( ) (2006 OD) Ans:
{ struct movie #include<iostream.h>
{char movie_name[20]; const int dividor= 5;
char movie_type; void main( )
int ticket_cost=100; { int Number = 15;
}MOVIE; for(int Count=1;Count<=5;Count++,Number -=
gets(movie_name); 3) if(Number % dividor = = 0)
gets(movie_type); { cout<<Number / Dividor;
} cout<<endl;
Ans: }
#include<iostream.h> else
#include<stdio.h> cout<<Number + Dividor <<endl;
void main( ) }
{ struct movie 13) Rewrite the corrected code for the following program.
{char movie_name[20]; char Underline each correction if any. (2004)
movie_type; #include<iostream.h>
int ticket_cost; structure Supergym
//Initialization of variables inside a structure is not allowed.
{ int member number;
}MOVIE; char membername[20];
gets(MOVIE.movie_name); char membertype[]=”HIG”;
cin>>MOVIE.movie_type;
//A single character cannot be read using gets
};
} void main( )
{ Supergym person1,person2;
11) Rewrite the following program after removing the cin>>”Member Number: “;
syntactical error(s), if any.Underline each correction.2
cin>>person1.membhernumber;
#include<iostream.h> cout<<”Member Name: “;
const int Multiple 3; (2005 D) cin>>person1.membername;
void main( )
person1.member type = “MIG”;
{ value = 15; person2=person1;
for(int Counter = 1;Counter = <5;Counter ++, Value -= 2)
cin>>”Member Number;“
if(Value%Multiple = = 0)
<<person2.membernumber;
cout<<Value * Multiple;
cin<<”Member Name”
cout<<end1;
<<person2.membername;
else
cin<<”Member Number:”
cout<<Value + Multiple <<endl;
<<person2.membertype;
}
}
Answer:
Ans:
#include<iostream.h>
#include<iostream.h>
const int Multiple=3;
#include<string.h>
void main( )
struct Supergym
{ int Value = 15;
for(int Counter = 1;Counter <=5;Counter ++, Value -= 2)
{ int membernumber;
if(Value%Multiple == 0) char membername[20];
{ cout<<Value * Multiple; char membertype[4];
cout<<endl; };
} void main( )
else { Supergym person1,person2;
cout<<Value + Multiple <<endl; cin>>”Member Number: “;
} cin>>person1.membernumber;
12) Rewrite the following program after removing the cout<<”Member Name: “;
syntactical error(s), if any.Underline each correction.2 cin>>person1.membername;
#include<iostream.h> strcpy(person1.membertype,”MIG”);
const int dividor 5; (2005 OD) person2=person1;
XII Computer Chap1 to 3 5
cin>>”Member Number;” cout<<s1<<s2;
>>person2.membernumber; }
cin>>”Member Name” Ans: The program will not execute successfully.
>>person2.membername; Because some syntax errors are there in the program.
cin>>”Member Number:” They are (i)cin and cout, stream objects used but
>>person2.membertype; iostream.h header file is not included in the program.
} (ii)x is not declared, it should be declared as int.
14) Rewrite the following program after removing all the (iii)With cin, we should use >> instead of <<.
syntax error(s) if any. 2 (iv)The shorthand operator /=, is given wrongly as =/.
#include<iostream.h> (2003) So the corrected program is as follows:
void main( ) #include<iostream.h>
{ int P[ ]={90,10,24,15};Q,Number=4; void main( )
Q=9; {int s1,s2,num;
for[int I=Number-1;I>=0,I--] s1=s2=0;
switch(I) for(int x=0;x<11;x++)
{ case 0; { cin>>num;
case 3:cout>>P[I]*Q<<endl;break; if(num>0)s1+=num;else s2/=num;
case 1: }
case 2: cout<<P[I]+Q; cout<<s1<<s2;
} } }
Ans:
#include<iostream.h> 16) Find the syntax error(s), if any, in the following
void main( ) program: (1999) #include<iostream.h>
{ int P[ ]={90,10,24,15},Q,Number=4;
Q=9; main( )
for(int I=Number-1;I>=0;I--) { int x[5],*y,z[5];
switch(I) for(i=0;i<5;i++)
{ case 0: { x[i]=I;
case 3:cout<<P[I]*Q<<endl; break; z[i]=i+3;
case 1: y=z;
case 2: cout<<P[I]+Q; x=y;
} }
} }
14)Find the syntax error(s), if any, in the following Ans (i) Line No 5: Undefined symbol ‘i’.
program. (2002) 2 The variable ‘i’ is not declared in the program.
#include<iostream.h> (ii)Line No 10:Assign the value of a pointer to an
void main( ) integer variable. Ie error in x=y.
{ int x; 17)Find the syntax error(s), if any, in the following
cin>>x; program: (1998)
for( int y=0,y<10,y++) include<iostream.h>
cout<<x+y; void main( )
} { int R; W=90;
Ans: while W>60
#include<iostream.h> { R=W-50;
void main( ) switch(W)
{ int x; { 20:cout<<”Lower Range”<<endl;
cin>>x; 30:cout<<”Middle Range “<<endl;
for( int y=0;y<10;y++) 40:cout<<”Higher Range”<<endl;
cout<<x+y; }
} }
15)Will the following program execute successfully?If not, }
state the reason(s) (2000) 2 Ans:
#include<stdio.h> (i) Line 1: It should be, #include<iostream.h>
void main( ) (ii) Line 4:Variables should be separated using
{int s1,s2,num; commas.
s1=s2=0; It should be int R,W=90;
for(x=0;x<11;x++) (iii) Line 5:Test expression should be in braces.
{ cin<<num; It should be while (W>60)
if(num>0)s1+=num;else s2=/num; (iv) Line 10:It should be case 20;
} (v) Line 11:It should be case 30;
XII Computer Chap1 to 3 6
(vi) Line 13:It should be case 40; #include<iostream.h>
So the corrected version of the program is as follows: void Jumpto(int N1,int N2=20); //Prototype missing
#include<iostream.h> void main( )
void main( ) { int First = 10, Second = 20; //Data type missing
{ int R, W=90; Jumpto(First,Second); //Comma to come instead of ;
while (W>60) Jumpto(Second);
{R=W-50; }
switch(W) void Jumpto(int N1, int N2)
{ case 20:cout<<”Lower Range”<<endl; { N1=N1+N2;
case 30:cout<<”Middle Range “<<endl; cout<<N1<<N2; //Output operator << required
case 40:cout<<”Higher Range”<<endl; }
} 20) Rewrite the following program after removing the
} syntax error(s) if any.Underline each correction. 2
} #include<iostream.h> (2008 OD)
18) Rewrite the following program after removing the void main( )
syntactical errors (if any). Underline each correction.2 { One=10,Two=20;
#include <iostream.h> Callme(One;Two);
struct Pixels Callme(Two);
{ int Color,Style;} void }
ShowPoint(Pixels P) void Callme(int Arg1,int Arg2)
{ cout<<P.Color,P.Style<<endl;} { Arg1=Arg1+Arg2;
void main() Count<<Arg1>>Arg2;
{ }
Pixels Point1=(5,3); Ans:
ShowPoint(Point1); void Callme(int Arg1,int
Pixels Point2=Point1; Arg2=20); #include<iostream.h>
Color.Point1+=2; void main( )
ShowPoint(Point2); { int One=10,Two=20;
} Callme(One,Two); //Given ; instead of ,
Ans: (MP2 2009-10) Callme(Two);
#include <iostream.h> 2 }
struct Pixels void Callme(int Arg1,int Arg2)
{ {
int Color,Style; Arg1=Arg1+Arg2;
}; cout<<Arg1<<Arg2;
void ShowPoint(Pixels P) }
{
cout<<P.Color<<P.Style<<endl;
} MODEL 3b): Rewrite the following program
void main() after removing the syntactical errors (if any).
{ Underline each correction (Using Class) -2
Pixels Point1={5,3}; Marks
ShowPoint(Point1); 1) Rewrite the following program after removing the
Pixels Point2=Point1; syntactical errors (if any). Underline each correction.2
Point1.Color+=2; #include<conio.h> (2017 MP)
ShowPoint(Point2); #include<iostream.h>
} #include<string.h>
19)Rewrite the following program after removing the #include<stdio.h>
syntactical error(s) if any.Underline each correction. 2 class product
#include<iostream.h> (2008 D) {
void main( ) int product_code,qty,price;
{First = 10, Second = 20; char name[20];
Jumpto(First;Second); public:
Jumpto(Second); product(){
} product_code=0;qty=0;price=0;
void Jumpto(int N1, int N2 = 20) name=NULL;
{ N1=N1+N2; }
count<<N1>>N2; void entry()
} {
Ans) cout<<"\n Enter code,qty,price";
XII Computer Chap1 to 3 7
cin>>product_code>>qty>>price; }
gets(name); Ans.
} #include<iostream.h>
void tot_price() {return qty*price;} #include<stdio.h>
}; class TRAIN
void main() {
{ long TrainNo;
p product; char Description [25];
p.entry(); public:
cout<<tot_price(); void Entry ()
} {
A) cin>>TrainNo; gets (Description);
#include<conio.h> }
#include<iostream.h> void Display ()
#include<string.h> {
#include<stdio.h> cout<<TrainNo<<“:”<<Description<<end1;
class product }
{ };
int product_code,qty,price; void main ()
char name[20]; {TRAIN T;
public: T.Entry();
product(){ T.Display();
product_code=0;qty=0;price=0; }
strcpy(name,NULL); 3) Rewrite the following C++ program code after removing
} the syntax error(s) (if any). Underline each correction. 2
void entry() include <iostream.h> (2010 OD)
{
cout<<"\n Enter code,qty,price"; class FLIGHT
cin>>product_code>>qty>>price; {
gets(name); long FlightCode;
} char Description[25];
int tot_price() {return qty*price;} public
}; void AddInfo ( )
void main() {
{ cin>>FlightCode; gets (Description) ;
product p; p.entry(); {
void ShowInfo ()
cout<<p.tot_price(); (
} cout<<FlightCode<<“:”<<Description<<endl;
2) Rewrite the following c++ program code after removing }
the syntax error(s) (if any). Underline each correction. 2 };
include <iostream.h> (2010 D) void main()
class TRAIN {
{ FLIGHT F;
long TrainNo; AddInfo.F(); ShowInfo.F();
char Description[25]; }
public Ans.
void Entry ( ) #include <iostream.h> / / Error 1
{ #include <stdio.h> / / Error 2
cin >>TrainNo; gets(Description); class FLIGHT
} {
Void Display ( ) long FlightCode;
{ //not required if gets( ) is re-placed with
cout<<TrainNo<<“:”<<Description<<endl; //cin.getline( ) or cin char
} Description[25];
}; public : / / Error 3
void main( ) void AddInfo ( )
{ { cin>>FlightCode; gets (Description) ;
TRAIN T; }
Entry. T( ); Display. T( ); void ShowInfo ( )
XII Computer Chap1 to 3 8
{ cout<<FlightCode<<”:”<<Description<<endl; PUBLIC:
} void Raise(){cin>>Charge;}
}; void Show{cout<<Charge;}
void main ( ) };
{ void main()
FLIGHT F; {
F.AddInfo( ) ; PAYITNOW P;
F. ShowInfo ( ) ; / / Error 4 P.Raise();
} Show();
4) Rewrite the following program after removing the }
syntactical errors (if any). (2009 OD) Answer:
Underline each correction. 2 #include <iostream.h>
include <iostream.h> class PAYITNOW
include <stdio.h> { int Charge;
class MyStudent public:
{ void Raise(){cin>>Charge;}
int StudentId = 1001; void Show(){cout<<Charge;}
char Name [20] ; };
public void main()
MyStudent( ){ } { PAYITNOW P;
void Register ( ) {cin>>StudentId; gets (Name) ;} P.Raise();
void Display ( ) {cout<<StudentId<< “:” <<Name<<end1;} P.Show();
}; }
void main ( ) 6 ) Rewrite the following program after removing the
{ syntactical errors (if any). (2009-10 MP1)
MyStudent MS ; Underline each correction. 2
Register.MS( ) ; #include [iostream.h]
MS.Display( ) ; class MEMBER
} {
Ans int Mno;float Fees;
# include <iostream.h> PUBLIC:
# include <stdio.h> void Register(){cin>>Mno>>Fees;}
class MyStudent void Display{cout<<Mno<<" : "<<Fees<<endl;}
{ int StudentId; };
char Name[20]; void main()
public : {
MyStudent( ) MEMBER M;
{ Register();
StudentId = 1001; M.Display();
} }
void Register( ) A)
{ #include <iostream.h>
cin>>StudentId; class MEMBER
gets (Name); { int Mno;float Fees;
} public:
void Display () void Register()
{ { cin>>Mno>>Fees;
cout«StudentId<<”:“<<Name<<endl; }
} void Display()
}; { cout<<Mno<<":"<<Fees<<endl;
void main () }
{ MyStudent MS; };
MS. Register (); void main()
MS. Display () ; { MEMBER M;
} M.Register();
5)Rewrite the following program after removing the M.Display();
syntactical errors (if any). Underline each correction. 2 }
#include [iostream.h] (2008-09 MP1) 7) Rewrite the following program after removing the
class PAYITNOW syntactical errors (if any). (2009 D)
{ int Charge; Underline each correction. 2
XII Computer Chap1 to 3 9
#include [iostream.h] void main ( )
#include [stdio.h] {
class Employee Item I ;
{ Purchase ( ) ;
int EmpId=901; I.Sale ( ) ;
char EName [20] ; I.Sale ( )
public }
Employee(){} Ans
void Joining() {cin>>EmpId; gets (EName);} #include<iosteam.h>
void List () {cout<<EmpId<<” : class Item // C Capital
“<<EName<<endl;} }; {
void main () long IId,Qty;
{ public:
Employee E; void Purchase ( ){cin>>IId>>Qty;}
Joining.E(); void Sale ( )
E.List() {
} cout<<setw(5)<<IId<<" Old: "<<Qty<<endl;
Ans //Either the statement setw(5) is removed
#include <iostream.h> //or header file included as #include<iomanip.h>
#include <stdio.h> cout<<"New:"<<--Qty<<endl;
class Employee }
{int EmpId; };
char EName[20]; void main ( )
public : {
Employee() Item I;
{ I.Purchase( );// Object missing
EmpId=901; I. Sale ( ) ;
} I. Sale ( ) ; // ; is missing
void Joining( ) }
{
cin>>EmpId;
MODEL 4a): Write the output of the following
gets (EName);
}
C++ program code (2 Marks).
void List ( ) Note: Assume all required header files are already
{ being included in the program (using pointers)
cout<<EmpId<<”: “<<EName<<endl; 1) Write the output of the following C++ program code:
} Note: Assume all required header files are already being
}; included in the program. 2
void main () void change(int *s) (2017 MP)
{ {
Employee E; for(int i=0;i<4;i++)
E.Joining (); {
E.List (); if(*s<40)
} {
if(*s%2==0)
8) Rewrite the following program after removing the *s=*s+10;
syntactical errors (if any). (2012 OD) else
Underline each correction. 2 *s=*s+11;
#include <iostream.h> }
Class 1tem else
{ {
long IId, Qty; if(*s%2==0)
public : *s=*s-10;
void Purchase{cin>>IId>>Qty;} else
void Sale ( ) *s=*s-11;
{ }
cout«setw(5)<<IId<<"Old:"<<Qty<<endl; cout<<*s<<" ";
cout<<''New: "<<Qty«end1; s++;
} }
}; }
XII Computer Chap1 to 3 10
void main() }
{ Answer:
int score[]={25,60,35,53}; TiLeP550
change(score); AiLJP430
}
A) MODEL 4b): Output(Using Class Concept)–3M
36 50 46 42
2) Obtain the output of the following C++ program as
expected to appear on the screen after its execution. 2 1.Write the output of the following C++ program code:
Important Note: (2014 OD) Note: Assume all required header files are already being
- All the desired header files are already included in the included in the program. 3
code, which are required to run the code. class seminar (2017 MP)
void main( ) {
{ char topic[30];
char *Text=”AJANTA”; int charges;
int *P,Num[ ]={1,5,7,9}; public:
P=Num; seminar()
cout<<*P<<Text<<endl; {
Text++; strcpy(topic,"Registration");
P++; charges=5000;
cout<<*P<<Text<<endl; }
} seminar(char t[])
A) {
1AJANTA strcpy(topic,t);
5JANTA charges=5000;
3) Observe the following C++ code carefully and obtain the }
output, which will appear on the screen after execution of it. seminar(int c)
Important Note: (2013 D) 2marks {
-All the desired header files are already included in the strcpy(topic,"Registration with Discount");
code, which are required to run the code. void main( ) charges=5000-c;
}
{ void regis(char t[],int c)
char *String=”SHAKTI”; {
int *Point,Value[ ]={10,15,70,19}; strcpy(topic,t);
Point=Value; charges=charges+c;
cout<<*Point<<String<<endl; }
String++; void regis(int c=2000)
Point++; {
cout<<*Point<<String<<endl; charges=charges+c;
} }
A) void subject(char t[],int c)
10SHAKTI {
15HAKTI strcpy(topic,t);
4)Find the output of the following program:2 charges=charges+c;
#include <iostream.h> (MP2 2008-09) }
struct Game void show()
{ char Magic[20];int Score; }; {
cout<<topic<<"@"<<charges<<endl;
void main() }
{Game M={“Tiger”,500}; char };
*Choice; void main()
Choice=M.Magic; {
Choice[4]=’P’; seminar s1,s2(1000),s3("Genetic Mutation"),s4;
Choice[2]=’L’; s1.show();
M.Score+=50; s2.show();
cout<<M.Magic<<M.Score<<endl; s1.subject("ICT",2000);
Game N=M; s1.show();
N.Magic[0]=’A’;N.Magic[3]=’J’; s2.regis("Cyber Crime",2500);
N.Score-=120; s2.show();
cout<<N.Magic<<N.Score<<endl; s3.regis();
XII Computer Chap1 to 3 11
s3.show(); Note: Assume all required header files are already being
s4=s2; included in the program. (2015) 3
s4.show(); class Eval
getch(); {
} char Level;
A) int Point;
Registration@5000 public:
Registration with Discount@4000 Eval( ) {Level=’E’;Point=0;}
ICT@7000 void Sink(int L)
Cyber Crime@6500 {
Genetic Mutation@7000 Level=
Cyber Crime@6500 L;
}
2) Find and write the output of the following C++ program void Float(int L)
code: (2016) {
Note: Assume all required header files are already being Level += L;
included in the program. 3 Point++;
class Share }
{ void Show()
long int Code; {
float Rate; cout<<Level<<”#”<<Point<<endl;
int DD; }
public: };
Share(){Code=1000;Rate=100;DD=1;} void main()
void GetCode(long int C,float R) { {
Eval E;
Code=C; E.Sink(3);
Rate=R; E.Show();
} E.Float(7);
void Update(int Change,int D) E.Show();
{ E.Sink(2);
Rate+=Change; E.Show();
DD=D; }
} A)
void Status() B#0
{ I#1
cout<<”Date:”<<DD<<endl; G#1
cout<<Code<<”#”<<Rate<<endl; 4) Obtain the output of the following C++ Program,
} which wll appear on the screen after its execution. 3
}; Important Note: (2014)
-All the desired header files are already included in
void main( ) the code, which are required to run the code. class
{ Game
Share S,T,U; { int Level, Score;
S.GetCode(1324,350); char Type;
T.GetCode(1435,250); public:
S.Update(50,28); Game(char GType=’P’)
U.Update(25,26); { Level=1;Score=01;Type=GType; }
S.Status(); void play(int GS);
T.Status(); void Change( );
U.Status(); void Show( );
} {
A) cout<<Type<<”@”<<Level<<endl;
Date:28 cout<<Score<<endl;
1324#400 }
Date:1 };
1435#250 void main( )
Date:26 {
1000#75 Game A(‘G’),B;
3) Write the output of the following C++ program code: B.Show( );
XII Computer Chap1 to 3 12
A.Play(11);
A.Change( ); 6.Find the output of the following program: 3
B.Play(25); #include <iostream.h> (2012)
A.Show( ); class METRO
B.Show( ); {
} int Mno,TripNo,PassengerCount;
void Player:: Change( ) public:
{ METRO(int Tmno=l)
Type=(Type==’P’)?’G’:’P’; {Mno=Tmno;TripNo=0;PassengerCount=0;}
} void Trip(int PC=20) {TripNo++;PassengerCount+=PC; }
void Game::Play(int GS) void status Show ()
{ {cout<<Mno<<":"<<TripNO<<":"<<PassengerCount<<end
Score+=GS; l:}
if(Score>=30) };
Level=3; void main ()
else if(Score>=20) {
Level=2; METRO M(5), T;
else M. Trip () ;
Level=1; M. StatusShow() ;
} T. StatusShow() ;
A) M. Status Show () ;
P@1 }
0
P@1
11
P@2
25
When I=7
When I=2 Since Text[7] is ‘r’, Which is a character, but which is
Since Text[2] is ‘n’, Which is a character, but which is not Upper case, else part will be executed.
not Upper case, else part will be executed. Ie Text[I]=Text[I+1]
Ie Text[I]=Text[I+1] Here Text[7]=Text[7+1]=Text[8]
Here Text[2]=Text[2+1] Ie ‘k’ will be stored in place of ‘r’
=Text[3] Now the String Text[ ] =
Ie ‘d’ will be stored in place of
‘n’ Now the String Text[ ] =
When I=8
Since Text[8] is ‘k’, Which is a character, but which is
When I=3 not Upper case, else part will be executed. Ie
Since Text[3] is ‘d’, Which is a character, but which is Text[I]=Text[I+1]
not Upper case, else part will be executed. Here Text[8]=Text[8+1]
Ie Text[I]=Text[I+1] =Text[9]
Here Text[3]=Text[3+1] Ie ‘!’ will be stored in place of ‘k’
=Text[4] Now the String Text[ ] =
Ie ‘@’ will be stored in place of ‘d’
Now the String Text[ ] =
When I=9
Since Text[9] is ‘!’, Since which is not an
alphabet, (!isalpha(Text[I])) will becomes true.
When I=4 Ie if(!isalpha(Text[I]))
XII Computer Chap1 to 3 15
Text[I]=’*’; 6113*MXAe*esbc
Ie Text[9]=’*’ 9) Find the output of the following program 2
Ie ‘*’ will be stored in place of ‘!’ #include<iostream.h> (2005 OD)
Now the String Text[ ] = #include<string.h>
#include<ctype.h>
void Change(char Msg[],int Len)
{ for(int Count=0;Count<Len;Count++)
{ if(islower(Msg[Count]))
Msg[Count] = toupper(Msg[Count]);
Output: Nnd@*Xrk!* else if(isupper(Msg[Count]))
Msg[Count] = tolower(Msg[Count]);
7)Find the output of the following program:3 else if (isdigit(Msg[Count]))
#include<iostream.h> (2008 OD) Msg[Count]=Msg[Count]+1;
#include<ctype.h> else Msg[Count] = ‘*’;
void main( ) }
{ char Mystring[ ] = “what@OUTPUT!”; }
for(int I=0; Mystring[I]!=’\0’;I++) void main( )
{ if(!isalpha(Mystring[I])) { char Message[ ]=”2005 Tests
Mystring[I]=’*’; ahead”; int Size=strlen(Message);
else if(isupper(Mystring[I])) Change(Message,Size);
Mystring[I]=Mystring[I]+1; cout<<Message<<endl;
else for(int C=0,R=Size – 1; C<=Size/2;C++,R--)
Mystring[I] =Mystring[I+1]; { char Temp=Message[C];
} Message[C]=Message[R];
cout<<Mystring;} Message[R]=Temp;
Ans: }
Output: hat@*PVUQVU* cout<<Message<<endl;
}
Ans: Output:
8) Find the output of the following program 2
#include<iostream.h> (2005 D)
3116*tESTS*AHEAD
#include<string.h> DAEHA*SSTEt*6113
#include<ctype.h>
void Convert(char Str[ ],int Len) 10)Give the output of the following program
{ for(int Count=0;Count<Len;Count++) segment(Assuming all required header files are included in
{ if(isupper(Str[Count])) the program): (2000) 2
Str[Count]=tolower(Str[Count]); char *NAME=”a ProFiLe”;
else if (islower(Str[Count])) for(int x=0;x<strlen(NAME);x++)
Str[Count]=toupper(Str[Count]); if(islower(NAME[x]))
else if(isdigit(Str[Count])) NAME[x]=toupper(NAME[x]);
Str[Count]=Str[Count]+1; else if(isupper(NAME[x]))
else Str[Count]=’*’; if(x%2!=0)
} NAME[x]=tolower(NAME[x-1]);
} else
void main( ) NAME[x]--;
{ char Text[ ]=”CBSE Exam cout<<NAME<<endl;
2005”; int Size = strlen(Text); Ans: Output: AOROoIiE
Convert(Text,Size);
cout<<Text<<endl; 11) Give the output of the following program segment:
for(int C=0,R=Size – 1;C<=Size/2;C++,R--) char *NAME=”IntRAneT”; (1998)
{ for(int x=0;x<strlen(NAME); x++)
char Temp=Text[C]; if(islower(NAME[x])
Text[C]=Text[R]; NAME[x]=toupper(NAME[x]));
Text[R]=Temp; else if(isupper(NAME[x]))
} if(x%2==0)
cout<<Text<<endl; NAME[x]=tolower(NAME[x]);
} else
Ans: NAME[x]=NAME[x-1];
Output: puts(NAME);
cbse*eXAM*3116 Ans: Output: INTTaNEE
XII Computer Chap1 to 3 16
cout<<PX<<” , “<<PY<<endl ;
12)Find the output of the following program: 2 Location(PX,PY);
#include <iostream.h> (MP1 2008-09) cout<<PX<<” , “<<PY<<endl ;
#include <ctype.h> }
void Encrypt(char T[]) A)
{ for (int i=0;T[i]!=’\0’;i+=2) 10, 8
if (T[i]==’A’ || T[i]==’E’) 20, 8
T[i]=’#’;
else if (islower(T[i])) (2)Find the output of the following program: 3
T[i]=toupper(T[i]); #inc1ude<iostream.h> (2011 D)
else void ChangeArray(int Number, int ARR[ ], int Size)
T[i]=’@’; {for (int L =0; L<Size; L++)
} if (L<Number)
void main() ARR [L] +=L;
{ char Text[]=”SaVE EartH”; e1se
//The two words in the string Textare separated by single ARR [L] *=L;
space }
Encrypt(Text); void Show (int ARR [ ], int Size)
cout<<Text<<endl; {
} for (int L=0; L<Size; L++)
Answer: (L%2!=0)?cout<<ARR[L]<<”#”: cout<<ARR[L]<<end1;
@a@E@E#rTH }
void main ( )
13) Find the output of the following program: 2 {
#include <iostream.h> (MP1 2009-10) int Array [ ] = {30, 20, 40, 10, 60,
void Secret(char Str[ ]) 50}; ChangeArray (3, Array, 6) ;
{ for (int L=0;Str[L]!=’\0’;L++); Show (Array, 6) ;
for (int C=0;C<L/2;C++) }
if (Str[C]==’A’ || Str[C]==’E’) Ans: 30
Str[C]=’#’; 21#42
else 30#240
{ 250#
char Temp=Str[C];
Str[C]=Str[L-C-1]; (3) Find the output of the following program:3
Str[L-C-1]=Temp; #include<iostream.h> (2011 OD)
} void SwitchOver(int A [ ], int N, int Split)
} {
void main() for (int K=0 ; K<N; K++)
{ if (K<Split)
char Message[ ]=”ArabSagar”; A(K]+ =K;
Secret(Message); else
cout<<Message<<endl; A [K]*=K;
} }
A) #agaSbarr void Display (int A [ ], int N)
{
for (int K=0 ; K<N ; K++)
(K%2==0)? Cout<<A[K]<<”%”:cout<<A(K]<<endl;
MODEL 4d): Output (Using functions)–2M }
void main ( )
1) Write the output of the following C++ program code: {
Note: Assume all required header files are already being int H[ ]= {30,40,50,20,10,5};
included in the program. (2015) 2 SwitchOver (H, 6, 3);
void Location(int &X,int Y=4) Display (H, 6);
{ Y+=2; }
X+=Y; Ans:
} 30%41
void main() 52%60
{ 40%25
int PX=l0,PY=2; 4)Find the output of the following program. 3
Location(PY) ; #include<iostream.h> (2007 D)
XII Computer Chap1 to 3 17
void Withdef(int HisNum=30) 7)Write the output of the following program 3
{ for(int I=20;I<=HisNum;I+=5) #include<iostream.h> (2002)
cout<<I<<”,”; void X(int &A,int &B)
cout<<endl; { A=A+B;
} B=A-B;
void Control(int &MyNum) A=A-B;
{ MyNum+=10; }
Withdef(MyNum); void main( )
} { int a=4,b=18;
void main() X(a,b);
{ int YourNum=20; cout<<a<<”,”<<b;
Control(YourNum); }
Withdef(); Ans: Output: 18,4
cout<<”Number=”<<YourNum<<endl; 8) Give the output of the following program:
} #include<iostream.h> (2001)
Ans: #include<conio.h>
Output: int g=20;
20,25,30, void func(int &x,int y)
20,25,30, { x=x-y;
Number=30 y=x*10;
5)Find the output of the following program3 cout<<x<<’,’<<y<<’\n’;
#include<iostream.h> (2007 OD) }
void Indirect(int Temp=20) void main( )
{ for(int I=10;I<=Temp;I+=5) { int g=7;
cout<<I<<”,”; func(g,::g);
cout<<endl; cout<<g<<’,’<<::g<<’\n’;
} func(::g,g);
void Direct(int &Num) cout<<g<<’,’<<::g<<’\n’;
{ Num+=10; }
Indirect(Num); Ans: Output:
} -13,-130
void main( ) -13,20
{ int Number=20; 33,330
Direct(Number); -13,33
Indirect( ); 9)Write the output of the following program3
cout<<”Number =”<<Number<<endl; #include<iostream.h> (2000)
} int func(int &x,int y=10)
Ans: Output: { if(x%y==0) return ++x;else return y- -;
10,15,20,25,30, }
10,15,20, void main( )
Number =30 { int p=20,q=23;
q=func(p,q);
6) Write the output of the following program: cout<<p<<q<<endl;
#include<iostream.h> (2003) p=func(q);
int Execute(int M) cout<<p<<q<<endl;
{ if(M%3==0) q=func(p);
return M*3; cout<<p<<q<<endl;
else }
return M+10; Ans: Output: 2023
} 1023
void Output(int B=2) 1111
{ for(int T=0;T<B;T++) 10) Write the output of the following program.
cout<<Execute(T)<<”*”; #include<iostream.h> (1999)
cout<<endl; static int i=100;
} void abc( )
void main( ) { static int i=8;
{ Output(4); cout<<”first =”<<I;
Output( ); }
Output(3); main( )
} { static int i=2;
XII Computer Chap1 to 3 18
abc( ); { P.X-=Step;
cout<<”second =”<<i<<endl; } P.Y+=Step;
Ans: Output: P.Z–=Step;
First =8second =2 }
11) Write the output of the following program: void main ( )
#include<iostream.h> (1998) { POINT P1={15, 25, 5}, P2={10, 30, 20};
void Execute(int &X,int Y=200) StepIn(P1);
{ int TEMP=X+Y; StepOut(P2,4);
X+=TEMP; cout<<P1.X<<“,”<<P1.Y<<“,”<<P1.Z<<endl;
if(Y!=200) cout<<P2.X<<“,”<<P2.Y<<“,”<<P2.Z<<endl;
cout<<TEMP<<X<<Y<<endl; StepIn(P2,12);
} cout<<P2.X<<“,”<<P2.Y<<“,”<<P2.Z<<endl;
void main( ) }
{ int A=50,B=20; Ans. 16, 24, 6
Execute(B); 6, 34, 16
cout<<A<<B<<endl; 18, 22, 28
Execute(A,B); (2) Find the output of the following program: 3
cout<<A<<B<<endl; #include <iostream.h> (2010 OD)
} struct THREE_D
12)Find the output of the following program3 { int X,Y,Z; };
#include <iostream.h> (MP2 2008-09 ) void MoveIn(THREE_D &T, int Step=l)
void Changethecontent(int Arr[], int Count) {T.X+=Step; T.Y-
{ for (int C=1;C<Count;C++) =Step;
Arr[C-1]+=Arr[C]; T.Z+=Step;
} }
void main() void MoveOut(THREE_D &T, int Step=l)
{ {T.X-=Step;
int A[ ]={3,4,5},B[ ]={10,20,30,40},C[ ]={900,1200}; T.Y+=Step;
Changethecontent(A,3); T.Z-=Step;
Changethecontent(B,4); }
Changethecontent(C,2); void main ()
for (int L=0;L<3;L++) { THREE_D Tl={lO,20,5},T2={30,lO,40};
cout<<A[L]<<’#’; MoveIn(T1);
cout<<endl; MoveOut(T2,5) ;
for (L=0;L<4;L++) cout<<Tl.X<<“,”<<Tl.Y<<“,”<<T1.Z<<endl;
cout<<B[L] <<’#’; cout<<T2.X<<“,”<<T2.Y<<“,”<<T2.Z<<endl;
cout<<endl; MoveIn(T2,l0);
for (L=0;L<2;L++) cout<<T2.X<<“,”<<T2.y<<“,”<<T2.Z<<endl;
cout<<C[L] <<’#’; }
} Ans. 11, 19, 6
Answer: 25, 15, 35
7#9#5# 35, 5, 45
30#50#70#40#
2100#1200# 3) Find the output of the following program:
#include<iostream.h> (2005 D)
MODEL 4e): Output (Using functions & struct MyBox
Structures) – 3M { int Length,Breadth,Height;
};
void Dimension(MyBox M)
(1) Find the output of the following program : 3 { cout<<M.Length<<”x”<<M.Breadth<<”x”;
#inc1ude <iostream.h> (2010 D) cout<<M.Height<<endl;
struct POINT
}
{ int X, Y, Z; }; void main( )
{ MyBox B1={10,15,5},B2,B3;
void StepIn(POINT & P, int ++B1.Height;
Step=1) { P.X+=Step; Dimension(B1);
P.Y-=Step; B3=B1;
P.Z+=Step;
++B3.Length;
}
B3.Breadth++;
void StepOut(POINT & P, int Step=1) Dimension(B3);
XII Computer Chap1 to 3 19
B2=B3; Calculate(PL,15);
B2.Height+=5; cout<<PL.Score<<”:”<<PL.Bonus<<endl;
B2.Length--; }
Dimension(B2); Answer:
} 11:20
4) Find the output of the following program: 12:30
#include<iostream.h> (2005 OD) 13:45
struct Package 7) Find the output of the following program:3
{ int Length,Breadth,Height; #include <iostream.h> (MP1 2009-10)
}; struct GAME
void Occupies(Package M) { int Score, Bonus; };
{ cout<<M.Length<<”x”<<M.Breadth<<”x”;
cout<<M.Height<<endl; void Play(GAME &g, int N=10)
} {g.Score++;
void main( ) g.Bonus+=N;
{ Package P1={100,150,50},P2,P3; }
++P1.Height; void main()
Occupies(P1); {GAME G={110,50};
P3=P1; Play(G,10);
++P3.Lengh; cout<<G.Score<<”:”<<G.Bonus<<endl;
P3.Breadth++; Play(G);
Occupies(P3); cout<<G.Score<<”:”<<G.Bonus<<endl;
P2=P3; Play(G,15);
P2.Height+=50; cout<<G.Score<<”:”<<G.Bonus<<endl;
P2.Length--; }
Occupies(P2); 111:60 3
5) Give the output of the following program: 112:70
#include<iostream.h> (2003) struct 113:85
Pixel MODEL 4f): Output (Mislleneous) – 2M
{ int C,R; };
Write a definition for function ONOFFER( ) in C++ to read Assume the class TOYS as declared below, write a function in
each object of a binary file TOYS.DAT, find and display C++ to read the objects TOYS from binary file TOYS.DAT and
details of those toys, which has status as “ÖNOFFER”. display those details of those TOYS, which are meant for
Assume that the file TOYS.DAT is created with the help children of AgeRange “5 to 8”. (2014) 3 class
of objects of class TOYS, which is defined below: (2016) 3 TOYS
class TOYS { int ToyCode; char
{ ToyName[10]; char
int TID;char Toy[20],Status[20]; float AgeRange; public:
MRP; public:
void Getinstock() void Enter( )
{cin>>ToyCode;
XII Computer Chapter – 7,8 85
gets(ToyName); found=1;
gets(AgeRange); break;
} }
void Display( ) }
{cout<<ToyCode<<”:”<<ToyName<<endl; }
cout<<AgeRange<<endl; if(found= =0)
} cout<<”Given Price not Match”;
char *WhatAge( ) }
{return AgeRange;
} (c) Write a function in C++ to search for the details (Phone
Answer) no and Calls) of those Phones, which have more than 800 calls
void Show( ) from a binary file "phones.dat" Assuming that this binary
{TOY T; file contains records/objects of class Phone, whichis defined
ifstream fcin(“TOY.DAT”,ios::in|ios::binary); below. (2012) 3
while(fcin) class Phone
{ fcin.read((char *)&T,sizeof(T)); {
if(strcmp((T,WhatAgeR( ),”5 to 8”)= =0) char Phoneno [10] ; int Calls ;
T.Display( ); public:
} void Get 0 {gets (Phoneno) ; cin>>ea11s;)
fcin.close( ); void Bi11ing() {cout<<Phoneno<<"#"<<Ca11s«end1:}
} int GetCa11s () {return Ca11s;}
};
Assuming the class ANTIQUE as declared below, write a Ans
function in C++ to read the objects of ANTIQUE from void Search ( )
binary file ANTIQUE.DAT and display those antique items, {
which are priced between 10000 and 15000. (2013) 3 Phone P;
class ANTIQUE fstream fin;
{ int ANO; fin. open ("phones. dat", ios: :binary| ios: :in);
char Aname[10]; whi1e (fin.read((char*) &P, sizeof (P)))
float Price; {
public: if(P.GetCa11s () >
void BUY( ) 800) P.Billing () ;
{ cin>>ANO; }
gets(Aname); fin.c1ose () ; // Ignore
cin>>price; }
}
void SHOW( )
{cout<<ANO<<endl;
cout<<Aname<<endl; (c) Write a function in C++ to search for a camera from a binary
cout<<Price<<endl; file "CAMERA.DAT" containing the objects of class" CAMERA
} (as defined below). The user should enter the Model No and the
float GetPrice( ) function should search display the details of
{ return Price; the camera. (2011 OD)3
} class CAMERA
Answer) { long ModelNo;
void Search(float pr) float MegaPixel;
{ int Zoom;
ifstream char Details[120];
ifile(“ANTIQUE.DAT”,ios::in|ios::binary); if(!file) public:
{ void Enter ( )
cout<<”Could not open ANTIQUE.DAT {cin>>ModelNo>>MegaPixel>>Zoom;gets(Details);
file”; exit(0); }
} void Display ( )
else {cout<<ModelNo<<MegaPixel<<Zoom<<Details<<endl;
{ ANTIQUE A; }
int found=0; long GetModelNo ( ) {return ModelNo;}
while(!file.read((char *)&A,sizeof(A))) };
{ Ans
pr=A.GetPrice( ); void Search ( )
if(pr>=10000 && pr<=15000) {
{ CAMERA C;
A.SHOW( ); long modelnum;
XII Computer Chapter – 7,8 86
cin>>modelnum; fin.close(); //
ifstream fin; }
fin.open ("CAMERA.DAT", ios: :binary | ios: :in) OR
; while (fin.read((char*) &C,sizeof (C))) { void Read( )
if (C. GetModelNo ( ) modelnum) {FLIGHT F;
C.Display() ; ifstream fin;
} fin.open (“FLIGHT. DAT”, ios::binary) ;
Fin.close( ) ; //Ignore //OR ifstream fin (“FLIGHT. DAT”, ios:: binary);
} if (fin)
OR { fin.read((char*)&F, sizeof (F));
void Search (long modelnum)
{ while(!fin.eof( ))
CAMERA C; { if (strcmp(F. GetTo( ),“Mumbai”))
ifstream fin; F.Display( );
fin.open ("CAMERA.DAT", ios: :binary | ios: fin.read((char*)&F,sizeof(F))
:in); while(fin.read((char*)&C,sizeof(C))) { }
fin.close( );
if (C.GetModelNo() = = modelnum)
}
C. Display ();
}
Fin.close( );//Ignore (c) Write a function in C++ to search and display details. of all
} trains, whose destination is “Delhi” . from a binary file
“TRAIN.DAT”. Assuming the binary file is containing the
(c) Write a function in C++ to search and display details of all objects of the following class. (2010 OD)
flights, whose destination is “Mumbai” from a binary file
class TRAIN
“FLIGHT.DAT”. Assuming the binary file is containing the {
objects of the following class. (2010 D) int Tno; // Train Number
class FLIGHT charFrom[20]; // Train Starting Point
{ int Fno; //Flight Number charTo [20]; // Train Destination
char From[20]; //Flight Starting Point public:
char* GetFrom( )
char To[20]; //Flight Destination
{return From;
public: }
char* GetFrom( ) char* GetTo( )
{return From;} {return To;
char* GetTo( ) }
{return To;} void Input( )
void Enter( ) {cin>>Tno;
gets(From);
{ cin>>Fno; gets(To);
gets(From); }
gets(To); void Show( )
} {
void Display( ) cout<<Tno<<“:”<<From<<“:”<<To<<endl;
{ cout<<Fno<<“:”<<From<<“:”<<To<<endl; }
} };
Ans)
}; void Read ( )
Ans) {
void Read ( ) TRAIN T;
{ ifstream fin;
FLIGHT F; fin. open (“TRAIN.DAT”,ios::binary);
ifstream fin; //OR ifstream fin (“TRAIN.DAT”,
ios::binary); while(fin.read((char*)&T,
fin.open(“FLIGHT.DAT”,ios::binary);
sizeof(T))) {
//OR ifstream fin (“FLIGHT. DAT”, ios: :binary)
if(strcmp(T.GetTo(),”Delhi”)==O)
; while(fin.read((char*)&F,sizeof(F))) T.Show( ) ;
{ if (strcmp(F. GetTo(),“Mumbai”)) }
F.Display( ) ; fin.close( );
} }
XII Computer Chapter – 7,8 87
char Mname [20]; //Member Name
(c) Write a function in C++ to read and display the detail of char Type; //Member Type: L Life Member M
all the users whose status is ‘A’ (i.e. Active) from a binary file //Monthly Member G Guest
“USER.DAT”. Assuming the binary file “USER.DAT” is public:
containing objects of class USER, which is defined as follows: void Register( );
(2009 D) //Function to enter the content
class USER void Display( );
{ //Function to display all data members
int Uid ; //User Id char WhatType( )
char Uname [20];//User Name {
char Status; //User Type: A Active I return Type;
Inactive Public: }
void Register ( ); };
//Function to enter the content Ans)
void show ( ) ; void DisplayL_M( )
//Function to display all data members {
char Getstatus ( ) CLUB C;
{ fstream fin;
return Status; fin. open (“CLUB.DAT”,
} ios::binary|ios::in);
}; //OR ifstream fin (“CLUB.DAT”, ios::binary);
Ans) while(fin.read((char*)&C, sizeof(C))
void DisplayActive ( ) {
{ if(C.WhatType()==’L’||C.WhatType()==’M’)
USER U; C .Display ( );
ifstream fin; }
fin.open (“USER.DAT”, ios::binary); fin.close( );
//OR ifstream fin (“USER.DAT”, }
ios::binary); while(fin.read((char*)&U, OR
sizeof(U))) { void Disp1ayL_M ( )
if(U.Getstatus()==’A’) {
U.show( ); CLUB C;
} fstream fin;
fin.close( ); fin.open (“CLUB.DAT”, ios::binary | ios::in);
} //ifstream fin (“CLUB.DAT”,ios::binary);
OR if(fin)
void DisplayActive() {
{ fin.read((char*)&C, sizeof(C));
USER U; while(!fin.eof())
ifstream fin; {
fin.open (“USER.DAT”, ios::binary); if(C.WhatType()==’L’||C.WhatType()==’M’)
//OR ifstream fin(“USER.DAT”,ios::binary); C. Display( );
if (fin) fin.read((char*)&C, sizeof(C));
{ }
fin.read((char*)&U, sizeof(U)); }
while(!fin.eof()) fin.close( );
{ }
if (U.Getstatus( )==’A’)
U.show( ) ; 4.c)Given a binary file PHONE.DAT, containing records of
fin.read((char*)&U, sizeof(U)) the following structure type (2008 D)
} class phonlist
fin.close( ); {
} char Name[20] ;
char Address[30] ;
(c) Write a function in C++ to read and display the detail of char AreaCode[5] ;
all the members whose membership type is ‘L’ or ‘M’ from a char PhoneNo[15] ;
binary file “CLUB.DAT”. Assume the binary file public ;
“CLUB.DAT” contains objects of class CLUB, which is void Register( ) ;
defined as follows: (2009 OD) void Show( ) ;
class CLUB int CheckCode(char AC[ ])
{ { return strcmp(AreaCode,AC) ;
int Mno; //Member Number }
XII Computer Chapter – 7,8 88
}; only those records from GAME.DAT where the game name is
Write a function TRANSFER( ) in C++, that would copy all those “Basket Ball”.
records which are having AreaCode as “DEL” from PHONE.DAT Solution:
to PHONBACK.DAT. void BPlayers( )
Solution: {
void TRANSFER( ) ifstream fin(“GAME.DAT’,ios::in,ios::binary);
{ ofstream fout(“BASKET.DAT”,ios::out|ios::binary);
ifstream fin(“PHONE.DAT’,ios::in,ios::binary); Game G;
ofstream fout(“PHONEBACK.DAT”, while(fin) // or while(!fin.eof( ))
ios::out,ios::binary); {
phonlist P; fin.read((char*)&G,sizeof(Game));
while(fin) // or while(!fin.eof( )) if(strcmp(G.GameName,”Basket Ball”)= = 0)
{ fout.write((char*)&G,sizeof(G));
fin.read((char*)&P,sizeof(P)); }
if(P.CheckCode(“DEL”)= = 0) fin.close( );
fout.write((char*)&P,sizeof(P)); fout.close( );
} }
fin.close( );
fout.close( ); 4.c)Given a binary file SPORTS.DAT,containg records of the
} following structure type: (2007 OD)
Write the definition of a function grace_score (int score [], Write a code for function EvenOdd(int T[ ], int C) in C++,
int size) in C++, which should check all the elements of the to add 1 in all the odd values and 2 in all the even values of
array and give an increase of 5 to those scores which are less the array T.
than 40. Example: If the original content of an array S is (2014) 3
Example: if an array of seven integers is as follows:
45, 35, 85, 80, 33, 27, 90 T[0] T[1] T[2] T[3] T[4]
After executing the function, the array content should 35 12 16 69 26
be changed as follows: The modified content will be:
45, 40, 85, 80, 38, 32, 90 (2016)3 T[0] T[1] T[2] T[3] T[4]
Ans) 36 14 18 70 28
void grace_score(int score[],int size) Answer)
{ void EvenOdd(int T[ ],int C)
for(int i=0;i<size;i++) {
{ int I;
if(score[i]<40) for(i=0;i<C;i++)
score[i]=score[i]+5; {
cout<<score[i]<<" "; if(T[i]%2==0)
} T[i]=T[i]+2;
} else
T[i]=t[i]+1;
Write the definition of a function FixSalary(float Salary[], int }
N) in C++, which should modify each element of the array cout<<”Modified content will be: “;
Salary having N elements, as per the following rules: (2016) 2 for(i=0;i<C;i++)
cout<<T[i];
}
b)An array S[40][30] is stored in the memory along the row (b) An array T[20][10] is stored in the memory along the
with each of the element occupying 2 bytes, find out the column with each of the elements occupying 2 bytes. Find out
memory location for the element S[20][10], if the Base the memory location of T[10][5], if the element T[2][9] is
Address of the array is 5000. 3 (MP109-10) stored at the location 7600.(2012) 3
Ans) Ans
Given,W=2 Assuming LBR=LBC=0
N=40 W=2 bytes
M=30 Number of Rows (M) =20
Base(S)=5000 Number of Co1umns(N)=10
LOC(T[I] [J]) = B +(I + J*M)*W
Row Major Formula: LOC(T[2] [9]) = B +(2+9*20)* 2
XII Computer Chapter – 9 110
7600 = B + (182*2) (b) An array T[90][100] is stored in the memory along the
B = 7600 - 364 column with each of the elements occupying 4 bytes. Find out the
B = 7236 memory location for the element T[10][40], if the Base Address
LOC (T[10] [5]) = 7236 +(10+5*20)* 2 of the array is 7200. (2010D)
= 7236 + (110*2) Ans.
= 7236 + 220 Loc(T[I][J)) = Base(T)+W(I+J*N)
= 7456 (where N is the number of rows, LBR = LBC = 0)
OR = 7200 + 4[10 + 40 x 90]
Assuming LBR=2, LBC=9 and B = 7600 = 7200 + 4[10+3600]
W=2 bytes = 7200 + 4 x 3610
Number of Rows (M) = 20 = 7200 + 14440
Number of Co1umns (N) = 10 = 21640
LOC (T[I] [J]) = B + ((I-LBR) + (J-LBC)*M)*W OR
LOC (S[10] [5]) = 7600 + ((10-2) + (5-9)*20)*2 Address of T[I][J] along the column
= 7600 + (8-80) * 2 = BaseAddress + W [(I-LBR)+(J-LBC)* N]
= 7600 + (-72)) * 2 (where N is the number of rows, LBR=LBC = 1)
= 7600 - 144
= 7456 Address of T[10][40] = BaseAddress
OR + 4[ (10 - 1) +(40 - l)x 90]
Assuming LBR=LBC=l = 7200+4[9 + 39 x 90]
W=2 bytes = 7200+4[9 + 3510]
Number of Rows (M) = 20 = 7200+4 x 3519
Number of Co1umns (N) = 10 = 7200+14076
LOC (T[I] [J]) = B +((I-LBR) + (J-LBC)*M)*W = 21276
LOC (T[2] [9]) = B +((2-1) + (9-1)*20)* 2
7600 = B + (161*2) (b) An array S[40][30] is stored in the memory along the
B = 7600 - 322 column with each of the element occupying 4 bytes, find out
B = 7278 the base address and address of element S[20][15], if an
LOC (T[10] [5]) = 7278 +((10-1)+(5-1)*20)* 2 element S[15][10] is stored at the memory location 7200. (2009
= 7278 + (9+80) *2) D)
= 7278 + 178 Ans)
= 7456 Loc(S[I][J]) = Base(S)+W(I+J*N)
Loc(S[15][10]) =
(b) An array P[50] [60] is stored in the memory along the Base(S)+4(15+10*40)
column with each of the element occupying 2 bytes, find out Base(S) = 7200-4*415
the memory location for the element P[10][20], if the Base Base(S) = 7200-1660
Address of the array is 6800. (2010D) Base(S) = 5540
Ans) Loc(S[20][15]) =
Loc(P[I] [J]) = Base(P)+W(I+J*M)i Loc(P[10][20]) = Base(S)+4(20+15*40)
Base(P)+2(10+20*50) Loc(S[20][15])
Loc(P[10] [20]) = 68OO + 2(10+20*50) = 5540 + 4(20+15*40)
= 6800 + 2 (10+1000) = 5540 + 4(20+600)
= 6800 + 2*1010 = 5540 + 4*620
= 6800 + 2020 = 5540 + 2480
= 8820 = 8020
OR OR
Address of P[i] [j] = BaseAddress Address of S[i][j]=BaseAddress +
+ W((i–L1)+(j–L2)*M) W[(i-L1) + ( j - L2) *M]
Address of P[10] [20]= 6800 + Address of S[15] [10] =
2((10-0)+(20-0)x50) BaseAddress+ 4[(15–0)+(10 - 0)*40]
= 6800 + 2 x 1010 7200= Base Address + 4 [415]
= 6800 + 2020 Base Address = 7200 - 4 * 415
= 8820 = 7200 - 1660
OR = 5540
Address of P[I] [J] along the column Address of S[20][15]
= BaseAddress + W((I–LBR)+(J– = 5540 + 4 [(20 - 0) + (15 - 0) x 40]
LBC)*M) = 5540 + 4 x 620
(where N is the number of rows, LBR = LBC = 1) = 5540 + 2480
Address of P[10][20] = 8020
=6800+2((10-1)+(20-l)x50) OR
= 6800 + 2 ( 9 + 19 x 50 ) Address of Sri] [j] along the column =
= 6800 + 2 x 959 = 6800 + 1918 = 8718 Base Address + W [( i - L1) + (j - L2) * M]
XII Computer Chapter – 9 111
Address of S[15)[10] = 3.b) An array Arr[40][10] is store in the memory along the
BaseAddress + 4[(15 - 1)+(10-1) x 40] column with each element occupying 4 bytes. Find out the
7200= Base Address + 4 [374] base address of the location Arr[3][6] if the location
Base Address = 7200 - 4 x 374 Arr[30][10] is stored at the address 9000. (2008D)
= 7200 - 1496 Solution:
= 5704 Address of Array[i][j] along the column =Base Address + W [( i -
Address of 5[20)[15] L1) + (j - L2) * M]
= 5704 + 4 [(20 - 1) + (15 - 1) x 40] where,
= 5704 + 4 x 579 W = size of each location in bytes = 4
= 5704 + 2316 L1 = Lower Bound of rows = 0
= 8020 L2 = Lower Bound of columns = 0 M
= Number of rows per column = 40
(b) An array T[50][20] is stored in the memory along the
column with each of the elements occupying 4 bytes. Find out Address of Array[30][10]
the base address and address of element T[30][15], if an = Base Address + 4 * (30 + 10 * 40)
element T[25][10] is stored at the memory location 9800. 9000 = Base Address + 4 * 430
(2009 OD)
Ans) Base Address = 9000 - 4 x 430
Loc(T[I][J]) = Base(T)+W(I+J*N) = 9000 -1720
Loc(T[25][10]) = Base(T)+4(25+10*50) = 7280
Base(T) = 9800-4*525 Address of Array[3][6]
Base(T) = 9800- = 7280 + 4 * (3 + 6 * 40)
2100 Base(T) = 7700 = 7280 + 4 * 243
Loc(T[30][15]) = = 7280 + 972
Base(T)+4(30+15*50) = 8252
Loc(T[30][15]) OR
= 7700 + 4(30+15*50) Address of Array[i][j] along the column = Base Address + W (( i -
= 7700 + 4(30+750) L1) + (j - L2) * M)
= 7700 + 4*780 where,
= 7700 + 3120 W = size of each location in bytes = 4
= 10820 L1 = Lower Bound of rows = 1
OR L2 = Lower Bound of columns = 1
Address of T[i][j] M = Number of rows per column =
=BaseAddress + W [(i - L1) + (j - L2) * 40 Address of Array[30][10]
M] Address of T[25] [10] = = Base Address + 4 * ((30 -1) +(10 -1) * 40)
BaseAddress + 4[(25 - 0)+(10 - 9000 = Base Address + 4 * (29+9*40)
0)*50] 9800 = Base Address + 4 [525] 9000 = Base Address + 4 * (29+360)
Base Address = 9800 - 4 * 525 9000 = Base Address + 4 * (389)
= 9800 - 21.00 Base Address
= 7700 = 9000 - 4 * 389
Address of T[30][15] = 9000 -1556
=7700 + 4 [(30 - 0) + (15 - 0) x 50] = 7444
= 7700 + 4 x 780 Address of Array[3][6]
= 7700 + 3120 = 7444 + 4 * ((3 -1) + (6 -1) * 40)
= 10820 = 7444 + 4 * (2+5 * 40)
OR = 7444 + 4 * (2+200),
Address of T[i][j] along the column = 7444 + 4 * 202
=Base Address+ W[( i - L1)+(j - L2)* M] = 7444 + 808
Address of T[25][10] = 8252
=BaseAddress + 4[(25 - 1) +(10 - OR
1)x50] 9800= Base Address + 4 [474] Address of Array[i][j] along the column =Address of Array[x][y]
Base Address + W [( i-x) + (j - y) *
= 9800 - 4 x 474 M] where,
= 9800 - 1896 W = size of each location in bytes = 4
= 7904 M = Number of rows per column = 40
Address of T[30][15] i , j = Index value of the unknown
= 7904 + 4 [(30 - 1) + (15 - 1) x 50] element x , y = Index value of the known
= 7904 + 4 x 729 element Address of Array[3][6]
= 7904 + 2916 = Address of Array[30][10]+ 4 [(3 - 30)
= 10820 +(6 -10) * 40]
= 9000 + 4 [-27 -160]
= 9000 - 4 x 187 = 9000 -748 = 8252
XII Computer Chapter – 9 112
3.b)An array Array[20][15] is stored in the memory along the Thus, Address of MAT[20][5]
column with each element occupying 8 bytes. Find out the = -472 + 8 ( 4 × 30 + 19)
base address of the element Array[2][3] if the element = -472 + 8 × 139
Array[4][5] is stored at the address 1000. (2007D) = -472 + 1112
Solution: = 640
Given Data: Aray [20][15]W=8 B=?R=20
L 0
C=15Lr = 0 c= b) An array P[20][30] is stored in the memory along the
Address of Array [2][3] =? column with each of the element occupying 4 bytes, find out
Address of Array[4][5] =1000. the Base Address of the array, if an element P[2][20] is stored
Address of an element (I,J) in column at the memory location 5000. (MP209-10) 3
major =B + W ( (I-Lr) + R(J-Lc ) ) Ans)
Therefore Given,
1000=B+8*((4-0)+20(5-0)) W=4
1000=B+8*(4+20*5) N=20
1000 =B+8*104 M=30
1000=B+832 Loc(P[2][20]) =5000
B =1000-832
B =168 Column Major Formula:
Therefore Address of
Array[2][3]=168+8*((2-0)+20(3-0)) Loc(P[I][J]) = Base(P)+W*(N*J+I)
=168+8*(2+20*3) Loc(P[2][20]) = Base(P)+4*(20*20+2)
=168+8*62 Base(P) = 5000 -4*(400+2)
=168+496 =5000-1608
=664 =3392
3.b) An array MAT[30][10] is stored in the memory along 3.b) An array P[20][30] is stored in the memory along the
column wise with each element occupying 8 bytes of the column with each of the element occupying 4 bytes, find out
memory. Find out the Base address and the address of the memory location for the element P[5][15], if an element
element MAT[20][5] , if the location MAT[3][7] is stored at P[2][20] is stored at the memory location 5000. (MP208-
the address 1000. (2006D) 09) 4
Ans) Ans)
For Column wise allocation Given,
Address of A[I][J] W=4
= BA + W[ (J –LBC) x M + (I - N=20
LBR)] Where M=30
BA = Base Address Loc(P[2][20])=5000
W = Size of each element in bytes Column Major Formula:
= 8 bytes (given) Loc(P[I][J])=Base(P)+W*(N*J+I)
M = No. of rows in the 2D Array = Loc(P[2][20])=Base(P)+4*(20*20+2)5000
30 (given) =Base(P)+4*(400+2)
Address of MAT[5][7] given is 1000. Base(P) = 5000- 1608
Assumption 1 : LBR=LBC=0 Base(P) = 3392
Therefore =3392+4*(20*15+5)
1000 = BA + 8 (7 × 30 + 5) =3392+4*(300+5) Loc(P[5][15])
= BA + 8 × 215 =3392+1220
= BA + 1720 =4612
BA = 1000 – 1720 = -720
Therefore,Base Address = - 720
Thus, Address of MAT[20][5] = -720 + 8 ( 5 × 30 + 20) 3.b) An array ARR[5][5] is stored in the memory with each
= -720 + 8 × 170 element occupying 3 bytes of space. Assuming the base
= -720 + 1360 address of ARR to be 1500, compute the address of
= 640 ARR[2][4], when the array is stored :
Assumption 2 : LBR=LBC=1 (2004)
Therefore Solution: Children, Try this answer as an assignment.
1000 = BA + 8 [(7-1) × 30 +(5-1)]
= BA + 8[6 × 30 + 4] 3.b)An array X[30][10] is stored in the memory with each
= BA + 8 ×184 element requiring 4 bytes storage. Find out the Base address
= BA + 1472 of X is 4500, find out memory locations of X[12][8] and
BA = 1000 – 1472 X[2][14], if the content is stored along the row. (2003)
= -472 Solution: Children, Try this answer as an assignment.
Therefore,Base Address = - 472 3.d) The array A[20][10] is stored in the memory with each
XII Computer Chapter – 9 113 element requiring one byte of storage if the base address of a
is 0, determine the location of A[10][5] when the array A is long Points;
stored by column major. (2002) };
Solution: Children, Try this answer as an assignment.
OR
.
3.e) Evaluate the following postfix notation of expression :
10 20 + 25 15 - * 30 / (O2005)
Ans)
Ans)
OR
OR
e) Evaluate the following postfix notation of expression:
(MP208-09)2
True, False, AND, True, True, NOT, OR,
AND Ans)
OR
OR
3.d) Obtain the postfix notation for the following infix notation of
expression showing the contents of the stack and postfix
expression formed after each step of conversion :
(P—Q)/(R*(S—T)+U) (2004)
Ans) ((P-Q)/((R*(S-T))+U))
S Symbol Stack Expression Y
No Scanned
1 ( (
2 ( ((
3 P (( P
4 - ((- P
5 Q ((- P Q
6 ) ( P Q -
7 / ( / P Q -
XII Computer Chapter – 7,8,9 135
8 ( (/ ( P Q -
9 ( (/ ( ( P Q -
10 R (/ ( ( P Q - R
11 * (/ ( ( * P Q - R
12 ( (/ ( ( * ( P Q - R
13 S (/ ( ( * ( P Q - R S
14 - (/ ( ( * ( - P Q - R S
15 T (/ ( ( * ( - P Q - R S T
16 ) (/ ( ( * P Q - R S T -
17 ) (/ ( P Q - R S T -
*
18 + (/ ( + P Q - R S T -
*
19 U (/ ( + P Q - R S T -
* U
20 ) (/ P Q - R S T -
* U +
21 ) P Q - R S T -
3.e) Write the equivalent infix expression for 10, 3, *, 7, 1, --,*,
* U + /
23, + (OD2006)
Postfix Form: PQ-RST-*U+/
EMPSALRAY
TABLE: SALARY
OR
OR
OR
OR
OR
(2013)
4)Verify the following algebraically2
(A’+B’).(A +B)=A’.B+A.B’ (2011)
15) State and verify Distributive law in Boolean Ans. LHS
Algebra.2
XII Computer – Chap 13 159
(A’ +B’ ) . (A+B) L.H.S. = X+X'.Y
= A’.A + A’.B + A.B’ + B’.B = (X+X').(X+Y)
= 0 + A’.B + A.B’+ 0 = 1.(X+Y)
= A’.B + A.B’ = X+Y
= RHS (Verified) = R.H.S
5)Verify the following algebraically: (OD 2010)2
X’.Y + X.Y’ = (X’+Y’).(X+Y) Model 1B: Boolean Laws – Using Truth Table
Ans. R. H . S (2Marks)
(X’+y’).(x+y) 1. Name the law shown below and verity it using a
= x’.(x+y)+y’.(x+y) truth table. (2014)
= x.x’+X’.y+y’.x+y’.y
= x’.y+y’.X
= x’.y+x.y’
So L.H.S=R.H.S
OR
L.H.S.
X’.Y + X.Y’
= (X’.Y+X) (X’.Y+Y’)
= (X’+X).(Y+X).(X’+Y’).(Y+Y’)
= 1.(X+Y).(X’ +Y’).1
= (X+Y).(X’+Y’) This is third distributive law.
= R.H.S. 2) Verify the following using truth table: (2012) 2
6) Verify X.Y’Z+X.Y’Z’+X’.Y’Z = X.Y’ + Y’.Z (i) X,X' = 0
algebraically. (2003)
7)State and algebraically verify Absorbtion Laws.
(MP208-09) 2
Ans) X+X.Y = X
L.H.S = X+X.Y
= X.1+X.Y
= X.(1+Y)
= X.1
= X
= R.H.S
X+X’.Y=X+Y
L.H.S. = X+X’.Y
(X+X’).(X+Y)
= 1.(X+Y) 3) Yerify the following using Truth Table: 2
= X+Y X+Y. Z=(X+Y).(X+Z)
= R.H.S
8) State and verify Demorgan's Laws algebraically.
(MP109-10)2
Ans) (X+Y)' = X'.Y'
Verification
(X+Y)'.(X+Y) = X'.Y'.(X+Y)
0 = X'.Y'.X + X'.Y'.Y
0 = X'.X .Y'+ X'.0
0 = 0 .Y'+ 0
0=0+0
0=0
L.H.S = R.H.S
4) Verify X’Y + X.Y’ + X’Y’ = (X’ + Y’) using truth
9) State and algebraically verify Absorption Laws.
(MP209-10) 2 table. (D2009) 2
Ans) Ans)
X+X.Y = X
L.H.S = X+X.Y
= X.1+X.Y
= X.(1+Y)
= X.1
=X
= R.H.S
X+X'.Y = X+Y
4. 2011
Ans)
(X+Y'+Z)(X'+Y+Z).(X'+Y'+Z)(X'+Y'+Z')
XII Computer – Chap 13 163
(8) Given the following truth table, write the product Model 3A: Write the Equivalent Boolean Expression
of sums form of the function. (2002) (2 Marks)
4)2013
Ans)F=A.B’+C’.D
2. Draw the Logic Circuit for the following Boolean
10) Write the equivalent Boolean expression for Expression : (2015)
the following logic circuit (D2007) 2 (X’+Y).Z+W’
Ans)
Ans) F(P,Q)=(P’+Q).(P+Q’)
10)Write the equivalent Boolean Expression for the
5) Draw a Logical Circuit Diagram for the following following Logic Circuit (MP208-09) 2
Boolean Expression. (D2008) 1
X’.(Y’+Z)
Ans) F(U,V)=U’.V+U.V’
6) Draw a logical circuit diagram for the following 11)Write the equivalent Boolean Expression for the
Boolean expression: A’.(B+C) 1 following Logic Circuit .(MP209-10)2
Ans) F(U,V)=U'.V+U.V'
(2017)
Ans) U.V’+U’.V+U’.V
(2016)
Ans)
5)2013
Ans)
OR
Model 4B: Reduce the Boolean Expression using K-
Map Π (3 Marks)
OR
6) Reduce the following Boolean Expression using K-
Map: 3
F(A,B,C,D)= (1,3,4,5,7,9,11,12,13,14)
1) Convert the following Boolean expression into its 1) Express P +Q’R in POS form. (OD 2006)1
equivalent Canonical Sum of Product Form (SOP): (P+Q’).(P+R)
(D2008) 2 OR
(X’+Y+Z’).(X’+Y+Z).(X’+Y’+Z).(X’+Y’+Z’) (P+Q’+R).(P+Q’+R’).(P+Q+R)
Ans)
Model 6A: Express the following in SOP (1 Mark) What if the output if (i) both inputs are FALSE(0)
(ii) one is FALSE and the other is TRUE.
1) Express P +Q’R in canonical SOP form. (D2006)1
(P + Q’R)
= P ( Q+Q’)(R+R’) + Q’R(P+P’)
= (PQ +PQ’) (R + R’) + PQ’R + P’Q’R
= PQR + PQ’R + PQR’ + PQ’R’ + PQ’R
+ P’Q’R
= PQR + PQ’R + PQR’ + PQ’R’ + P’Q’R
5)2013
Layout 2
Approximate distance between these Units is as follows: 11) “Hindustan Connecting World Association “is
planning to start their offices in four major cities in
India to provide regional IT infrastructure support
in the field of Education & Culture. The company
has planned to set up their head office in New Delhi
in three locations and have named their New Delhi
offices as “Sales Office “,”Head Office “and “Tech
Office “.The company’s regional offices are located
at “Coimbatore”,”Kolkata”and “Ahmadabad”. A
rough layout of the same is as follows:(2007OD)4
Layout Option 2:
Since the distance between Block A and Block B is quite
short
e4) The organization is planning to link its front office
situated in the city in a hilly region where cable
connection is not feasible, suggest an economic way to
connect it with reasonably high speed? 1 Ans) The most
economic way to connect it with a reasonable high speed
would be to use radio wave transmission, as they are
easy to install, can travel long distances, and penetrate
buildings easily, so they are widely used for
communication, both indoors and outdoors. Radio waves
e2) Suggest the most suitable place (i.e. block) to house
also have the advantage of being omni directional, which
the server of this organisation with a suitable reason. 1
is they can travel in all the directions from the source, so
that the transmitter and receiver do not have to be
Ans) The most suitable place / block to house the server
carefully aligned physically.
of this organisation would be Block C, as this block
contains the maximum number of computers, thus
decreasing the cabling cost for most of the computers as
well as increasing the efficiency of the maximum Theory Question: Fundamental Concepts
computers in the network.
e3) Suggest the placement of the following devices with 1) What was the role of ARPANET in the Computer
justification 1 Network? (D2010) 1
i)Repeater ii)Hub/Switch Ans. The first computer network was jointly designed
Ans) For Layout 1, since the cabling distance between by The Advanced-Research Projects Agency (ARPA)
Blocks A and C, and that between B and C are quite and Department of Defence (DoD) of United States in
large, so a repeater each, would ideally be needed along 1969 and was called ARPANET. It was an experimental
their path to avoid loss of signals during the course of project, which connected a few computers from some of
data flow in these routes the reputed universities of USA and DoD. ARPANET
allowed access to computer resource sharing projects.
This ARPANET was handed over to Defence
Communication Agency (DCA) for further
development.
2)What is the significance of ARPANET in the
network? (MP108-10) 1
Ans) The first evolution of network was jointly designed
by The Advanced Research Projects Agency (ARPA)
and Department of Defence (DoD) in 1969 and was
LAN,MAN,WAN,PAN:
2.Differentiate between PAN and LAN types of 6) What is the difference between MAN and WAN?
networks. (2016)1 (2003) 1m
7) What is the difference between LAN and WAN?
(2000) 1m
8) What is the difference between WAN and MAN.
(1999) 1m
9) What is the difference between LAN and MAN?
(1998)1m
3.2013
TOPOLOGIES:
1) Identify the type of topology on the basis of the
following: (2017MP)
a. Since every node is directly connected to the server, a
large amount of cable is needed which increases the
4 In networking, what-is WAN? How is it different installation cost of the network.
from LAN? (2011) 1 b. It has a single common data path connecting all the
Ans A WAN (wide area network), is not restricted to a nodes. 2
geographical location, although it might be confined Ans: a. Star Topology b. Bus Topology
within the bounds of a state or country. A WAN 2. Illustrate the layout for connecting 5 computers in
connects several LANs, and may be limited to an a Bus and a Star topology of Networks. (2015) 2
enterprise (a corporation or an organization) or
accessible to the public. The technology is high speed
and relatively expensive. The Internet is an example of a
worldwide public WAN.
A LAN (local area network) is a group of computers and
network devices connected together, usually within the
same building or campus.
5) What is the difference between LAN and WAN?
(OD2009) 1
Ans LAN (Local Area Network):
Interconnects a high number of access or node points or
stations within a confined physical area. An example is
the territory covered in a single office building that
houses various departments/offices. All these areas are
interconnected using a LAN.
3) Write one advantage of Bus Topology of
network. Also, illustrate how 4 computers can be
connected with each other using star topology of
network. (2012)2
Ans Cable length required for this topology is the
least compared to other networks.
OR
WAN (Wide Area Network)
Any other correct advantage of Bus Topology
It is used to connect systems with no limitation of of network.
geographical area. It is used to serve many locations Illustration of 4 computers connected with each other
distributed over a large geographical area. A system of using star topology of network.
XII Computer – Chap 13 181
(d) Name two switching techniques used to transfer data
between two terminals(computers). (D2009) 1
Ans Message Switching and Packet Switching
OR
Circuit Switching and Message Switching
OR
Circuit Switching and Packet Switching
services? (2016) 1 Ans Speed 2) Name one server side scripting language and one client
side scripting language. (2012)1
● Faster web browsing Ans Client side scripts: Java script / VB script / Peril Tcl/Tk
/ REXX.
● Faster‐file transfer
Service
Server side scripts: JSP / ASP / PHP / CGI / Perl