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

Test II Sample 2

This document contains instructions and questions for a computer programming test. It includes 4 multiple choice questions testing concepts like output from code snippets, writing a program to calculate net price based on user input, writing a program to analyze store inventory from user input, and writing a program to read from a file and output details. The test is out of 40 total marks and includes instructions to write clearly and only consider one solution per question.

Uploaded by

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

Test II Sample 2

This document contains instructions and questions for a computer programming test. It includes 4 multiple choice questions testing concepts like output from code snippets, writing a program to calculate net price based on user input, writing a program to analyze store inventory from user input, and writing a program to read from a file and output details. The test is out of 40 total marks and includes instructions to write clearly and only consider one solution per question.

Uploaded by

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

University of Bahrain

College of Information Technology SERIAL


Department of Computer Science
Second Semester, 2014-2015
Computer Programming for Scientists and Engineers

CSC 103
TEST II

Date: 13th May 2015 Time: 11:00 - 12:15

STUDENT NAME

STUDENT ID # 2 0 SECTION #

QUESTION # MARKS COMMENTS

1 10

2 10

3 10

4 10

TOTAL 40

NOTE: THERE ARE SIX (6) PAGES IN THIS TEST


ONLY ONE SOLUTION WILL BE CONSIDERED FOR EACH QUESTION
WRITE YOUR ANSWERS CLEARLY
LAST PAGE IS EMPTY

Page 1 of 6
Question 1 ( 10 marks )
Show the output of each code in the corresponding box to the right.

(1) int a =1 , b=2 , c= 1;


int s = b*b-4*a*c ;
if ( s == 0 && a==1 )
cout<<"Factored"<<endl;
else
cout<<"Imaginary"<<endl;
cout<<"Coefficient= " << s << endl;

(2) int y = 5, x = 49;


cout <<"X="<< x / 7 << endl;
switch (x / 7)
{
case 1: y++;
case 2:
case 3: y = y + 2;
break;
case 5:
case 7: y = y % 3;
}
cout <<"Y="<< y << endl;

(3) int Sp = 100;


while ( Sp <= 101 ) {
cout<<"Speed = "<< Sp << endl;
Sp++;
}
cout<<"Fast & Furious";

(4) int p, m;
for (p=1 ; p <= 3 ; p++)
{
for (m=9 ; m > 8 ; m--)
cout << "[" << m-p <<"]"<< endl;
}

Page 2 of 6
Question 2 ( 10 marks )

Write a C++ program to calculate and display the net price of pasta
based on two user inputs: Type (C for chicken, M for Meat, or V for
Vegetable) and the number of appetizers. The net price of pasta is
the sum of the following:

1. Base price of the pasta is 2.5 BD for chicken, 2.5 BD for Meat,
and 2.1 for Vegetable.
2. Each appetizer is an additional 1.2 BD.

SAMPLE INPUT/OUTPUT
Enter pasta type: C for Chicken, M for Meat, V for Vegetable
C
Enter number of appetizers:
2
Net price = 4.9

Page 3 of 6
Question 3 ( 10 marks )
A supply chain is performing end of the year store inventory. Write a C++ program that asks
the user to enter the Type (D for Deskjet, L for Laser) and price for 120 printers. The
program then displays how many Deskjet printers, how many Laser printers and how many
other printers.

Page 4 of 6
Question 4 ( 10 marks )
Assume that we have a file called savings.txt with unknown number of lines. Each line
contains the client name and his/her saving money in the bank. Below is a sample file.
Write a C++ program that reads all the lines from the file and prints on screen on separate
lines the client name and the saved money. The program should also display the total saving
money in the bank and the name of the customer who has the highest saving money.

savings.txt Sample Output


Ahmed 1500 Customer name saving money
Mohamed 600 Ahmed 1500
Ali 3000 Mohamed 600
Ali 3000

Total saving amount =5100


Ali has the highest saving money 3000

Page 5 of 6
Page 6 of 6

You might also like