You are on page 1of 2

American University of Science & Technology

Faculty of Arts and Sciences

CSI 205 – Programming I


Spring 2019 - 2020
Exam III (Online)

PLEASE BE SURE THAT YOU READ AND UNDERSTAND THE FOLLOWING


ANY FORM OF CHEATING WILL RESULT IN A ZERO ON THE WHOLE EXAM TO
ALL INVOLVED STUDENTS.

TIME ALLOWED 150 MINUTES

THREE PROBLEMS TOTAL GRADE IS 100

TOTAL NUMBER OF SHEETS INCLUDING THIS COVER IS 2

Total
Question 1 2 3
Grade
Weight 35% 35% 30% 100%
Learning Outcomes 6,7,8
Grade
[35 points] Problem 1 – Lazy Johny
Johny is a lazy accountant. His job is to keep record of the dates on which each transaction in his
company was done. Because he’s lazy, he used to write the dates as a numeric value without using
any separators (‘/’ or ‘-‘) and he used to even drop any leading zeros e.g. he used to write 1452020
instead of 14052020 to denote today’s date. Johny was attained by COVID-19 and the company he
works for has hired Jane as a temporary accountant to replace him until he recovers and asked her to
standardize all the date values Johny messed up with. They asked her to replace all the date values
with a properly formatted date value of the form dd/mm/yyyy.

Jane, however, is bad in numbers. Therefore, she turned to you in order to help her. Being a C++
guru, you decided to do this using functions (right?)

Accordingly, write a function that accepts a numeric date and prints it in the correct format. In case
your function can’t tell, print “No idea!”.

Test your function in the main 5 times.

Sample run:
Please enter a numeric date value: 14052020
The correct format is: 14/05/2020

Please enter a numeric date value: 4052020


The correct format is: 04/05/2020

Please enter a numeric date value: 452020


The correct format is: 04/05/2020

Please enter a numeric date value: 1452020


The correct format is: 14/05/2020

Please enter a numeric date value: 1012020


The correct format is: No idea! (why? Well, is it 10/01/2020 or 01/01/2020?)

[35 points] Problem 2 - Difference


Write a program that reads two integer values from the user called a and b. If a > b then swap them.
Next, fill an array of integers of size 10 from the user with values between a and b (including both).
Make sure the values entered by the user fall indeed in the range [a,b].
Using a function that checks whether a value exists in an array or not, generate in the main 10 random
values between a and b and print the ones that are not found in the array of integers that the user filled.

[30 points] Problem 3 - Mapping


Implement the following:
1. A function that fills an array of integers with random values between 0 and 100.
2. A function that checks if an integer is between 70 and 100.

Write a program that fills an array of integers using the function created in (1) (you decide upon its
size). Create another array of Booleans having the same size as the one for integers and, using the
function created in (2) fill it such that the ith element in it reflects whether the ith element in the array of
integers is between 70 and 100 or not.

Example:
If your array of integers contains the following values: 78, 64, 88, 91, 44
Then the array of Booleans should be filled with: true, false, true, true, false

Once done, print the content of both arrays.

Page 2 of 2

You might also like