اسئلة واجوبة لسنوات سابقة
  أستــاذ المــادة  هديل قاسم غني
  تـاريـخ النشــر   10/04/2017
Share |


اسئلة امتحان المودل الثاني الخاص ب While و Do-While و For

Q1/ How many times "Hi" word is printed in the below C++ program?

#include <iostream>

#include <conio.h>

voidmain( )

{

    inti = 0;

    do

    {

        cout<<"Hi"<<"\n";

          i++;

    } while(i <=4);

     cout<<"\n";

}

a) 2     b) 4       c) 5     d) 1

 

Answer: c

 

Q2/ What is the output of the following C++ Program?

 

#include <iostream>

#include <conio.h>

voidmain( )

{

    inti = 2;

    while(i < 2)

    {

        cout<<("car")<<" ";

          i++;

    }

     cout<<"\n";

}

a)car  b) Compilation error    c) car is printed infinite times   d)   Nothing

 

 

Answer: d

 

Q3/ What is the output of the following C++ Program?

#include <iostream>

#include <conio.h>

voidmain( )

{

    inti = 0;

    for( i = 2; i == 3; i++)

          cout<<("In for loop ")<<"\n";

    cout<<("After loop\n");

    cout<<"\n";

}

a)      In for loop

In for loop

After loop

   b) Nothing

   c) After loop

   d)  In for loop

     After loop

 

Answer: c

Q4/ What is the output of the following C++ Program?

#include <iostream>

#include <conio.h>

voidmain( )

{

     intsum = 1;

     for( int i = 1; i <= 3; i ++ )

          sum = sum + ( i * i );

     cout << "The sum is:" << sum;

}

 

a) Compilation error    b) the sum is:14    c) Nothing  d) the sum is:15

 

Answer: d

 

Q5/ What is the output of the following C++ Program?

#include <iostream>

#include <conio.h>

voidmain( )

{

int k = 0;

    for (k = 7; k < 3; k++)

            cout<<"Hello"<<" ";

     cout<<"\n";

}

a) Compilation error   b) hello hello hello hello c) Nothing  d) hello hello hello

 

Answer: c

 

 

Q6/ What is the output of the following C++ Program? 

#include <iostream>

#include <conio.h>

voidmain( )

{

     inti = 2;

     do

    {

          cout<<("Book");

     } while(i < 2)

cout<<"\n";

}

 

a) Book  b) Compile time error  c) Book is printed infinite times     d)  Nothing

 

Answer: a

 

Q7/ How many times "Spoon" word is printed in the below C++ program?

#include <iostream>

#include <conio.h>

voidmain( )

{

     inti = 4;

    while(i < 6)

    {

        cout<<(" Spoon")<<" ";

          i=i+2;

    }

     cout<<"\n";

}

a) 2   b) 4   c) 3   d) 1

 

Answer: d

Q8/ What is the output of the following C++ Program?

#include <iostream>

#include <conio.h>

voidmain( )

{

     inti = 0;

     do

     {

          cout << i;

          i ++;

     }

     while( i < 10 );

     cout<<"\n";

}

a) Compilation error     b) 0123456789    c) Nothing   d) 0 1 2 3 4 5 6 7 8 9

  

Answer: b