The American University in Cairo Computer Science Department CSCI 106 03 Dr KHALIL EXAM II Fall 2003 Last Name ID First Name Form I EXAMINATION INSTRUCTIONS Do not turn this page until asked to do so Exam time is 60 minutes Put the answers on the same question sheet do not use any additional papers even for scratch Write your name ID section no in the indicated places Read the exam instructions Read the honesty policy Sign the following statement HONESTY POLICY Cheating in Exams is a violation of the honesty policy of AUC Whispering talking looking at someone else s paper or copying from any source is considered cheating Any one who does any of these actions or her his answers indicates that she he did any of them will receive a punishment ranging from zero in this exam to failing the course If repeated it may lead to dismissal from AUC I have read the honesty policy and exam instructions and I am presenting this exam as entirely my effort Signature DO NOT USE THIS SECTION Question Points 1 25 2 15 3 20 4 20 5 20 Total 100 1 Grade Question 1 25 points A mail order house sells five different products whose retail prices are product 1 LE 2 98 product 2 LE 4 50 product 3 LE 9 98 product 4 LE 4 49 and product 5 LE 6 87 Draw a flow chart and write a program that reads a series of pairs of numbers as follows Product number an integer value between 1 and 5 Quantity sold an integer value between 1 and 100 The program should stop reading values when a 0 zero is entered for the product number Your program should calculate and display the total retail value approximated to the nearest hundredth decimal digit of all products sold You are requested to enforce validation on all entered values to the program Flow Chart 2 The Program 3 Question 2 15 points 1 Write a program segment in C to print out all the integers that are divisible by 5 and not divisible by 10 in the range 1 to 500 inclusive 2 Is there anything wrong with the following loop If yes what is it int x 0 do x cout setw 3 x endl while x 10 x 10 4 Question 3 20 points How many times will each of the following loops execute What is the output in each case int y 60 for int x 5 x y x 15 cout setw 3 x setw 3 y endl cout setw 5 x y int y 80 for int x 5 x y x 10 cout setw 3 x setw 3 y endl cout setw 5 x y int x 1 int y 1 while x 5 y x cout setw 3 x setw 3 y endl int x 5 y 30 do x 2 y 10 cout setw 3 x setw 3 y endl while x y cout setw 3 x setw 3 y endl 5 Question 4 20 points Show the output of the following program segment int x 10 y 6 ctr 0 cout Hi There endl endl while ctr 3 cout setw 3 x setw 3 y endl ctr y do cout I Love C endl while ctr 3 For int i 1 i 5 I for j 1 j 4 j for k 1 k 5 k cout cout endl cout endl const int n 6 int L n 3 5 5 4 9 9 bool valu true int k 0 while k n 1 valu if L k L k 1 valu false cout setw 2 k setw 2 L k endl else k if valu cout The list is OK endl string S1 S2 S int ca 0 S1 Mina S2 Naguib S S2 S1 For int i S length 7 i 0 i cout S at i endl 6 if S at i a ca 1 cout setw 4 ca endl const int ten 10 int n 846 do d n 10 cout d n ten while n 0 7 Question 5 20 points Using nested loops write a program segment that produces the following output 1 123 12345 12345 123 1 8 Good Luck 9
View Full Document
Unlocking...