You are on page 1of 7

WOLITA SODO UNIVERSITY

COLLEGE OF ENGINNERING
DEPARTEMENT OF ELECTRICAL AND COMPUTER ENGINNERING
COURSE TITLE: INTRODUCTION TO COMPUTER PROGRAMMING

COURSE CODE: MEng1052 TIME ALLOWED: 2:30 hrs.

NAME: _____________________________________ID NO: ________________SECTION

BASIC INSTRUCTIONS:

1. WRITE YOUR NAME AND ID.NO IN ABOVE PROVIDED SPACE


2. WRITE YOUR ANSWER ONLY ON THE ANSWER SHEET
3. CHEATING AND SIDE TALKS ARE STRICTLY FORBIDDEN
4. USING CALCULATOR IS NOT ALLOWED
5. USING ANY EXTRA PAPER IS NOT ALLOWED
6. CHECK THAT THERE IS FOUR PARTS

FOR INSTRUCTOR USE ONLY:

Parts Questions Mark Gained Mark


10 0.5 pt
I. Choose 5
each
II. OUT PUT 3 4 pt each 12
2 5.5 pt
III. Error Check 11
each
IV. WAP 2 6 pt each 12
40%
TOTAL 17

Monday, Jan 27, 2019 Good Luck!!!

COMPUTER PROGRAMMING ECEG 2101 FINAL - EXAM (40%)


Part I: Choose the best Answer. (5 %)

1. All of the following is wrong syntax except one?


A. for(exp1: exp2: exp3)
{
Statements;
}
B. for(exp1; exp2; exp3)
{
Statements;
}
C. for(exp1; exp2; exp3);
{
Statements;
}
D. for(exp1, exp2, exp3)
{
Statements;
}

2). which one of the following statement terminates the switch, and flow of control
jumps to the next line following the switch statement?

A. default B. break C. goto D. continue

3). If k=10; which of the following is false about the function y and the literal constant k?

A. y=++k; (y=11,k=11) B. y=k++; (y=10,k=11)

C. y=k--; (y=10, k=9) D. y= --k; (y=10, k=9)

4). which of the typical development cycle of C++ is comes first?

A. Linking the program B. Running the program

C. Compiling the source code D. Monitoring the program

5). which of the following is valid.

A. cout>>’’hello’’;
B. double height, weight = 62.0, width;
C. double π = 3.14;
D. int 23birr;

6). All are parameters used in for loop except


A. Initialization B. Condition C. Increment D. Decrement E. All F. None

COMPUTER PROGRAMMING ECEG 2101 FINAL - EXAM (40%)


7). Two or more functions having same name but different argument is called
A. function overloading B. function prototype
C. return statement D. default arguments

8). The output of

#include <iostream>
using namespace std;
int main ()
{
int a = 5;
int b = 10;
cout <<( (a>b)?a:b);
return 0;
}

A. 5
B. 10
C. Syntax error
D. None of above

9). which of the following functions will correctly return true if its argument x is an odd integer?

I. bool IsOdd (int x) {


return (x % 2 == 1);
}
A. II only
II. bool IsOdd (int x) {
B. I and II only
return (x / 2 == 1);
} C. I and III only

III. bool IsOdd (int x) { D. II and III only


if (x % 2 == 1) E. I, II and III
return true;
else
return false;
}

COMPUTER PROGRAMMING ECEG 2101 FINAL - EXAM (40%)


Look the following code for the question “10”
int c[12]={-45,6,0,72,15,-89,0,62,-31,6478};
cout<<c[1]+c[2]+c[3]<<endl;
10).What is the output of the above code?
A.3 B.-39 C. 78 D.0

Part II: write output of the following questions (12%)

Q1 OUTPUT
#include <iostream>
using namespace std;
int main()
{
int i=1,s = 0;
while (i<= 11)
{
s += i;
cout<<i<<" "<<s<<endl;
if(i==4)
break;
i++;
}
cout << "S = " << s<<endl;
cout << "i after loop = " <<i;
return 0;
}

COMPUTER PROGRAMMING ECEG 2101 FINAL - EXAM (40%)


Q2 OUTPUT
#include<iostream>
using namespace std;
int main()
{
char op='+';
int result,operand1=4,operand2=5;
switch(op)
{
case('-'):result=operand1-operand2;
cout<<result<<endl;
break;
case('+'):result=operand1+operand2;
cout<<result<<endl;
case('/'):result=operand1/operand2;
cout<<result<<endl;
case('*'):result=operand1*operand2;
cout<<result<<endl;
break;
}
return 0;
}

Q3 OUTPUT

#include<iostream>
using namespace std;
int main()
{
int x=5,y=7,z;
z=x;
cout<<x<<y<<z<<endl;
cout<<++x+y<<endl;
z=x++;
cout<<x<<","<<z<<endl;
z=y++;
cout<<(x-y+z)<<endl;
cout<<”end\n”<<x<<endl<<y<<endl<<z;
return 0;
}

COMPUTER PROGRAMMING ECEG 2101 FINAL - EXAM (40%)


Part III: The following programs have compiler error. Correct the error and rewrite the
program. (11%)

Q1 OUTPUT
#include< >
using namespace std;
double daverage(int x1, int x2)
{
av=(x1+x2)/2;
RETURN av;
}
int main()
{
double n1, n2;
cout>>”enter two numbers\n”>>;
cin>>n1;n2;
davrg= daverage(n1,n2);
cout<<davrg<<endl;
}

COMPUTER PROGRAMMING ECEG 2101 FINAL - EXAM (40%)


Q2 OUTPUT

include<iostream>
using namespace std;
int main[]
{
integer sum
for[i=0; i<=100 i++];
{
sum =sum+i
}
cout>>sum
return 0;

Part Iv: Write a C++ program for the following questions. (12%)

Q1. That displays the ff.

Q2. Write a program that takes ten integer numbers from the user; calculates and display the sum and
average of those numbers (hint: use an array)

COMPUTER PROGRAMMING ECEG 2101 FINAL - EXAM (40%)

You might also like