Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

CPSC 1620 - Fundamentals of Programming I

Spring 2024
Assignment # 8
Total Marks: 115
Due: Thursday, March 21, 2024 @ 11:55 PM

Instructions:
1. Assignment answers/files must be submitted using the prescribed Moodle
submission link.
2. You must use the package provided in the model.
3. Don’t change the name of the .cc file.
4. Don’t change the Makefile definition/description.
5. Your assignment will be marked on program correctness and readability (including
comments).
6. Submitted work must work/run in the UofL lab environment.
7. You must submit your own work; if the work is not original or found in
collaboration, necessary steps will be taken based on UofL policy.

Write a program that uses a random number generator to generate a two-digit positive
integer and allows the user to perform one or more of the following operations:

a) Double the number.


b) Reverse the digits of the number.
c) Raise the number to the power of 2, 3, or 4.
d) Sum the digits of the number.
e) If the number is a two-digit number, then raise the first digit to the power of the
second digit.
f) If the number is a three-digit number and the last digit is less than or equal to 4,
then raise the first two digits to the power of the last digit.

After performing an operation if the number is less than 10, add 10 to the number. Also,
after each operation determine if the number is prime.

Each successive operation should be performed on the number generated by the last
operation. Your program should not contain any global variables and each of these
operations must be implemented by a separate function. Also, your program should be
menu driven.

PAGE # 1
Sample Input/Outputs:

The two digit number is: 89


1: Enter 1 to double the number.
2: Enter 2 to reverse the digits of the number.
3: Enter 3 to raise the number to the power of 2, 3, or 4.
4: Enter 4 to Sum the digits of the number.
5: Enter 5 to raise the first digit to the power of the second digit.
6: Enter 6 to raise the first two digits the power of the last digit.
9: Enter 9 to terminate the program.
1

178 is not prime.


1: Enter 1 to double the number.
2: Enter 2 to reverse the digits of the number.
3: Enter 3 to raise the number to the power of 2, 3, or 4.
4: Enter 4 to Sum the digits of the number.
5: Enter 5 to raise the first digit to the power of the second digit.
6: Enter 6 to raise the first two digits the power of the last digit.
9: Enter 9 to terminate the program.
3

Enter power (2, 3, or 4): 3

5639752 is not prime.


1: Enter 1 to double the number.
2: Enter 2 to reverse the digits of the number.
3: Enter 3 to raise the number to the power of 2, 3, or 4.
4: Enter 4 to Sum the digits of the number.
5: Enter 5 to raise the first digit to the power of the second digit.
6: Enter 6 to raise the first two digits the power of the last digit.
9: Enter 9 to terminate the program.
4

37 is prime.
1: Enter 1 to double the number.
2: Enter 2 to reverse the digits of the number.
3: Enter 3 to raise the number to the power of 2, 3, or 4.
4: Enter 4 to Sum the digits of the number.
5: Enter 5 to raise the first digit to the power of the second digit.
6: Enter 6 to raise the first two digits the power of the last digit.
9: Enter 9 to terminate the program.
9

PAGE # 2
Executing the code:

➢ It needs to compile with Makefile


➢ To create the executable file, the command will be→ make compileAll
➢ To run the executable file command will be→ ./assignment8

Deliverables checklist

➢ Completed ‘assignment8.cc’ file.


➢ Makefile (no change).

PAGE # 3

You might also like