The following code is from a game, which generates a set of 4 random number. Pallav 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 winds the game. Justify your answer.
#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- -;
}
}
19:16:15:18:
14:18:15:16:
19:16:14:18
19:16:15:16:
What is the difference between automatic type conversion and type casting? Also, give a suitable CPP code to illustrate both.
Which C++ header file(s) will be essentially required to be included to run/execute the following C++ code?
void main()
{
int Eno=123, char EName[]="Rehan Swarup";
cout<<setw(5)<<Eno<<Setw(25)<<EName<<endl;
}
Rewrite the following C++ Program code after removing the syntax error(s) (if any). Underline each correction.
include<iostream.h>
class TRAIN
{
long TrainNo;
char Description [25];
public
void Entry()
{
cin>>TrainNo; gets(Description);
}
void Display()
{
cout<<TrainNo<<":"<<Description<<endl;
}
};
void main()
{
TRAIN T;
Entry.T(); Display.T();
}
#include<iostream.h>
#include<stdio.h>
class TRAIN
{
long TrainNo;
char Description[25];
public :
void Entry()
{
cin>>TrainNo; gets(Description);
}
void Display()
{
cout<<TrainNo<<":"<<Description<<endl;
}
};
void main()
{
TRAIN T;
Entry.T(); Display.T();
}
Find the output of the following program :
#include<iostream.h>
struct POINT
{
int X,Y,Z;
};
Void StepIn(POINT & P, int Step = 1)
{
P.X+=Step;
P.Y-=Step;
P.Z+=Step;
}
void StepOut(POINT & P, int Step = 1)
{
P.X-=Step;
P.Y+=Step;
P.Z-=Step;
}
void main()
{
POINT P1={15,25,5}, P2={10,30,20};
StepIn(P1);
StepOut(P2,4);
cout<<P1.X<<","<<P1.Y<<","<<P1.Z<<endl;
cout<<P2.X<<","<<P2.Y<<","<<P2.Z<<endl;
StepIn(P2,12);
cout<<P2.X<<","<<P2.Y<<","<<P2.Z<<endl;
}
Find the output of the following program :
#include<iostream.h>
#include<ctype.h>
void ChangeIt(char Text[],char c)
{
for(int K=0; Text[k]!='\0'; K++)
{
if(Text [k]>='F' && Text [K]<='L')
Text[K]=tolower (Text [K]);
else
if(Text [K]=='E' || 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";
ChangeIt(OldText,'%');
cout<<"New TEXT :"<<OldText<<endl;
}
Answer the question (i) and (ii) after going through the following class:
class Test
{
int Regno,Max,Min,Score;
public:
TEST() //Function 1
{
Regno=101; Max=100; Min=40; Score=75;
}
Test(Int Pretgno,int Pscore) //Function 2
{
Reno=Pregno; Max=100; Min=40; Score=Pscore;
}
TEST() //Function 3
{
cout<<"TEST Over"<<endl;
}
void Display() //Function 4
{
cout<<Rogno<<";"<<Max<<";" <<Min<<endl;
cout<<"[Score]"<<Score<<endl;
}
};
Write a function CHANGE() in C++, which accepts an array of integer and its size as parameters and divide all those array elements by 7 which are divisible by 7 and multiple other array elements by 3.
Sample Input Data of the array
A[0] | A[1] | A[2] | A[3] | A[4] |
21 | 12 | 35 | 42 | 18 |
Content to the array after calling CHANGE() function
A[0] | A[1] | A[2] | A[3] | A[4] |
3 | 36 | 5 | 6 | 54 |