The American University in Cairo Computer Science Department CSCI 106 Instructor: ……………. Final EXAM Last Name : ........................................................... First Name: ........................................................... Fall 2003 ID: ................................. Section No: 03 EXAMINATION INSTRUCTIONS * * * * * * * Do not turn this page until asked to do so. Exam time is 120 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 15 2 20 3 30 4 15 5 20 Total 100 1 Grade Question 1 A company wants to transmit data oer the Internet, but is concerned that its communication lines be tapped. All of the data are transmitted as four-digit integers. The company has asked you to write a program that encrypts the data so that it can be transmitted more securely. Yoyr program should read a four-digit integer and encrypt it as follows: Replace each each digit by (the sum of that digit plus 7) modulus 10. Then swap the first digit with the third, swap the second digit with the fourth and print the encrypted integer. Bonus Problem: Write a separate program that inputs an incrypted four-digit integer and decrypts it to form the original number. Question 2 Use an array to read in 20 numbers, each of which is between 10 and 100, inclusive. As each number is read, print it only if it is not a duplicate of a number already read. Provide for the “worst case” in which all 20 numbers are different. Question 3 Write a function that takes an integer value and returns the number with its digits reversed. For example, given the number 7631, the function should return 1367. Question 4 Write a function qualityPoints that inputs a student’s average and returns the letter grade ‘A’ if a student’s average is 90-100, ‘B’ if the average is 80-89, ‘C’ if the average is 70-79, ‘D’ if the average is 60-69, and ‘F’ if the average is lower than 60. Question 5 A company pays its employees as managers (who receive a fixed weekly salary), hourly workers (who receive a fixed hourly wage for up to the first 40 hours they work and “time-and-a-half” – 1.5 times their hourly wage – for overtime hours worked), commission workers (who receive LE 250 plus 5.7% of their gross weekly sales), or pieceworkers (who receive a fixed amount of money per item for each of the items they produce – each pieceworker in this company works on only one type of item). Write a modular program to compute the weekly pay for each employee. You do not know the number of employees in advance. Each type of employee has its own pay code: Managers have paycode 1, hourly workers have code 2, commission workers have code 3 and pieceworkers have code 4. Use a switch to compute each employee’s pay according to that employee’s paycode. Within the switch, prompt the user (i.e., the payroll clerk) to enter the appropriate facts your program needs to calculate each employee’s pay according to that employee’s paycode. Question 6 Write a program that takes ten integers as input. The program places the even integers into an array called evenList, the odd integers into an array called oddList, and the negative integers into an array called negativeList. The program displays the contents of the three arrays – in a tabular form – after all of the integers have been entered. 2 Question 7 Write a program fragment that uses only two nested loops (the number of loops should not exceed 2) to produce the following output: 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Question 8 Write a complete C++ program that has a main function, a GetThreeNumbers function, and a DescSort function. The main function calls the GetThreeNumbers function, which asks the user for three positive integers. Then the program sends the three integers to DescSortt, which arranges the three integers in a descending order. The main function will then print out the three sorted integers. Incorporate a loop in the main function so that the user can keep entering three integers as long as he or she desires. Your program should prompt the user how to stop the program. Question 9 An integer is divisible by 9 if the sum of its digits is divisible by 9. Write a program that prompts the user to input an integer. The program should then output the number and a message stating whether the number is divisible by 9. It does so using the given rule. 3