0% found this document useful (0 votes)
9 views6 pages

Midterm Exam - Solution

This document is a mid-term exam for a Programming for Engineers course, scheduled for June 26, 2014. It includes instructions, a marking scheme, and various programming problems related to C++ concepts, such as syntax errors, algorithm design, and program output. Students are required to answer all questions under closed book conditions.

Uploaded by

dr.khawlla-
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views6 pages

Midterm Exam - Solution

This document is a mid-term exam for a Programming for Engineers course, scheduled for June 26, 2014. It includes instructions, a marking scheme, and various programming problems related to C++ concepts, such as syntax errors, algorithm design, and program output. Students are required to answer all questions under closed book conditions.

Uploaded by

dr.khawlla-
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

College of Sciences

Department of Computer Science


Programming for Engineers (1411113)
Mid-Term Exam, Summer 2013/2014
DATE: Thursday June 26, 2014; TIME: 8:30 - 9:30

Student Name: ___________________________________ ID#: _______________________


Please circle the name of your instructor:

Mahir Abdullah

INSTRUCTIONS:
 Closed Books, Closed Notes,
 No Calculators, No E-Dictionaries, No Mobiles.
 Answer ALL the questions in each section.

Marking Scheme:
Weight Score

10 Part I

15 Part II

25 Total

Outcomes:

Outcome Weight Questions Score

Analyze simple problems, design algorithms and write them in pseudo-


C. 3 Part I.2
code or flowcharts.

D. Develop, test, and debug computer programs. 3 Part I.3

4 Part I.1
Apply the concepts of variables, data types, input, output, expressions,
E. 8 Part II.1
assignment, the processes of decision-making and repetition.
7 Part II.2

Part I [10 Marks]


1
1. [4 Marks] Indicate whether each of the following statements is True or False:
TRUE/FALSE Statement
F In C++, the value of the expression 32/5 is 6.4. 1
The explicit conversion of a value from one data type to another is called type 2
T
casting.
F Multiple line comments are enclosed between // and //. 3
T In C++, ! and != are different operators. 4
Suppose P and Q are logical expressions. The expression P || Q is false if either 5
F
P is false or Q is false.
The following expressions are equivalents: 6
F

The expression (x >= 0 && x <= 100) evaluates to false if either x < 0 or x >= 7
F
100.
T In a switch statement, the default is optional.. 8

2. [3 Marks] Correct the three syntax errors in the following program:

# include <iostream>

using namespace std;

int main( )
{
int amount;
float bill;

cin >> amount;

if amount < 1000


bill = 7.5 + 0.03*amount;
else
bill = 57.5 + 0.015 (amount - 2000);

cout >> bill;

return 0;
}
3. [3 Marks] Trace the following program and write its output:

2
#include <iostream>
Output
using namespace std;
616 int main( )
{
319 int i = 1, a = 6, b = 4, c = 3;
616 while( i <= 3 )
{
if (a > b){
b = 5 + a;
c = a - 1;
cout << a;
}
else{
b -= 8;
cout << b;
}
c = c + b;
cout << c << endl;
i++;
}
return 0;
}

Part II [15 Marks]

1. [8 Marks] Miles per Gallon: Drivers are concerned with the mileage obtained by their cars. A
driver likes to know the number of miles driven and the number of gallons used. If the average

3
miles per gallon is more than 20 the car is economical, otherwise it is not economical. Write a
program that prompts the user to enter the number of gallons used and the number of driven miles.
The program calculates and prints the average miles per gallon and also prints a message that the car
is economical or not economical.

Sample input / output:

2. [7 Marks] Number Divisors: Write a program that prompts the user to enter a positive integer N.
The program reads N positive integers and finds the product of the even integers and the sum of the
odd integers.

Sample input / output:

#include <iostream>

using namespace std;

4
int main( )
{
float gallons, miles, average;

cout << "Enter the gallons used: ";


cin >> gallons;

cout << "Enter the miles driven: ";


cin >> miles;

average = miles / gallons;

cout << "The miles / gallon is: " << average << endl;

if(average > 20)


cout << "The car is economical" << endl;
else
cout << "The car is not economical" << endl;

return 0;
}

#include <iostream>

using namespace std;

int main( )
5
{
int N, num, even=1, odd=0, k=0;

cout << "Enter how many integers (N): ";


cin >> N;

while(k<N)
{
cout << "Enter a positive integer: ";
cin >> num;
if(num % 2 == 0)
even = even * num;
else
odd = odd + num;
k++;
}

cout << "The product of the even integers is " << even << endl;
cout << "The sum of the odd integers is " << odd << endl;

return 0;
}

You might also like