You are on page 1of 5

‫جامعة البلقاء التطبيقية‬

Al- Balqa Applied University


‫كلية الحصن الجامعية‬
Al-huson University College
Dept. of  Information Technology ‫قسم تكنولوجيا المعلومات‬
First Exam
computer skillsII (C++)
Name : -------------------------------------- Date : 20/3/2014
--------------- :Number : ----------------------------------- Instructor
Section#:------------------------------ A

Q1) [10 Marks] circle the correct answer for the following questions in the answer sheet:
1. The result of the following code segment is :
int w; double x;
w=2+3*5.2; x=w+5;
cout<<x<<" "<<w<<endl;
A 22.9 17.9 C 31 26
B 22 17 D None of them
2. The result of the following code segment is :
int x=4 ;
if( x=6 ) cout<<x; else cout<<++x;
A 5 C 6
B 4 D None of them
3. The result of the following code segment is :
int x = (3 ? 4 : 5);
cout<<x<<endl;
A 5 C 6
B 4 D None of them
4. The result of the following code segment is :
int x=3, a=x++;
cout<<a<<" "<<x<<endl;
A 5 6 C 3 4
B 4 4 D 4 5

5. The result of the following code segment is :


int i=5;
for(i=1;i>10;i++); cout<<i<<" ";
A 5 C 1
B 11 D None of them
6. The result of the following code segment is :
int a=0;int b=0;
a = 2 +( b= 5);
cout <<a;
A 7 C 5
B 2 D None of them
7. The result of the following code segment is :
int x=5,y=2;
if (((x-2)==y) &&(x>y)) cout<<x+y;
else
cout<<x-y;
A 7 C 5
B 3 D None of them
8. The result of the following code segment is :
char x='a';
switch (x) {
case 'a':
case 'A': cout<<"Excellent" << endl; break;
case 'b':
case 'B': cout<<"Very good"<<endl; break;
case 'c': cout<<"good"<<endl;break;
default: cout<<" Passed."<<endl; }

A Excellent C Passed
B Excellent Very good D None of them
9. The result of the following code segment is :
int c=1;
cout<<++c+c++<< endl;

A 4 C 3
B 2 D None of them
10. The result of the following code segment is :
for(int i=0;i<=5;i++){
cout<<endl;
for(int j=0;j<i;j++)
cout<<"*";}

A ***** C *
***** **
***** ***
***** ****
***** *****
B ***** D None of them
****
***
**
*

Q2) [3 marks] find the error in the following segment of C++ code and correct it.
void main(){
Const double y=0
y=3;
Y++;
if (y ≥ 4)
cout<<y<<endl;
Else
cout>>++y;}
First line: missing semicolon
Second: change constant variable;
Third line: Y is undefined
Fourth line: if (x≥4), (x>=)
Sixth line: Else :undefined variable.
Seventh line : >> insertion operator must replace by <<
Q3) [3 marks] write a program in c++ to compute the sum of the following series,
then print the result on the screen:
1+4+9+ . . . +100
#include<iostream.h>
int main ()
{
int sum=0;
for(int i=1; i<=10; i++)
sum+=i*i;
cout<<sum<<endl;
return 0;
}

Q4) [4 Marks] Rewrite the following program to use for-statement instead of while
statement.
#include <iostream>
using namespace std;
void main (){
int x,s=0;
int n=0;
cin>> x;
while(x!=-1){
s+=x;
n++;
cin>> x;
}
cout << s/n;
}

Answer q4

#include <iostream>
using namespace std;
main(){
int x,s=0;
int n=1;
cin>> x;
for(;x!=-1;){
s+=x;
n++;
cin >>x;
}
cout << s/n;
cout<<"================="<<endl;
}
Answer sheet
Answer Q1
1. a b c d
2. a b c d
3. a b c d
4. a b c d
5. a b c d
6. a b c d
7. a b c d
8. a b c d
9. a b c d
10. a b c d
Answer Q2:
First line: missing semicolon
Second: change constant variable;
Third line: Y is undefined
Fourth line: if (x≥4), (x>=)
Sixth line: Else :undefined variable.
Seventh line : >> insertion operator must replace by <<

Answer Q3:
#include<iostream.h>
int main ()
{
int sum=0;
for(int i=1; i<=10; i++)
sum+=i*i;
cout<<sum<<endl;
return 0;
}
Good luck

You might also like