Sie sind auf Seite 1von 6

# University of Bahrain

## College of Information Technology

Department of Computer Science
Semester 2, 2013-2014
ITCS 101/ITCS 103 (Computer Programming)
Test 1 Form A
Date: 24th March 2014

Time: 3:00-4:15PM

STUDENT NAME
STUDENT ID #
SECTION #

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

WRITE ONLY ONE SOLUTION FOR EACH QUESTION

Question #

MARKS

10

10

12

TOTAL

40

Page 1 of 6

## Question 1 (10 Points)

YOU MUST SHOW your work clearly in each of the following parts

## (i) [6 Points] Convert the following numbers from/to indicated bases:

a- ( 124 )10 = (

b- ( 11011001 )2 = (

)16

)10

c- ( CB7 )16 = (

)8

## (ii) [4 Points] Perform the following arithmetic operations:

a- The binary sum of 1101011 and 110111

## b- The binary multiplication (product) of 1001101 and 110

Page 2 of 6

Question 2 (8 Points)
What is the output of the following codes?
(1) Suppose the user input is:
BSc Computer Science
Equals 132 Credits
char c;
string w1, w2;
int n;
cin>>c;
getline(cin, w1);
cin>>w2>>n;
cout << w2 << "\n" << n << endl;
cout << c << "\t" << w1;

(2)
int x=4, y=3, k=10;
cout << ( x + k/y y/k*10 ) << endl;
cout << ( ++x * 3 ) << endl;
cout << y-- << endl;
cout << x << "\t" << y << endl;

(3)
int A= 12;
float B= 1.546, C= 95.4803;
cout
cout
cout
cout
cout

<<
<<
<<
<<
<<

## fixed << showpoint;

setprecision(2)<< setfill('@');
setw(7) << B << endl;
left << setw(7) << C << endl;
A << endl;

Page 3 of 6

## Question 3 (10 Points)

In a game center, a child can play the games if the childs age is above 5 years and the
height is above 120 cm.
DRAW A FLOWCHART OF A PROGRAM that will ask the user to enter the child
age and height, then the program should print a message saying Yes, You can Play if
the child can play the game; otherwise it should print a message Sorry, you cannot
play.

Page 4 of 6

## Question 4 (12 Points)

Write a C++ program that reads from an input file called input.txt, three float
numbers, representing base (b), height (h) and length (l) of a triangular prism
respectively. The program then calculates and displays the volume of the triangular prism
formatted to two decimal points as follows:
1

## Volume of Triangular Prism = ( 2 )

SAMPLE INPUT/OUTPUT
input.txt (input file)
4.0

3.0 10.0

Screen Output
The Volume of Triangular prism
is 60.00

Page 5 of 6

Page 6 of 6