Page 147 - C++
P. 147
statename=new char[size+1];
}
state (char *s)
{
size=strlen(s);
statename=new char[size+1];
strcpy(statename,s);
}
void display()
{
cout<<statename<<endl;
}
void replace(state&a, state &b)
{
size=a.size+b.size;
delete statename;
statename=new char[size+1];
strcpy(statename, a.statename);
strcat(statename,b.statename);
}
};
void main()
{
clrscr();
char *temp="Delhi";
state state1(temp), state2("Mumbai"), state3("Nagpur"), s1,s2;
s1.replace(state1,state2);
s2.replace(s1,state3);
s1.display();
s2.display();
getch();
}
(f) Observe the following program and find out, which output(s) out of (i) to (iv) will not be expected
from the program? What will be the minimum and the maximum value assigned to the variable
chance? [2]
#include<iostream.h>
#include<stdlib.h>
void main( )
{
randomize( );
intArr[ ]={9,6},N;
int Chance=random(2)+10;
for (int C=0;C<2;C++)
{
MTP.2 Computer Science with C++ —CBSE XII