CLASS 12TH SOLVED QUESTIONS LIST
NOTE: SEARCH YOUR QUESTION, IF IT IS LISTED HERE THEN CLICK ON THE VIDEO SOLUTION LINK TO WATCH THE VIDEO SOLUTION.
USE THE SEARCH OPTION FROM THE BROWSER'S MENU, AND SEARCH FOR A KEYWORD/IDENTIFIER OF THE PROGRAM.
QUESTION 1:
Find and write the output of the following C++ program code:
typedef char TEXT[80];
void JumbleUp(TEXT T)
{
int L=strlen(T);
for (int C=0;C<L1;C+=2)
{
char CT=T[C];
T[C]=T[C+1];
T[C+1]=CT;
}
for (C=1;C<L;C+=2)
{
if (T[C]>=’M’ && T[C]<=’U’)
T[C]=’@’;
}
}
void main()
{
TEXT Str=”HARMONIOUS”;
JumbleUp(Str);
cout<<Str<<endl;
}
VIDEO SOLUTION OF QUESTION 1.
QUESTION 2:
Find and write the output of the following C++ program code: (3)
class Share
{
long int Code;
float Rate;
int DD;
public:
Share()
{
Code=I0 0 0;Rate=I0 0;DD=I;
}
void GetCode(long int C,float R)
{
Code=C;
Rate=R;
}
void Update(int Change,int D)
{
Rate+=Change;
DD=D;
}
void Status()
{
cout<<"Date:"<<DD<<endl;
cout<<Code<<"#"<<Rate<<endl;
}
};
void main()
{
Share S,T,U;
S.GetCode(1324,350) ;
T.GetCode(1435,250) ;
S.Update(50,28) ;
U.Update(-25,26);
S.Status();
T.Status();
U.Status();
}
VIDEO SOLUTION OF QUESTION 2.
QUESTION 3:
Rewrite the following C++ code after removing any/all syntactical errors with each
correction underlined. (2)
Note: Assume all required header files are already being included in the program.
#define Formula(a,b) = 2*a+b
void main()
{
float X=3.2; Y=4.1;
Z=Formula(X,Y);
cout<<'Result='<<Z<<endl;
}
VIDEO SOLUTION OF QUESTION 3.
QUESTION 4:
Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program.
void change (into *s)
{
For (into i=0; i<4;i++)
{
if (*s<40
{
if(*s%2==0)
*s=*s+10;
else
*s=*s+11;
}
else
{
if(*s%2==0)
*s=*s-10;
else
*s=*s-11;
}
cout<<*s<<" ";
s++;
}
}
void main()
{
int score[]={25,60,35,53};
change(score);
}
VIDEO SOLUTION OF QUESTION 4.
QUESTION 5:
Write the definition of a class CITY in C++ with following description:
Private Members
- Ccode //Data member for City Code (an integer)
- CName //Data member for City Name (a string)
- Pop //Data member for Population (a long int)
- KM //Data member for Area Coverage (a float)
- Density //Data member for Population Density (a float)
- DenCal() //A member function to calculate --Density as Pop/KM
Public Members
- Record() //A function to allow user to enter values of Acode,Name,Pop,KM and call DenCal() function
- View() //A function to display all the data members also display a message "Highly Populated City"
//if the Density is more than 10000
VIDEO SOLUTION OF QUESTION 5.
QUESTION 6:
Look at the following C++ code and find the possible output(s) from the options (i) to
(iv) following it. Also, write the maximum and the minimum values that can be
assigned to the variable PICKER. (2)
void main()
{
randomize();
int PICKER;
PICKER=1+random(3) ;
char COLOR[] [5]={"BLUE","PINK","GREEN","RED"};
for(int I=O;I<=PICKER; 1++)
{
for(int J=0; J<=I;J++)
cout<<COLOR[J];
cout<<endl;
}
}
VIDEO SOLUTION OF QUESTION 6.
QUESTION 7:
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(s) 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.
#include <iostream.h>
#include <stdlib.h>
const int LOW=25;
void main ()
{
randomize() ;
int P01NT=5,Number;
for (int I=1;I<=4;I++)
{
Number=LOW+random(POINT);
Cout<<Number<<“:”;
P0INT--;
}
}
(i) 29:26:25:28:
(ii) 24:28:25:26:
(iii) 29:26:24:28:
(iv) 29:26:25:26:
VIDEO SOLUTION OF QUESTION 7.
QUESTION 8:
Find the output of the following program.
#include<iostream.h>
struct Dress
{
int size,cost,Tax,Total_cost;
};
void change(Dress &S, int Flag=1)
{
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;
}
VIDEO SOLUTION OF QUESTION 8
QUESTION 9:
Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program .
void Position (int &C1, int C2=3)
{
C1+=2;
C2+=Y;
}
void main()
{
int P1=20, P2=4;
Position(P1);
cout<<P1<<”,”<<P2<<endl;
Position(P2,P1);
cout<<P1<<”,”<<P2<<endl;
}
VIDEO SOLUTION OF QUESTION 9
QUESTION 10:
Write the definition of a function Alter(int A[], int N) in C++, which should change
all the multiples of 5 in the array to 5 and rest of the elements as 0. For example, if an
array of 10 integers is as follows:
After executing the function, the array content should be changed as follow:
VIDEO SOLUTION OF QUESTION 10
QUESTION 11
Find the output of the following program:
# include < iostream.h>
void Withdef (int HisNum = 30)
{
for (int 1=20; I<*= HisNum; I+=5)
cout<<I<<””;
cout<<endl;
}
void Control (int &MyNum)
{
MyNum+=10;
Withdef(MyNum);
}
void main ()
{
int YourNum=20;
Control (YourNum);
Withdef();
cout<<”Number=”<<YourNum<<endl;
}
VIDEO SOLUTION OF QUESTION 11
QUESTION 12
Find the output
class Array
{
int num;
int size;
public:
void change(int num, int arr[], int size)
{
for(int n=0;n<size;n++)
{
if (n<num)
{
arr[n]+=n;
}
else arr[n]*=n;
}
}
void display(int arr[], int size)
{
for(int n=0;n<size;n++)
(n%2!=0)?cout<<arr[n]<<"#":cout<<arr[n]<<endl;
}
};
void main()
{
clrscr();
Array a;
int array[]={50,40,90,10,60,70};
a.Change(4,array,7);
a.display(array,7);
getch();
}
VIDEO SOLUTION OF QUESTION 12
QUESTION 13
Find the output of the following program:
#include<iostream.h>
#include <ctype.h>
void main ()
{
Char Mystring[] = “What@OUTPUT!”;
for (int I = 0; Mystring [ I ] = ‘\0’ ; I++)
{
if ( isalpha (Mystring [ I ] ) )
Mystring [ I ] = ‘ * ’;
else if ( isupper (Mystring [ I ]) )
Mystring [ I ] = Mystring [ I ] + 1;
else
Mystring [ I ] = Mystring [ I + 1];
}
cout<< Mystring;
}
VIDEO SOLUTION OF QUESTION 13
QUESTION 14
Find the output :
VIDEO SOLUTION OF QUESTION 14
QUESTION 15
Find the output of the following program:
#include<iostream.h>
void main()
{
int Numbers[] = {2,4,8,10};
int *ptr = Numbers;
for (int C = 0; C<3; C++)
{
cout<< *ptr << “@”;
ptr++;
}
cout<<endl;
for(C = 0; C<4; C++)
{
(*ptr)*=2;
--ptr;
}
for(C = 0; C<4; C++)
cout<< Numbers [C]<< “#”;
cout<<endl;
}
VIDEO SOLUTION OF QUESTION 15
QUESTION 16
Find the output of the following program:
#include<iostream.h>
void main ( )
{
int A[ ] = {10, 15, 20, 25, 30}
int *p = A;
while (*p < 30)
{
if (*p%3 ! = 0)
*p = *p + 2 ;
else
*p = *p + 1;
p++;
}
for (int J = 0; J<=4; J++)
{
cout << A[J] << “*” ;
if ( J%3 = = 0) cout<<endl;
}
}
VIDEO SOLUTION OF QUESTION 16
QUESTION 17
Find the output of the following program:
#include<iostream.h>
void main ( )
{
int Track [ ] = {10, 20, 30, 40}, *Striker ;
Stxiker=Track :
Track [1] += 30 ;
cout<<"Striker>"<<*Striker<<end1 ;
Striker – =10 ;
Striker++ ;
cout<<"Next@"<<*Striker<<end1 ;
Striker+=2 ;
cout<<"Last@"<<*Striker<<end1 ;
cout<< "Reset To" <<Track[0] <<end1 ;
}
VIDEO SOLUTION OF QUESTION 17
QUESTION 18
Give the output of the following program 2
#include<iostream.h>
int global = 10;
void func(int &x, int y)
{
x = x-y;
y = x * 10;
cout<< x <<' , ' << y << "\n";
}
void main()
{
int global = 7;
func(:: global, global);
cout<<global<<' , '<<::global<<"\n";
func(global, ::global);
cout<<global<<' , '<<::global<<"\n";
}
VIDEO SOLUTION OF QUESTION 18
QUESTION 19:
Find the output of the following program:
#include<iostream.h>
void main()
{ long Number = 7583241;
int First=0, Second=0;
do
{ int R=Number%10;
if (R%2==0)
First+=R;
else
Second+=R;
Number /=10;
} while (Number>O);
cout<<First-Second;
}
VIDEO SOLUTION OF QUESTION 19
QUESTION 20:
Write the output of the following program:
# include <iostream.h>
int func(int &x, int y = 10)
{
if (x%y == 0)
return ++x;
else
return y--;
}
void main()
{
int p=20, q=23;
q=func (p,q);
cout << p << " " << " " << q << endl;
p=func (q);
cout<< p << " " << " " << q << endl;
q=func (p);
cout << p << " " << " " << q << endl;
}
VIDEO SOLUTION OF QUESTION 20
QUESTION 21:
Find the output:
VIDEO SOLUTION OF QUESTION 23
QUESTION 24:
Find the output:
QUESTION 36:
Find the output of the following program.
int m=10;
void pass(int&a,int b,int&c)
{
int m=4;
c+=m;
a*=::m;
}
int main()
{
int p=1,m=2;
pass(p,::m,m);
cout<<m<<':'<<p<<':'<<::m;
cout<<endl;
pass(::m,p,m);
cout<<m<<':'<<p<<':'<<::m;
}
QUESTION 41:
Find the output of the following C++ code considering that the binary file
SCHOOLS.DAT exists on the hard disk with the following records of 10 schools of
the class SCHOOLS.
class SCHOOLS
{
int SCode; //School Code
char SName[20]; //School Name
int NOT; //Number of Teachers in the school
public:
void Display()
{
cout<<SCode<<"#"<<SName<<"#"<<NOT<<endl;
}
int RNOT()
{return NOT;}
};
void main()
{
fstream SFIN;
SFIN.open("SCHOOLS.DAT",ios::binary | ios::in);
SCHOOLS S;
SFIN.seekg(5*sizeof(S));
SFIN.read((char*)&S, sizeof(S));
S.Display();
cout<<"Record :"<<SFIN.tellg()/sizeof(S) + 1<<endl;
SFIN.close();
}
VIDEO SOLUTION OF QUESTION 44
QUESTION 45:
Study the following program and select the possible output(s) from the option (i) to
(iv) following it. Also, write the maximum and the minimum values that can be
assigned to the variable VAL. (2)
void main()
{
randomize();
int VAL;
VAL=random(3)+2;
char GUESS[]="ABCDEFGHIJK";
for (int I=l;I<=VAL;I++)
{
for(int J=VAL;J<=7;J++)
cout«GUESS[J];
cout«endl;
}
}
(i)
BCDEFGH
BCDEFGH
(ii)
CDEFGH
CDEFGH
(iii)
EFGH
EFGH
EFGH
EFGH
(iv)
FGHI
FGHI
FGHI
FGHI
VIDEO SOLUTION OF QUESTION 45
QUESTION 46:
USE THE SEARCH OPTION FROM THE BROWSER'S MENU, AND SEARCH FOR A KEYWORD/IDENTIFIER OF THE PROGRAM.
QUESTION 1:
Find and write the output of the following C++ program code:
typedef char TEXT[80];
void JumbleUp(TEXT T)
{
int L=strlen(T);
for (int C=0;C<L1;C+=2)
{
char CT=T[C];
T[C]=T[C+1];
T[C+1]=CT;
}
for (C=1;C<L;C+=2)
{
if (T[C]>=’M’ && T[C]<=’U’)
T[C]=’@’;
}
}
void main()
{
TEXT Str=”HARMONIOUS”;
JumbleUp(Str);
cout<<Str<<endl;
}
VIDEO SOLUTION OF QUESTION 1.
QUESTION 2:
Find and write the output of the following C++ program code: (3)
class Share
{
long int Code;
float Rate;
int DD;
public:
Share()
{
Code=I0 0 0;Rate=I0 0;DD=I;
}
void GetCode(long int C,float R)
{
Code=C;
Rate=R;
}
void Update(int Change,int D)
{
Rate+=Change;
DD=D;
}
void Status()
{
cout<<"Date:"<<DD<<endl;
cout<<Code<<"#"<<Rate<<endl;
}
};
void main()
{
Share S,T,U;
S.GetCode(1324,350) ;
T.GetCode(1435,250) ;
S.Update(50,28) ;
U.Update(-25,26);
S.Status();
T.Status();
U.Status();
}
VIDEO SOLUTION OF QUESTION 2.
QUESTION 3:
Rewrite the following C++ code after removing any/all syntactical errors with each
correction underlined. (2)
Note: Assume all required header files are already being included in the program.
#define Formula(a,b) = 2*a+b
void main()
{
float X=3.2; Y=4.1;
Z=Formula(X,Y);
cout<<'Result='<<Z<<endl;
}
VIDEO SOLUTION OF QUESTION 3.
QUESTION 4:
Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program.
void change (into *s)
{
For (into i=0; i<4;i++)
{
if (*s<40
{
if(*s%2==0)
*s=*s+10;
else
*s=*s+11;
}
else
{
if(*s%2==0)
*s=*s-10;
else
*s=*s-11;
}
cout<<*s<<" ";
s++;
}
}
void main()
{
int score[]={25,60,35,53};
change(score);
}
VIDEO SOLUTION OF QUESTION 4.
QUESTION 5:
Write the definition of a class CITY in C++ with following description:
Private Members
- Ccode //Data member for City Code (an integer)
- CName //Data member for City Name (a string)
- Pop //Data member for Population (a long int)
- KM //Data member for Area Coverage (a float)
- Density //Data member for Population Density (a float)
- DenCal() //A member function to calculate --Density as Pop/KM
Public Members
- Record() //A function to allow user to enter values of Acode,Name,Pop,KM and call DenCal() function
- View() //A function to display all the data members also display a message "Highly Populated City"
//if the Density is more than 10000
VIDEO SOLUTION OF QUESTION 5.
QUESTION 6:
Look at the following C++ code and find the possible output(s) from the options (i) to
(iv) following it. Also, write the maximum and the minimum values that can be
assigned to the variable PICKER. (2)
void main()
{
randomize();
int PICKER;
PICKER=1+random(3) ;
char COLOR[] [5]={"BLUE","PINK","GREEN","RED"};
for(int I=O;I<=PICKER; 1++)
{
for(int J=0; J<=I;J++)
cout<<COLOR[J];
cout<<endl;
}
}
VIDEO SOLUTION OF QUESTION 6.
QUESTION 7:
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(s) 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.
#include <iostream.h>
#include <stdlib.h>
const int LOW=25;
void main ()
{
randomize() ;
int P01NT=5,Number;
for (int I=1;I<=4;I++)
{
Number=LOW+random(POINT);
Cout<<Number<<“:”;
P0INT--;
}
}
(i) 29:26:25:28:
(ii) 24:28:25:26:
(iii) 29:26:24:28:
(iv) 29:26:25:26:
VIDEO SOLUTION OF QUESTION 7.
QUESTION 8:
Find the output of the following program.
#include<iostream.h>
struct Dress
{
int size,cost,Tax,Total_cost;
};
void change(Dress &S, int Flag=1)
{
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;
}
VIDEO SOLUTION OF QUESTION 8
QUESTION 9:
Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program .
void Position (int &C1, int C2=3)
{
C1+=2;
C2+=Y;
}
void main()
{
int P1=20, P2=4;
Position(P1);
cout<<P1<<”,”<<P2<<endl;
Position(P2,P1);
cout<<P1<<”,”<<P2<<endl;
}
VIDEO SOLUTION OF QUESTION 9
QUESTION 10:
Write the definition of a function Alter(int A[], int N) in C++, which should change
all the multiples of 5 in the array to 5 and rest of the elements as 0. For example, if an
array of 10 integers is as follows:
After executing the function, the array content should be changed as follow:
QUESTION 11
Find the output of the following program:
# include < iostream.h>
void Withdef (int HisNum = 30)
{
for (int 1=20; I<*= HisNum; I+=5)
cout<<I<<””;
cout<<endl;
}
void Control (int &MyNum)
{
MyNum+=10;
Withdef(MyNum);
}
void main ()
{
int YourNum=20;
Control (YourNum);
Withdef();
cout<<”Number=”<<YourNum<<endl;
}
VIDEO SOLUTION OF QUESTION 11
QUESTION 12
Find the output
class Array
{
int num;
int size;
public:
void change(int num, int arr[], int size)
{
for(int n=0;n<size;n++)
{
if (n<num)
{
arr[n]+=n;
}
else arr[n]*=n;
}
}
void display(int arr[], int size)
{
for(int n=0;n<size;n++)
(n%2!=0)?cout<<arr[n]<<"#":cout<<arr[n]<<endl;
}
};
void main()
{
clrscr();
Array a;
int array[]={50,40,90,10,60,70};
a.Change(4,array,7);
a.display(array,7);
getch();
}
VIDEO SOLUTION OF QUESTION 12
QUESTION 13
Find the output of the following program:
#include<iostream.h>
#include <ctype.h>
void main ()
{
Char Mystring[] = “What@OUTPUT!”;
for (int I = 0; Mystring [ I ] = ‘\0’ ; I++)
{
if ( isalpha (Mystring [ I ] ) )
Mystring [ I ] = ‘ * ’;
else if ( isupper (Mystring [ I ]) )
Mystring [ I ] = Mystring [ I ] + 1;
else
Mystring [ I ] = Mystring [ I + 1];
}
cout<< Mystring;
}
VIDEO SOLUTION OF QUESTION 13
QUESTION 14
Find the output :
void main()
{
float *Ptr,Points[]={20,50,30,40,10};
ptr=Points;
cout<<*Ptr<<endl;
ptr+=2;
points[2]+=2.5;
cout<<*Ptr<<endl;
ptr++;
(*ptr)+=2.5;
cout<<Points[3]<<endl;
}
VIDEO SOLUTION OF QUESTION 14
QUESTION 15
Find the output of the following program:
#include<iostream.h>
void main()
{
int Numbers[] = {2,4,8,10};
int *ptr = Numbers;
for (int C = 0; C<3; C++)
{
cout<< *ptr << “@”;
ptr++;
}
cout<<endl;
for(C = 0; C<4; C++)
{
(*ptr)*=2;
--ptr;
}
for(C = 0; C<4; C++)
cout<< Numbers [C]<< “#”;
cout<<endl;
}
VIDEO SOLUTION OF QUESTION 15
QUESTION 16
Find the output of the following program:
#include<iostream.h>
void main ( )
{
int A[ ] = {10, 15, 20, 25, 30}
int *p = A;
while (*p < 30)
{
if (*p%3 ! = 0)
*p = *p + 2 ;
else
*p = *p + 1;
p++;
}
for (int J = 0; J<=4; J++)
{
cout << A[J] << “*” ;
if ( J%3 = = 0) cout<<endl;
}
}
VIDEO SOLUTION OF QUESTION 16
QUESTION 17
Find the output of the following program:
#include<iostream.h>
void main ( )
{
int Track [ ] = {10, 20, 30, 40}, *Striker ;
Stxiker=Track :
Track [1] += 30 ;
cout<<"Striker>"<<*Striker<<end1 ;
Striker – =10 ;
Striker++ ;
cout<<"Next@"<<*Striker<<end1 ;
Striker+=2 ;
cout<<"Last@"<<*Striker<<end1 ;
cout<< "Reset To" <<Track[0] <<end1 ;
}
VIDEO SOLUTION OF QUESTION 17
QUESTION 18
Give the output of the following program 2
#include<iostream.h>
int global = 10;
void func(int &x, int y)
{
x = x-y;
y = x * 10;
cout<< x <<' , ' << y << "\n";
}
void main()
{
int global = 7;
func(:: global, global);
cout<<global<<' , '<<::global<<"\n";
func(global, ::global);
cout<<global<<' , '<<::global<<"\n";
}
VIDEO SOLUTION OF QUESTION 18
QUESTION 19:
Find the output of the following program:
#include<iostream.h>
void main()
{ long Number = 7583241;
int First=0, Second=0;
do
{ int R=Number%10;
if (R%2==0)
First+=R;
else
Second+=R;
Number /=10;
} while (Number>O);
cout<<First-Second;
}
VIDEO SOLUTION OF QUESTION 19
QUESTION 20:
Write the output of the following program:
# include <iostream.h>
int func(int &x, int y = 10)
{
if (x%y == 0)
return ++x;
else
return y--;
}
void main()
{
int p=20, q=23;
q=func (p,q);
cout << p << " " << " " << q << endl;
p=func (q);
cout<< p << " " << " " << q << endl;
q=func (p);
cout << p << " " << " " << q << endl;
}
VIDEO SOLUTION OF QUESTION 20
QUESTION 21:
Find the output:
Int *function(int *p, int n, int &v)
{
int *q,*r;
for(q=p;n>0;n--,p++)
{
if(*p>*q)
{
r=q;
q=p;
}
}
v=*q;
return r;
}
int main()
{
int *ip,v;
int a[]={15,2,35,40,50,6,7,8,9,25};
ip=function(a,10,v);
cout<<v<<endl<<*ip;
return 0;
}
QUESTION 22:
Give the output of the following program segment (Assuming all required header files are
included in the program):
# include<iostream.h>
# include<ctype.h>
void change (char* state, int &s)
{ int b = s;
for (int x = 0; s>=0; x++, s−−)
if ((x+s)%2)
*(state+x) = toupper(*(state+b-x));
}
void main ( )
{
char s[ ] = “Punjab”;
int b = strlen (s)−1;
change (s, b);
cout<<s<<”#”<<b;
}
QUESTION 23:
Find the output of the following program:
#include<iostream.h>
#include<string.h>
#include<ctype.h>
void Convert(char Str[],int Len)
{
for (int Count =0; Count<Len; Count++ )
{
if (isupper (Str [Count] ) )
Str[Count]= tolower(Str[Count]);
else if (islower (Str [Count] ) )
Str[Count]= toupper(Str[Count]);
else if (isdigit (Str [Count]))
Str[Count]= Str[Count] + 2;
else Str[Count] = ‘#’;
}
}
void main ()
{
char T[] = “AISSCE 2010@”;
int ,r,Size=strlen(T);
Convert(T,Size);
cout<<T<<endl;
for (int C = 0,R=Size-l;C<=Size/2; C++,r--)
{
char Temp= T[C];
T[C] = T[r] ;
T[r] = Temp;
}
cout<<T<<endl;
}
VIDEO SOLUTION OF QUESTION 23
QUESTION 24:
Find the output:
void processptr(int *ptr)
{
for(int i=4;i>2;i--)
{
(*ptr)*=I;
ptr-=2;
}
}
int main()
{
int Num[]={2,4,8,10};
int *p=Num+3;
cout<<*p;
processptr(p);
for(int i=0;i<4;i++)
{
cout<<Num[i]<<’@’;
cout<<”\n”<<I;
}
return 0;
}
VIDEO SOLUTION OF QUESTION 24
QUESTION 25:
Find the output:
void pass(int*a, int n)
{
for(int i=0;i<n;i++)
{
*a+=i*i;
a++;
}
}
void main()
{
int p[ ]={5,2,7,9,4,3,6,8};
pass(p,8);
for(int i=0;i<8;i++)
{
cout<<p[i]<<" ";
if(i%4==0)
{
cout<<end;
}
}
}
VIDEO SOLUTION OF QUESTION 25
QUESTION 26:
void change(char Text[ ],char C)
{
for(int K=0; Text[K]!='\0'; K++)
{
if (Text[K] >=`F' && Text[k] <=`L')
{
Text[K] = to lower(Text[K]);
}
else if(Text[K] ==`E' ll 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 oldText[ ] ="pOwERALone";
change( oldText,'%');
cout<<"New Text:"<<oldText<<endl;
}
VIDEO SOLUTION OF QUESTION 26
QUESTION 27:
class METRO
{
int Mno, TripNo, PassengerCount;
public:
METRO(int Tmno=1)
{
Mno =Tmno;
TripNo=0;
PassengerCount=0;
}
void Trip(int PC=20)
{
TripNo++, PassengerCount+=PC;
}
void StatusShow()
{
cout<<Mno<< “:”<<TripNo<< “ :”<<PassengerCount<<endl;
}
};
void main()
{
METRO M(5),T;
M.Trip();
T.Trip(50);
M.StatusShow();
M.Trip(30);
T.StatusShow();
M.StatusShow();
}
VIDEO SOLUTION OF QUESTION 27
QUESTION 28:
void Encrypt (char*S,int key)
{
char *Temp=S;
if(key%2==0)
{
key--;
}
while(*Temp!='\0')
{
*Temp+=key;
Temp+=key;
}
}
int main()
{
int Key_Set[]={1,2,3};
char Pvt_Msg[]="Computer2017";
for(int C=0;C<2;C++)
{
Encrypt(Pvt_Msg,Key_Set[C]);
cout<<"New Encrypted Message after Pass "<<C+1<<"is :"<<Pvt_Msg;
cout<<endl;
}
}
VIDEO SOLUTION OF QUESTION 28
QUESTION 29:
Define a function SWAPCOL() in C++ to swap the first column elements with the last column elements, for a two-dimensional integer array passed as the argument of the function.
VIDEO SOLUTION OF QUESTION 29
QUESTION 30:
Evaluate the following postfix notation expression : 50, 60, +, 20, 10, -, *.
VIDEO SOLUTION OF QUESTION 30
QUESTION 31 :
Write a function in C++ to perform push operation on a dynamically allocated stack containing real numbers.
VIDEO SOLUTION OF QUESTION 31
QUESTION 32:
Write a function QDELETE() in c++ to perform delete operation in a linked queue which contains passenger number and passenger name.
Consider the following definiton of node in the code.
struct node
{
long int Pno;
char Pname[20];
node *Link;
};
VIDEO SOLUTION OF QUESTION 32
QUESTION 33:
Consider the following portion of a program, which implements passenger queue for
a bus.Write the definiton of function Insert, to insert a new node in the queue with required information.
struct NODE
{
int Ticketno;
char PName[20];
NODE * NEXT;
};
class Queueofbus
{
NODE *rear, *front;
public:
Queueofbus()
{
rear = NULL;
front = NULL;
};
void Insert();
void Delete();
~Queueofbus()
};
VIDEO SOLUTION OF QUESTION 33
QUESTION 34 :
Write a function NewMAT(int A[][],int r,int c ) in C++, which accepts a 2d array of
integer and its size as parameters divide all those array elements by 6 which are not in
the range 60 to 600(both values inclusive) in the 2d Array .
QUESTION 25:
Find the output:
void pass(int*a, int n)
{
for(int i=0;i<n;i++)
{
*a+=i*i;
a++;
}
}
void main()
{
int p[ ]={5,2,7,9,4,3,6,8};
pass(p,8);
for(int i=0;i<8;i++)
{
cout<<p[i]<<" ";
if(i%4==0)
{
cout<<end;
}
}
}
VIDEO SOLUTION OF QUESTION 25
QUESTION 26:
void change(char Text[ ],char C)
{
for(int K=0; Text[K]!='\0'; K++)
{
if (Text[K] >=`F' && Text[k] <=`L')
{
Text[K] = to lower(Text[K]);
}
else if(Text[K] ==`E' ll 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 oldText[ ] ="pOwERALone";
change( oldText,'%');
cout<<"New Text:"<<oldText<<endl;
}
VIDEO SOLUTION OF QUESTION 26
QUESTION 27:
class METRO
{
int Mno, TripNo, PassengerCount;
public:
METRO(int Tmno=1)
{
Mno =Tmno;
TripNo=0;
PassengerCount=0;
}
void Trip(int PC=20)
{
TripNo++, PassengerCount+=PC;
}
void StatusShow()
{
cout<<Mno<< “:”<<TripNo<< “ :”<<PassengerCount<<endl;
}
};
void main()
{
METRO M(5),T;
M.Trip();
T.Trip(50);
M.StatusShow();
M.Trip(30);
T.StatusShow();
M.StatusShow();
}
VIDEO SOLUTION OF QUESTION 27
QUESTION 28:
void Encrypt (char*S,int key)
{
char *Temp=S;
if(key%2==0)
{
key--;
}
while(*Temp!='\0')
{
*Temp+=key;
Temp+=key;
}
}
int main()
{
int Key_Set[]={1,2,3};
char Pvt_Msg[]="Computer2017";
for(int C=0;C<2;C++)
{
Encrypt(Pvt_Msg,Key_Set[C]);
cout<<"New Encrypted Message after Pass "<<C+1<<"is :"<<Pvt_Msg;
cout<<endl;
}
}
QUESTION 29:
Define a function SWAPCOL() in C++ to swap the first column elements with the last column elements, for a two-dimensional integer array passed as the argument of the function.
VIDEO SOLUTION OF QUESTION 29
QUESTION 30:
Evaluate the following postfix notation expression : 50, 60, +, 20, 10, -, *.
VIDEO SOLUTION OF QUESTION 30
QUESTION 31 :
Write a function in C++ to perform push operation on a dynamically allocated stack containing real numbers.
VIDEO SOLUTION OF QUESTION 31
QUESTION 32:
Write a function QDELETE() in c++ to perform delete operation in a linked queue which contains passenger number and passenger name.
Consider the following definiton of node in the code.
struct node
{
long int Pno;
char Pname[20];
node *Link;
};
VIDEO SOLUTION OF QUESTION 32
QUESTION 33:
Consider the following portion of a program, which implements passenger queue for
a bus.Write the definiton of function Insert, to insert a new node in the queue with required information.
struct NODE
{
int Ticketno;
char PName[20];
NODE * NEXT;
};
class Queueofbus
{
NODE *rear, *front;
public:
Queueofbus()
{
rear = NULL;
front = NULL;
};
void Insert();
void Delete();
~Queueofbus()
};
VIDEO SOLUTION OF QUESTION 33
QUESTION 34 :
Write a function NewMAT(int A[][],int r,int c ) in C++, which accepts a 2d array of
integer and its size as parameters divide all those array elements by 6 which are not in
the range 60 to 600(both values inclusive) in the 2d Array .
VIDEO SOLUTION OF QUESTION 34
QUESTION 35:
Write a function in C++ to count the words “this” and “these” present in a text file “ARTICLE.TXT”.
VIDEO SOLUTION OF QUESTION 35QUESTION 35:
Write a function in C++ to count the words “this” and “these” present in a text file “ARTICLE.TXT”.
QUESTION 36:
Find the output of the following program.
int m=10;
void pass(int&a,int b,int&c)
{
int m=4;
c+=m;
a*=::m;
}
int main()
{
int p=1,m=2;
pass(p,::m,m);
cout<<m<<':'<<p<<':'<<::m;
cout<<endl;
pass(::m,p,m);
cout<<m<<':'<<p<<':'<<::m;
}
VIDEO SOLUTION OF QUESTION 36
QUESTION 37:
Find the output of the following program.
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
class friendname
{
char *name;
int a;
public:
friendname()
{
a=0;
name=new char[a+1];
}
friendname(char *f)
{
a=strlen(f);
name=new char[a+1];
strcpy(name,f);
}
void display()
{
cout<<name<<endl;
}
void modify(friendname &d,friendname &b)
{
a=d.a+b.a;
delete name;
name=new char[a+1];
strcpy(name,d.name);
strcat(name,b.name);
}
};
int main()
{
char * temp="Dark";
friendname name1(temp),name2("Soft"),name3("Doll"),name4("Barbie"),F1,F2,F3;
F1.modify(name1,name2);
F2.modify(F1,name3);
F3.modify(name4,F2);
F1.display();
F2.display();
F3.display();
}
QUESTION 37:
Find the output of the following program.
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
class friendname
{
char *name;
int a;
public:
friendname()
{
a=0;
name=new char[a+1];
}
friendname(char *f)
{
a=strlen(f);
name=new char[a+1];
strcpy(name,f);
}
void display()
{
cout<<name<<endl;
}
void modify(friendname &d,friendname &b)
{
a=d.a+b.a;
delete name;
name=new char[a+1];
strcpy(name,d.name);
strcat(name,b.name);
}
};
int main()
{
char * temp="Dark";
friendname name1(temp),name2("Soft"),name3("Doll"),name4("Barbie"),F1,F2,F3;
F1.modify(name1,name2);
F2.modify(F1,name3);
F3.modify(name4,F2);
F1.display();
F2.display();
F3.display();
}
QUESTION 38:
class Traveller
{
long PNR;
char TName[20];
public :
Traveller() //Function 1
{
cout<<”Ready”<<end1;
}
void Book(long P,char N[])//Function 2
{
PNR = P; strcpy(TName, N);
}
void Print() //Function 3
{
cout<<PNR << TName <<end1;
}
~Traveller() //Function 4
{
cout<<”Booking cancelled!”<<end1;
}
};
(i) Fill in the blank statements in Line 1 and Line 2 to execute Function 2 and Function 3
respectively in the following code:
void main{)
{
Traveller T;
_____________ //Line 1
_____________ //Line 2
} //Stops here
(ii) Which function will be executed at}//Stops here? What is this function referred as?
QUESTION 39:
Find the output of the following code:
class CLIENTS
{
int Cno;
char Name[20];
public:
void In();
void Out();
};
void main()
{
fstream CF;
CF.open("CLIENTS.DAT",ios:: binary| ios::in) ;
CLIENTS C;
CF.read((char*)&C,sizeof(C));
CF.read((char*)&C,sizeof(C));
CF.read((char*)&C,sizeof(C));
int POS=CF.tellg()/sizeof(C);
cout<<"PRESENT RECORD:"<<POS<<endl;
CF.close() ;
}
VIDEO SOLUTION OF QUESTION 39
QUESTION 40:
Observe the program segment given below carefully and fill the blanks marked as Statement 1 and Statement 2 using tellg() and seekp() functions
for performing the required task.
class Client
{
long Cno;
char Name[20],
Email[30] ;
public:
void Enter() ;
void Modify() ;
long ReturnCno()
{
return Cno;
}
};
void ChangeEmail()
{
Client O;
fstream F;
F.open (“INFO.DAT”,ios::binary|ios::in|ios::out);
long C;
cin>>C;
while (F.read((char*)&O, sizeof(O)))
{
if (C==O.ReturnCno())
{
O.Modify();
int Pos = ________//To find the current position of file pointer
_______________ //To move the file pointer to write the modified record back onto the file for the desired Cno.
F.write((char*)&O, sizeof(O));
}
}
F.close();
}
VIDEO SOLUTION OF QUESTION 40
QUESTION 40:
Observe the program segment given below carefully and fill the blanks marked as Statement 1 and Statement 2 using tellg() and seekp() functions
for performing the required task.
class Client
{
long Cno;
char Name[20],
Email[30] ;
public:
void Enter() ;
void Modify() ;
long ReturnCno()
{
return Cno;
}
};
void ChangeEmail()
{
Client O;
fstream F;
F.open (“INFO.DAT”,ios::binary|ios::in|ios::out);
long C;
cin>>C;
while (F.read((char*)&O, sizeof(O)))
{
if (C==O.ReturnCno())
{
O.Modify();
int Pos = ________//To find the current position of file pointer
_______________ //To move the file pointer to write the modified record back onto the file for the desired Cno.
F.write((char*)&O, sizeof(O));
}
}
F.close();
}
VIDEO SOLUTION OF QUESTION 40
QUESTION 41:
Find the output of the following C++ code considering that the binary file
SCHOOLS.DAT exists on the hard disk with the following records of 10 schools of
the class SCHOOLS.
class SCHOOLS
{
int SCode; //School Code
char SName[20]; //School Name
int NOT; //Number of Teachers in the school
public:
void Display()
{
cout<<SCode<<"#"<<SName<<"#"<<NOT<<endl;
}
int RNOT()
{return NOT;}
};
void main()
{
fstream SFIN;
SFIN.open("SCHOOLS.DAT",ios::binary | ios::in);
SCHOOLS S;
SFIN.seekg(5*sizeof(S));
SFIN.read((char*)&S, sizeof(S));
S.Display();
cout<<"Record :"<<SFIN.tellg()/sizeof(S) + 1<<endl;
SFIN.close();
}
QUESTION 42:
A text file MATTER.TXT contains some text, which needs to be displayed such that every next character is separated by a symbol ‘#’.
Write a function definition for HashDisplay( ) in C++ that would display the entire content of the file MATTER.TXT in the desired format.
Example:
THE WORLD IS ROUND
Output:
T#H#E# #W#O#R#L#D# #I#S# #R#O#U#N#D#
VIDEO SOLUTION OF QUESTION 42
QUESTION 43:
(f) The following code is from a game, which generates a set of 4 random numbers.
Yallav is playing this game, help him to identify the correct option(s) 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. (2)
#include <iostream.h>
#include <stdlib.h>
const int LOW=15;
void main ( )
{
randomize( ) ;
int POINT=5, Number;
for (int I=1;I<=4;I++)
{
Number=LOW+random(POINT) ;
cout<<Number<<“:” ;
POINT--;
}
}
(i) 19:16:15:18:
(ii) 14:18:15:16:
(iii) 19:16:14:18:
(iv) 19:16:15:16:
VIDEO SOLUTION OF QUESTION 43
QUESTION 44:
(f) 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: (2)
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
QUESTION 43:
(f) The following code is from a game, which generates a set of 4 random numbers.
Yallav is playing this game, help him to identify the correct option(s) 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. (2)
#include <iostream.h>
#include <stdlib.h>
const int LOW=15;
void main ( )
{
randomize( ) ;
int POINT=5, Number;
for (int I=1;I<=4;I++)
{
Number=LOW+random(POINT) ;
cout<<Number<<“:” ;
POINT--;
}
}
(i) 19:16:15:18:
(ii) 14:18:15:16:
(iii) 19:16:14:18:
(iv) 19:16:15:16:
VIDEO SOLUTION OF QUESTION 43
QUESTION 44:
(f) 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: (2)
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
VIDEO SOLUTION OF QUESTION 44
QUESTION 45:
Study the following program and select the possible output(s) from the option (i) to
(iv) following it. Also, write the maximum and the minimum values that can be
assigned to the variable VAL. (2)
void main()
{
randomize();
int VAL;
VAL=random(3)+2;
char GUESS[]="ABCDEFGHIJK";
for (int I=l;I<=VAL;I++)
{
for(int J=VAL;J<=7;J++)
cout«GUESS[J];
cout«endl;
}
}
(i)
BCDEFGH
BCDEFGH
(ii)
CDEFGH
CDEFGH
(iii)
EFGH
EFGH
EFGH
EFGH
(iv)
FGHI
FGHI
FGHI
FGHI
VIDEO SOLUTION OF QUESTION 45
QUESTION 46:
Look at the following C++ code and find the possible output(s) from the options (i) to
(iv) following it. Also, write the maximum and the minimum values that can be
assigned to the variable CHANGER. (2)
void main ()
{
randomize();
int CHANGER;
CHANGER=random(3);
char CITY [] [25]={"DELHI","MUMBAI","KOLKATA" ,"CHENNAI"};
for(int I=O;I<=CHANGER;1++)
{
for(int J=0;J<=I;J++)
cout<<CITY[J];
cout<<endl;
}
}
(i)
DELHI
DELHIMUMABAI
DELHIMUMABAIKOLKATA
(ii)
DELHI
DELHIMUMABAI
DELHIMUMABAIKOLKATA
DELHIMUMABAIKOLKATACHENNAI
(iii)
MUMABAI
MUMABAIKOLKATA
MUMABAIKOLKATACHENNAI
(iv)
KOLKATA
KOLKATACHENNAI
VIDEO SOLUTION OF QUESTION 46
QUESTION 47:
2017
Q. find the possible output(s) from the options (i) to (iv).
Also, write the maximum values that can be assigned to each of the
variables N and M.
void main ( )
{
randomize ( );
int N=random(3);
int M=random(4);
int DOCK[3][3] = {{1,2,3},{2,3,4},{3,4,5}};
for(int R=0; R<2; R++)
{
for (int C=0; C<2; C++)
{
cout<<DOCK[R][C]<<" ";
}
cout<<endl;
}
}
(i)
1 2 3
234
345
(ii)
123
234
(iii)
12
23
(iv)
12
23
34
VIDEO SOLUTION OF QUESTION 47
QUESTION 48:
2018
Q.Look at the following C++ code and find the possible output(s) from the options
(i) to (iv) following it. Also, write the highest and lowest values that can be
assigned in the array A. (2)
void main()
{
randomize();
int A[4], C;
for(C=0; C<4; C++)
A[C]=random(C+1)+10;
for(C=3; C>=0; C--)
cout<<A[C]<<"@";
}
1. 13@10@11@10@
2. 15@14@12@10
3. 12@11@13@10@
4. 12@11@10@10@
VIDEO SOLUTION OF QUESTION 48
QUESTION 49:
2017
Find the output of the following C++ code considering that the binary file
CLIENTS.DAT exists on the hard disk with a data of 200 clients : (1)
class CLIENTS
{
int CCode;
char CName[20];
public:
void REGISTER ( );
void DISPLAY();
};
void main ( )
{
fstream File;
File.open("CLIENTS.DAT",ios::binary|ios::in);
CLIENTS C;
File.seekg(6*sizeof(C));
File.read((char*)&C, sizeof(C));
cout<<"Client Number:"<<File.tellg()/sizeof(C) + 1;
File.seekg(0,ios::end);
cout<<" of "<<File.tellg()/sizeof(C)<<endl;
File.close();
}
VIDEO SOLUTION OF QUESTION 49
QUESTION 50:
2016
Find the output of the following C++ code considering that the binary file
CLIENT.DAT exists on the hard disk with a data of 1000 clients. (1)
class CLIENT
{
int Ccode;char CName[2 0];
public:
void Register();void Display();
};
void main()
{
fstream CFile;
CFile.open("CLIENT.DAT",ios::binary|ios::in);
CLIENT C;
CFile.read((char*)&C, sizeof (C)) ;
cout<<"Rec:"<<CFile.tellg()/sizeof(C)<<endl;
CFile.read((char*)&C, sizeof (C)) ;
CFile.read((char*)&C, sizeof (C)) ;
cout<<"Rec:"<<CFile.tellg()/sizeof(C)<<endl;
CFile.close();
}
VIDEO SOLUTION OF QUESTION 50
QUESTION 51:
2015
Write a definition for function Economic() in C++ to read each record of a binary file
ITEMS.DAT, find and display those items, which costs less than 2500. Assume that the
file ITEMS.DAT is created with the help of objects of class ITEMS, which is defined
below: (3)
class ITEMS
{
int ID;
char GIFT[20];
float Cost;
public :
void Get()
{
cin>>CODE;gets(GIFT);cin>>Cost;
}
void See()
{
cout<<ID<<":"<<GIFT<<":"<<Cost<<endl;
}
float GetCost()
{
return Cost;
}
};
QUESTION 52:
2016
Write function definition for DISP3CHAR() in C++ to read the content of a text file
KIDINME.TXT, and display all those words, which have three characters in it. Example:
If the content of the file KIDINME.TXT is as follows: (2)
When I was a small child, I used to play in the garden with my grand mom. Those days
were amazingly funful and I remember all the moments of that time.
The function DISP3CHAR() should display the following:
was the mom and all the
VIDEO SOLUTION OF QUESTION 52
QUESTION 53:
2017
Write a definition for function COUNTPICS( ) in C++ to read each object of a binary
file PHOTOS.DAT, find and display the total number of PHOTOS of type PORTRAIT.
Assume that the file PHOTOS.DAT is created with the help of objects of class PHOTOS,
which is defined below: (2)
class PHOTOS
{
int PCODE;
char PTYPE[20];//Photo Type as “PORTRAIT”,“NATURE”
public:
void ENTER()
{
cin>>PCODE;
gets(PTYPE);
}
void SHOWCASE()
{
cout<<PCODE<<":" <<PTYPE<<endl;
}
char *GETPTYPE()
{
return PTYPE;
}
};
VIDEO SOLUTION OF QUESTION 53
QUESTION 54:
QUESTION 47:
2017
Q. find the possible output(s) from the options (i) to (iv).
Also, write the maximum values that can be assigned to each of the
variables N and M.
void main ( )
{
randomize ( );
int N=random(3);
int M=random(4);
int DOCK[3][3] = {{1,2,3},{2,3,4},{3,4,5}};
for(int R=0; R<2; R++)
{
for (int C=0; C<2; C++)
{
cout<<DOCK[R][C]<<" ";
}
cout<<endl;
}
}
(i)
1 2 3
234
345
(ii)
123
234
(iii)
12
23
(iv)
12
23
34
VIDEO SOLUTION OF QUESTION 47
QUESTION 48:
2018
Q.Look at the following C++ code and find the possible output(s) from the options
(i) to (iv) following it. Also, write the highest and lowest values that can be
assigned in the array A. (2)
void main()
{
randomize();
int A[4], C;
for(C=0; C<4; C++)
A[C]=random(C+1)+10;
for(C=3; C>=0; C--)
cout<<A[C]<<"@";
}
1. 13@10@11@10@
2. 15@14@12@10
3. 12@11@13@10@
4. 12@11@10@10@
VIDEO SOLUTION OF QUESTION 48
QUESTION 49:
2017
Find the output of the following C++ code considering that the binary file
CLIENTS.DAT exists on the hard disk with a data of 200 clients : (1)
class CLIENTS
{
int CCode;
char CName[20];
public:
void REGISTER ( );
void DISPLAY();
};
void main ( )
{
fstream File;
File.open("CLIENTS.DAT",ios::binary|ios::in);
CLIENTS C;
File.seekg(6*sizeof(C));
File.read((char*)&C, sizeof(C));
cout<<"Client Number:"<<File.tellg()/sizeof(C) + 1;
File.seekg(0,ios::end);
cout<<" of "<<File.tellg()/sizeof(C)<<endl;
File.close();
}
VIDEO SOLUTION OF QUESTION 49
QUESTION 50:
2016
Find the output of the following C++ code considering that the binary file
CLIENT.DAT exists on the hard disk with a data of 1000 clients. (1)
class CLIENT
{
int Ccode;char CName[2 0];
public:
void Register();void Display();
};
void main()
{
fstream CFile;
CFile.open("CLIENT.DAT",ios::binary|ios::in);
CLIENT C;
CFile.read((char*)&C, sizeof (C)) ;
cout<<"Rec:"<<CFile.tellg()/sizeof(C)<<endl;
CFile.read((char*)&C, sizeof (C)) ;
CFile.read((char*)&C, sizeof (C)) ;
cout<<"Rec:"<<CFile.tellg()/sizeof(C)<<endl;
CFile.close();
}
VIDEO SOLUTION OF QUESTION 50
QUESTION 51:
2015
Write a definition for function Economic() in C++ to read each record of a binary file
ITEMS.DAT, find and display those items, which costs less than 2500. Assume that the
file ITEMS.DAT is created with the help of objects of class ITEMS, which is defined
below: (3)
class ITEMS
{
int ID;
char GIFT[20];
float Cost;
public :
void Get()
{
cin>>CODE;gets(GIFT);cin>>Cost;
}
void See()
{
cout<<ID<<":"<<GIFT<<":"<<Cost<<endl;
}
float GetCost()
{
return Cost;
}
};
QUESTION 52:
2016
Write function definition for DISP3CHAR() in C++ to read the content of a text file
KIDINME.TXT, and display all those words, which have three characters in it. Example:
If the content of the file KIDINME.TXT is as follows: (2)
When I was a small child, I used to play in the garden with my grand mom. Those days
were amazingly funful and I remember all the moments of that time.
The function DISP3CHAR() should display the following:
was the mom and all the
VIDEO SOLUTION OF QUESTION 52
QUESTION 53:
2017
Write a definition for function COUNTPICS( ) in C++ to read each object of a binary
file PHOTOS.DAT, find and display the total number of PHOTOS of type PORTRAIT.
Assume that the file PHOTOS.DAT is created with the help of objects of class PHOTOS,
which is defined below: (2)
class PHOTOS
{
int PCODE;
char PTYPE[20];//Photo Type as “PORTRAIT”,“NATURE”
public:
void ENTER()
{
cin>>PCODE;
gets(PTYPE);
}
void SHOWCASE()
{
cout<<PCODE<<":" <<PTYPE<<endl;
}
char *GETPTYPE()
{
return PTYPE;
}
};
VIDEO SOLUTION OF QUESTION 53
QUESTION 54:
2017
Polina Raj has used a text editing software to type some text in an article. After
saving the article as MYNOTES.TXT, she realised that she has wrongly typed alphabet K
in place of alphabet C everywhere in the article.
Write a function definition for PURETEXT ( ) in C++ that would display the corrected
version of the entire article of the file MYNOTES.TXT with all the alphabets 'k' to
be displayed as an alphabet “c” on screen. (3)
Example :
If Polina has stored the following content in the file MYNOTES.TXT:
OWN A KUTE LITTLE KAR.
I KARE FOR IT AS MY KHILD
The function PURETEXT() should display the following content:
I OWN A CUTE LITTLE CAR.
I CARE FOR IT AS MY CHILD.
VIDEO SOLUTION OF QUESTION 54
QUESTION 55:
2018
Write a definition for a function TotalTeachers( ) in C++ to read each object of a
binary file SCHOOLS.DAT, find the total number of teachers, whose data is
stored in the file and display the same.
Assume that the file SCHOOLS.DAT is
created with the help of objects of class SCHOOLS, which is defined below: (2)
class SCHOOLS
{
int SCode; //School Code
char SName[20]; //School Name
int NOT; //Number of Teachers in the school
public:
void Display()
{
cout<<SCode<<"#"<<SName<<"#"<<NOT<<endl;
}
int RNOT()
{
return NOT;
}
};
VIDEO SOLUTION OF QUESTION 55
QUESTION 56:
2016
Write a definition for function ONOFFER( ) in C++ to read each object of a binary
file TOYS.DAT, find and display details of those toys, which has status as “ON OFFER”.
Assume that the file TOYS.DAT is created with the help of objects of class TOYS, which
is defined below: (3)
class TOYS
{
int TID;
char Toy[20],Status[20];
float MRP;
public:
void Getinstock()
{
cin>>TID;
gets(Toy);
gets(Status);
cin>>MRP;
}
void View()
{
cout<<TID<<" : "«Toy«" : "<<MRP<<"" : "<<Status<<endl;
}
char *SeeOffer()
{
return Status;
}
};
VIDEO SOLUTION OF QUESTION 56
QUESTION 57:
2012 Delhi
Find the output of the following code and choose the correct possible
output from the options given below from (i) to (iv) and also find
the maximum and minimum value for Turn.
#include<iostream.h>
#include<stdlib.h>
void main()
{
randomize();
int Game[]={10, 16}, P;
int Turn=random(2)+5;
for(int T=0; T<2; T++)
{
P=random(2);
cout<<Game[P]+Turn<<"#" ;
}
}
(i) 15#22# (ii) 22#16#
(iii) 16#21# (iv) 21#22#
VIDEO SOLUTION OF QUESTION 57
QUESTION 58:
Write the definition of a function AddUp(int Arr[], int N) in C++, in which all even
locations (i.e., 0,2,4,...) of the array should be added with the content of the element in
the next locations and odd locations(i.e., 1,3,5,...) elements should be incremented by 10. (3 mks)
VIDEO SOLUTION OF QUESTION 58
QUESTION 59:
Write the definition of a function SumEO(int VALUES[], int N) in C++, which
should display the sum of even values and sum of odd values of the array
separately. (2 mks)
VIDEO SOLUTION OF QUESTION 59
QUESTION 60:
Write the definition of a function FixSalary(float Salary[], int N) in C++, which
should modify each element of the array Salary having N elements, as per the following
rules: (2 MKS)
Existing Salary Values Required Modification in Value :
If less than 100000 Add 35% in the existing value
If >=100000 and <200000 Add 30% in the existing value
If >=200000 Add 20% in the existing value
VIDEO SOLUTION OF QUESTION 60
QUESTION 61:
Write a function int ALTERSUM (int B[ ] [5], int N, int M) in C++ to find and return the
sum of elements from all alternate elements of a two-dimensional array starting from
B[0][0].
VIDEO SOLUTION OF QUESTION 61
QUESTION 62:
Write definition for a function REVROW(int P[][5],int N, int M) in C++ to display the content of a
two dimensional array, with each row content in reverse order. (3 MKS)
VIDEO SOLUTION OF QUESTION 62
QUESTION 63:
Write definition for a function REVCOL (int P[][5], int N, int M) in C++ to display the content of a
two dimensional array, with each column content in reverse order. (3)
Nice bro ... Keeping doing
ReplyDeleteTHANK YOUUUUUU! :)))
ReplyDelete