Output Questions

Question 1

[Year 2015]

Find the output of the following program. Assume all required header files are already being included in the program.

void Position(int &C1, int C2 = 3)

{

    C1 += 2;

    C2 += 1;

}



int main()

{

    int P1 = 20, P2 = 4;

    Position(P1);

    cout << P1 << ", " << P2 << endl;

    Position(P2, P1);

    cout << P1 << ", " << P2 << endl;

} 




Question 2.

[Year 2007]

Find the output of the following program. Assume all required header files are already being included in the program.

void Withdef(int HisNum = 30)

{

    for (int I = 20; I <= HisNum; I += 5)

    cout << I << " ";

    cout << endl;

}

void Control(int &MyNum)

{

    MyNum += 10;

    Withdef(MyNum);

}

int main()

{

    int YourNum = 20;

    Control(YourNum);

    Withdef();

    cout << "Number = " << YourNum << endl;

}



Question 3.

[Year 2009]

Find the output of the following program. Assume all required header files are already being included in the program.

 

void Encode(char Info[], int N);



int main()

{

    char Memo[] = "Justnow";

    Encode(Memo, 2);

    cout << Memo << endl;

}

void Encode(char Info[], int N)

{

    for (int I = 0; Info[I] != '\0'; I++)

    if (I % 2 == 0)

        Info[I] = Info[I] - N;

    else if (islower(Info[I]))

        Info[I] = toupper(Info[I]);

    else

        Info[I] = Info[I] + N;

}





Question 4.

[Year 2010]

Find the output of the following program. Assume all required header files are already being included in the program.


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];

    }

}



int main()

{

    char oldText[] = "pOwERALone";

    ChangeIt(oldText, '%');

    cout << "New TEXT:" << oldText << endl;

}



Question 5.

[Year 2005]

Find the output of the following program. Assume all required header files are already being included in the program.

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] + 1;

        else Str[Count] = '*';

    }

}



int main()

{

    char Text[] = "CBSE Exam 2005";

    int Size = strlen(Text);

    Convert(Text, Size);

    cout << Text << endl;

    for (int C = 0, R = Size - 1; C < Size / 2; C++, R--)

    {

        char Temp = Text[C];

        Text[C] = Text[R];

        Text[R] = Temp;

    }

    cout << Text << endl;

}

Question 6.

[Year 2010]

Find the output of the following program. Assume all required header files are already being included in the program.


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;

}



int 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;

}



Question 7.

[Year 2005]

Find the output of the following program. Assume all required header files are already being included in the program.

struct MyBox

{

    int Length, Breadth, Height;

};



void Dimension(MyBox M)

{

    cout << M.Length << "x" << M.Breadth << "x";

    cout << M.Height << endl;

}

int main()

{

    MyBox B1 = {10, 15, 5}, B2, B3;

    ++B1.Height;

    Dimension(B1);

    B3 = B1;

    ++B3.Length;

    B3.Breadth++;

    Dimension(B3);

    B2 = B3;

    B2.Height += 5;

    B2.Length--;

    Dimension(B2);

}





Question 8.

[Year 2013]

Observe the following C++ code carefully and obtain the output, which will appear on the screen after execution of it. Assume all required header files are already being included in the program.




class Aroundus

{

    int Place, Humidity, Temp;

  public:

    Aroundus(int P = 2)

    {

        Place = P;

        Humidity = 60;

        Temp = 20;

    }

    void Hot (int T)

    {

        Temp += T;

    }

    void Humid(int H)

    {

        Humidity += H;

    }

    void JustSee()

    {

        cout << Place << ":" << Temp << "&" << Humidity << "%" << endl;

    }

};



int main()

{

    Aroundus A, B(5);

    A.Hot(10);

    A.JustSee();

    B.Humid(15);

    B.Hot(2);

    B.JustSee();

    A.Humid(5);

    A.JustSee();

}

Question 9.

[Year 2015]

Find the output of the following program. 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 << endl;

    }

};



int main()

{

    Calc C;

    C.Down(2);

    C.Show();

    C.Up(7);

    C.Show();

    C.Down(2);

    C.Show();

}



Question 10.

[Year 2014]

Find the output of the following program. Assume all required header files are already being included in the program.


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;

    }

};



int main()

{

    METRO M(5), T;

    M.Trip();

    T.Trip(50);

    M.StatusShow();

    M.Trip(30);

    T.StatusShow();

    M.StatusShow();

}



Question 11.

[Year 2009]

Find the output of the following program. Assume all required header files are already being included in the program.


int main()

{

    int X[] = { 10, 25, 30, 55, 110 };

    int *p = X;

    while ( *p < 110)

    {

        if ( *p % 3 != 0)

            *p = *p + 1;

        else

            *p = *p + 2;

        p++;

    }

    for (int I = 4; I >= 1; I--)

    {

        cout << X[I] << "*";

        if (I % 3 == 0)

            cout << endl;

    }

    cout << X[0] * 3 << endl;

}



Question 12.

[Year 2007]

Find the output of the following program. Assume all required header files are already being included in the program.

int main()

{

    int Array[] = { 4, 6, 10, 12 };

    int *pointer = Array;

    int I;

    for (I = 1; I <= 3; I++)

    {

        cout << *pointer << "#";

        pointer++;

    }

    cout << endl;

    for (I = 1; I <= 4; I++)

    {

        ( *pointer) *= 3;

        --pointer;

    }

    for (I = 1; I < 5; I++)

    cout << Array[I - 1] << "@";

    cout << endl;

}



Question 13.

[Year 2013]

Find the output of the following program. Assume all required header files are already being included in the program.

int main()

{

    char *String = "SHAKTI";

    int *Point, Value[] = {10,15,70,19};

    Point = Value;

    cout << *Point << String << endl;

    String++;

    Point++;

    cout << *Point << String << endl;

}



Question 14.

[Year 2011]

Find the output of the following program. Assume all required header files are already being included in the program.


int main()

{

    int Track[] = { 10, 20, 30, 40}, *Striker;

    Striker = Track;

    Track[1] += 30;

    cout << "Striker > " << *Striker << endl; 

    *Striker -= 10;

    Striker++;

    cout << "Next@" << *Striker << endl;

    Striker += 2;

    cout << "Last@" << *Striker << endl;

    cout << "Reset To " << Track[0] << endl;

}

Question 15.

[Year 2004]

What will be the output of the following program. Assume all required header files are already being included in the program.


void ChangeString(char Text[], int &Counter)

{

    char *Ptr = Text;

    int Length = strlen(Text);

    for (; Counter < Length - 2; Counter += 2, Ptr++)

    { 

        *(Ptr + Counter) = toupper( *(Ptr + Counter));

    }

}

int main()

{

    int Position = 0;

    char Message[] = "Pointers Fun";

    ChangeString(Message, Position);

    cout << Message << "@" << Position;

}
 

Question 16.

[Year 2012]

Find the output of the following program. Assume all required header files are already being included in the program.


typedef char Str80[80];



int main()

{

    char *Notes;

    Str80 Str = "vR2GooD";

    int L = 6;

    Notes = Str;

    while(L >= 3)

    {

        Str[L] = (isupper(Str[L])? tolower(Str[L]): toupper(Str[L]));

        cout << Notes << endl;

        L--;

        Notes++;

    }

}



Question 17.

[Year 2009]

Study the following program and select the possible output from it. Assume all required header files are already being included in the program.


int main()

{

    randomize();

    int Points;

    Points = 100 + random(LIMIT);

    for (int P = Points; P >= 100; P--)

        cout << P << "#";

    cout << endl;

}


(i) 103#102#101#100#
(ii) 100#101#102#103#
(iii) 100#101#102#103#104#
(iv) 104#103#102#101#100#

Question 18.

[Year 2007]

In the following C++ program what is the expected value of MyMarks from Options (i) to (iv) given below. Justify answer. Assume all required header files are already being included in the program.


int main()

{

    randomize();

    int Marks[] = { 99, 92, 94, 96, 93, 95 }, MyMarks;

    MyMarks = Marks[1 + random(2)];

    cout << MyMarks << endl;

}


(i) 99 (ii) 94
(iii) 96 (iv) None of the above

Question 19.

[Year 2011]

Go through the C++ code shown below, and find out the possible output or output from the suggested output options (i) to(iv). Also, write the least value and highest value, which can be assigned to the variable guess. Assume all required header files are already being included in the program.


int main()

{

    randomize();

    int Guess, High = 4;

    Guess = random(High) + 50;

    for (int C = Guess; C <= 55; C++)

    cout << C << "#";

}


(i) 50 # 51 # 52 # 53 # 54 # 55 #
(ii) 52 # 53 # 54 # 55 #
(iii) 53 # 54 #
(iv) 51 # 52 # 53 # 54 # 55

Question 20.

[Year 2005]

Observe the following program SCORE.CPP carefully, if the value of Num entered by the user is 5, choose the correct possible output(s) from the options from (i) to (iv), and justify your option. Assume all required header files are already being included in the program.


//program : SCORE.CPP

int main()

{

    randomize();

    int Num, Rndnum;

    cin >> Num;

    Rndnum = random(Num) + 5;

    for (int N = 1; N <= Rndnum; N++)

    cout << N << "";

}


Output Options:
(i) 1 2 3 4
(ii) 1 2
(iii) 1 2 3 4 5 6 7 8 9
(iv) 1 2 3

Question 21

[Year 2015]


Find the output of the following program. Assume all required header files are already being included in the program.


int 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

BCDEFGH

EFGH

CDEFGH

FGHI

BCDEFGH

EFGH

CDEFGH

FGHI

 

EFGH

 

FGHI

 

EFGH

 




Question 22.

[Year 2013]

Based on the following C++ code, find out the expected correct output(s) from the options (i) to (iv). Also, find out the minimum and the maximum value that can be assigned to the variable Trick used in the code at the time when value of Count is: 3. Assume all required header files are already being included in the program.

int main()

{

    char Status[][10] = {"EXCEL", "GOOD", "OK"};

    int Turn = 10, Trick;

    for(int Count = 1; Count < 4; Count++)

    {

        Trick = random(Count);

        cout << Turn – Trick << Status[Trick] << "#";

    }

}


(i) 10EXCEL#10EXCEL#8OK#
(ii) 10EXCEL#8OK#9GOOD#
(iii) 10EXCEL#9GOOD#10EXCEL#
(iv) 10EXCEL#10GOOD#8OK#

Question 23.

[Year 2010]

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. Assume all required header files are already being included in the program.


const int LOW = 15;

int 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:

Question 24.

[Year 2012]

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? Assume all required header files are already being included in the program.




int main()

{

    randomize();

    int Arr[] = {9, 6}, N;

    int Chance = random(2) + 10;

    for (int C = 0; C < 2; C++)

    {

        N = random(2);

        cout << Arr[N] + Chance << "#";

    }

}

(i) 9#6#
(ii) 19#17#
(iii) 19#16#
(iv) 20#16#