0% found this document useful (0 votes)
107 views

CSI 205-Exam II

This document provides instructions for an exam on programming fundamentals. It outlines 3 problems to solve involving writing functions to: 1) return a specified digit of a number, 2) print a shape of a given height, and 3) check if one number is a power or multiple of another. Students are warned that cheating will result in a zero on the entire exam. The problems are worth varying percentages of the total grade.

Uploaded by

Georges karam
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)
107 views

CSI 205-Exam II

This document provides instructions for an exam on programming fundamentals. It outlines 3 problems to solve involving writing functions to: 1) return a specified digit of a number, 2) print a shape of a given height, and 3) check if one number is a power or multiple of another. Students are warned that cheating will result in a zero on the entire exam. The problems are worth varying percentages of the total grade.

Uploaded by

Georges karam
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/ 2

American University of Science & Technology

Faculty of Arts and Sciences

CSI 205 – Programming I


Spring 2019 - 2020
Exam II (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 4,5
Grade
[35 points] Problem 1
Write a function called getDigit() that returns the nth digit of an integer m. In the main, the user enters
the integer m and specifies also which digit in m he/she would like to print. You should then call the
function getDigit() and pass to it m and n so that it gives you back the corresponding digit. Your
function should return -1 in case the user chooses to print a digit that is outside the boundaries of the
m.

Note that the digits in m are numbered from left to right i.e. the leftmost digit is the first, the one on its
right is the second, and so on.

Example:
- If m = 2020 and n = 3 then your program should print 2 (since the rightmost 2 is the third
digit).
- If m = 2020 and n = 5 then your program should print -1 (since the value 2020 is composed of
4 digits only).
- If m = 2345012714 and n = 6 then the program prints 1 (the leftmost 1).

[35 points] Problem 2


Write a program that uses a function to print a shape of height n as shown below:

Example:
If n = 5, your program prints the following:

-*
*-*-
-*-*-*
*-*-*-*-
-*-*-*-*-

Your program should read n from the user in the main and then call the function to get the above shape.

[30 points] Problem 3


Write a program that uses two functions to check whether an integer n is a power of or a multiple of
another integer m and then prints the relation between both accordingly e.g.

- if n = 40 and m = 2 then your program prints 2*20 = 40


- If n = 27 and m = 3 then your program prints 3^3 = 27 (^ denotes power). Although power is a
special case of a multiple, yet power supersedes i.e. although 3 * 9 = 27 yet also 3^3 = 27 is
true so your program should prefer the second case over the first one.

If there is no mathematical relation between n and m, your program should print “No relation exists!”
e.g.
- If n = 20 and m = 6 then your function prints “No relation exists!”.

Read both integers from the user in the main and then call these two functions and print the result
accordingly.

Note: you may NOT use any built-in functions in this exercise.

Page 2 of 2

You might also like