0% found this document useful (0 votes)
86 views

CBSE Worksheets For Class 12 Computer Science Class, Object, Constructor and Distructor

The document contains 15 coding questions related to C++ programming. It asks the reader to analyze code snippets, find outputs, minimum and maximum values of variables, and summarize key details. The questions cover topics like classes, objects, constructors, destructors, arrays, functions, references, and random number generation. The reader is expected to carefully examine each code sample and apply their knowledge of C++ concepts to understand program flow and deduce results.

Uploaded by

K Sahinandan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

CBSE Worksheets For Class 12 Computer Science Class, Object, Constructor and Distructor

The document contains 15 coding questions related to C++ programming. It asks the reader to analyze code snippets, find outputs, minimum and maximum values of variables, and summarize key details. The questions cover topics like classes, objects, constructors, destructors, arrays, functions, references, and random number generation. The reader is expected to carefully examine each code sample and apply their knowledge of C++ concepts to understand program flow and deduce results.

Uploaded by

K Sahinandan
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment : 4 Class: XII : Computer science

Topic: Class&Object, Constructor & destructor, C++ revision tour

Find the output of the following programs:

(1) #include <iostream.h> (2) #include <iostream.h>


struct GAME void Secret(char Str[ ])
{ int Score, Bonus;}; {
void Play(GAME &g, int N=10) for (int L=0;Str[L]!='\0';L++);
{ for (int C=0;C<L/2;C++)
g.Score++;g.Bonus+=N; if (Str[C]=='A' || Str[C]=='E')
} Str[C]='#';
void main() else
{ {
GAME G={110,50}; char Temp=Str[C];
Play(G,10); Str[C]=Str[L-C-1];
cout<<G.Score<<":"<<G.Bonus<<endl; Str[L-C-1]=Temp;
Play(G); }
cout<<G.Score<<":"<<G.Bonus<<endl; }
Play(G,15); void main()
cout<<G.Score<<":"<<G.Bonus<<endl; {
} char Message[ ]="ArabSagar";
Secret(Message);
cout<<Message<<endl;
}
(3) In the following program, if the (4) void swap(char &c1,char &c2)
value of Guess entered by the { char temp;
user is 65, what temp=c1;
will be the expected output(s) from the c1=c2;
following options (i), (ii), (iii) and (iv)? 2 c2=temp;
#include <iostream.h> }
#include <stdlib.h> void update(char *str)
void main() { int k,j,l1,l2;
{ l1 = (strlen(str)+1)/2;
int Guess; l2=strlen(str);
randomize(); for(k=0,j=l1-1;k<j;k++,j–)
cin>>Guess; {
for (int I=1;I<=4;I++) if(islower(str[k]))
{ swap(str[k],str[j]);
New=Guess+random(I); }
cout<<(char)New; for(k=l1,j=l2-1;k<j;k++,j–)
} {
} if(isupper(str[k]))
(i) ABBC swap(str[k],str[j]);
(ii) ACBA }
(iii) BCDA }
(iv) CABD7 void main()
{
chardata[100]={“gOoDLUck”};
cout<<”OriginalData“<<data<<endl;
update(data);
cout<<”UpdatedData“<<data;
}
(5) void main ( ) (6) void SwitchOver(int A [ ], int N, int
{ Split)
int *Queen, Moves [ ] = {11, 22, 33, {
44}; for (int K=0 ; K<N; K++)
Queen = Moves; if (K<Split)
Moves [2] + = 22; A(K]+ =K;
Cout<< “Queen @”<<*Queen<<end1; else
*Queen – = 11; A [K]*=K;
Queen + = 2; }
cout<< “Now @”<<*Queen<<endl; void Display (int A [ ], int N)
Queen++; {
cout<< “Finally@”<<*Queen«endl; for (int K=0 ; K<N ; K++)
cout<< “New Origin (K%2==0)?
@”<<Moves[0]<<end1; cout<<A[K]<<”%”:cout<<A(K]<<en
dl;
} }
void main ( )
{int H[ ]= {30,40,50,20,10,5};
SwitchOver (H, 6, 3);
Display (H, 6);
}

(7) Go through the C++ code shown (8) int A[][4] = {{11,21,32,43},
below, and find out the possible {20,30,40,50}};
output or outputs from the suggested for (int i = 1; i<2; i++)
Output Options (i) to (iv). Also, write for (int j = 0; j<4; j++)
the minimum and maximum values, cout<<A[i][j]<<”*\n”;
which can be assigned to the variable
MyNum.
#include
#include (9) int a = 5;
void main ( ) void demo(int x, int y, int &z)
{ { a += x+y;
randomize ( ) ; z = a+y;
int MyNum, Max=5; y += x;
MyNum = 20 + random (Max) ; cout<<x<<’*'<<y<<’*'<<z<<endl;
for (int N=MyNum; N<=25;N++) }
cout<N<”*”; void main()
} { int a = 3, b = 4;
(i) 20*21*22*23*24*25 demo(::a,a,b);
(ii) 22*23*24*25* demo(::a,a,b);
(iii) 23*24* }
(iv) 21*22*23*24*25

: (10) #include<iostream.h> (11) #include


int g=20; void main()
void Func(int &x, int y) {
char a[2]={”Amit”,”Sumit”};
{
for(int i=0;i<2;i++)
x=x-y; {
y=x*10; int l=strlen(a[i]);
cout<<x<<’,’<<y<<”\n”; for(int j=0;j<2;j++)
cout<<a[i]<<” : “;
}
void main() }
{ }
int g=7;
Func(g,::g);
cout<<g<<’,’<<::g<<’\n’;
Func(::g,g);
cout<<g<<’,’<<::g<<’\n’;
}

(12) #include (13) In the following C++ program


class student , what will the maximum and
{ minimum value of r generated
public: with the help of random
student() function.
{
cout<<”\n Computer
Science“; #include
} voidmain()
~student() {
{ int r;
cout<<” subject”;
} randomize();
}st; r=random(20)+random(2);
void main() cout<<r;
{ }
cout<<” is my best“
}
(14) (15) int a = 3;
int A[][3] ={{1,2,3}, void demo(int x,int y,int
{5,6,7}}; &z)
for (int i = 1; i<2; i++) { a += x+y;
for (int j = 0; j<3; j++) z = a+y;
cout<<A[i][j]<<"*\n"; y += x;
cout<<x<<'*'<<y<<'*'<<z<<endl;
}
void main()

{ int a = 2, b = 5;
demo(::a,a,b);
demo(::a,a,b);
}

You might also like