Study the following program and select 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 NUM.
Note :
– Assume all required header files are already being included in the program.
– random(n) function generates an integer between 0 and n – 1.
void main()
{
randomize();
int NUM;
NUM=random(3)+2;
char TEXT[]='ABCDEFGHIJK';
for (int I=1;I<=NUM; I++)
{
for(int J=NUM; J<=7;J++){
cout<<TEXT[J];
}
cout<<end1;
}
}
(i) | (ii) | (iii) | (iv) |
FGHI FGHI FGHI FGHI |
BCDEFGH BCDEFGH EFGH EFGH |
EFGH EFGH EFGH EFGH |
CDEFGH CDEFGH |
Possible outcome
(iii) and (iv)
Minimum value of NUM = 2
Maximum value of NUM = 4
Observe the following C++ code and answer the question.
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;
}
};
Which function will be executed at }//Stops here? What is this function referred as?
Observe the following C++ code very carefully and rewrite it after removing any/all syntactical errors with each correction underlined.
Note: Assume all required header files are already being included in the program.
#Define float Max=70.0;
Void main()
{
int Speed
char Stop='N';
cin>>Speed;
if Speed>Max
Stop='Y';
cout<<Stop<<end;
}
Write the output of the following C++ program code:
Note: Assume all required header files are already being included in the program.
class Calc
{
char Grade;
int Bonus;
public:
Calc() {Grade='E';Bonus=0;}
void Down(int G)
{
Grade-=G;
}
Void Up(int G)
{
Grade+=G;
Bonus++;
}
void Show()
{
cout<<Grade<<'#'<<Bonus<<end1;
}
};
void main()
{
Calc c;
C.Down(2);
C.Show();
C.Up(7);
C.Show();
C.Down(2);
C.Show();
}
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<<end1;
Position(P2,P1);
cout<<P1<<','<<P2<<end1;
}
What is a copy constructor ? Give a suitable example in C++ to illustrate with its definition within a class and a declaration of an object with the help of it.
Write the definition of a class PIC in C++ with the following description :
Private Members
– Pno //Data member for Picture Number (an integer)
– Category //Data member for Picture Category (a string)
– Location //Data member for Exhibition Location (a string)
– FixLocation //A member function to assign
//Exhibition Location as per category
//as shown in the following table
Category | Location |
Classic | Amina |
Modern | Jim Plaq |
Antique | Ustad Khan |
Public Members
– Enter() //A function to allow user to enter values
//Pno, category and call FixLocation() function
– SeeAll() //A function to display all the data members
Observe the following C++ code and answer the question.
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<
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
Find the correct identifiers out of the following, which can be used for naming variables, constants or functions in a C++ program:
While, for, Float, new, 2ndName, A%B, Amount2, _Counter
Observe the following program very carefully and write the names of those header files (s), which are essentially needed to compile and execute the following program successfully :
typedef char TEXT[80];
void main()
{
TEXT Str[] = 'Peace is supreme';
int Index=0;
while (Str[Index]!='\0'){
if (isupper(Str[Index])){
Str[Index++]='#';
}
else{
Str[Index++]='*';
}
}
puts(Str);
}