CMSC104, Fall 2005
Programming Project 2
Math Helper v0.1
Out: Monday, November 7, 2005
Due Date: Friday, November 18, 2005 before 11:59pm
Help with C
The Objective
This project is designed to give you practice with loops (for/while),
switch statements and characters.
The Task
The local elementary school has asked you to volunteer as a helper
in several of its classrooms. You have come to realize that the
students need the most help with math (go figure!) There are few
problems that you find yourself helping with frequently,
so you have decided to create some software that will assist you.
Your software is going to allow the user to print a multiplication
table, find the greatest common divisor of two numbers and raise
a number to a particular power.
The Details
Your software should initially present a menu to the user.
The menu should have four options. Each option will perform
a different task. The options are as follows:
- The 'M' option will print a multiplication table. You should ask
the user for the maximum multiplier/multiplicand they would like
to see in the table. Since we are only printing a table the multiplier
and the multiplicand are the same number. For example, if the user
enters 3, your table should go from 1 to 3.
1 2 3
------------
1 | 1 2 3
2 | 2 4 6
3 | 3 6 9
|
1 2 3 4
5 6 7 8
9 10 11
-----------------------------------------------------
1 | 1 2 3
4 5 6 7
8 9 10 11
2 | 2 4 6
8 10 12 14 16 18 20
22
3 | 3 6 9
12 15 18 21 24 27 30 33
4 | 4 8 12 16 20
24 28 32 36 40 44
5 | 5 10 15 20 25 30
35 40 45 50 55
6 | 6 12 18 24 30 36
42 48 54 60 66
7 | 7 14 21 28 35 42
49 56 63 70 77
8 | 8 16 24 32 40 48
56 64 72 80 88
9 | 9 18 27 36 45 54
63 72 81 90 99
10 |10 20 30 40 50 60 70 80
90 100 110
11 |11 22 33 44 55 66 77 88
99 110 121 |
this is NOT
a well formatted table |12345
-----------------
1 |1 2 3 4 5
2 |2 4 6 8 10
3 |3 6 9 12 15
4 |4 8 12 16 20
5 |5 10 15 20 25
|
----> Your code needs to use
loops to create the multiplication table. Hint: use nested for loop
(Lecture L14 slide 18)
Your table should be formatted nicely and contain the appropriate
number of dashes to make up the table heading. Your table should like nice
even if you have double or triple digit numbers.
You should also
print the numbers as the column column headings and at the
beginning of each row. Hint: See if you can just get the
basic table printed initially without the headings and numbers
for the rows. Once you have that working, then work on the
formatting.
- The 'G' option will find the greatest common divisor. You can
feel free to use the pseudocode from the "Algorithms I"
(slides 11, 12 and 13) && "Algorithms III"
(slides 10, 11 and 12) lecture to find the greatest common
divisor.
- The 'R' option will raise a number to a power.
You MAY NOT use any functions from the math library
to calculate the answer. You will receive no credit if you
do so.
Use loop structure to compute
the power.
- There should also be a Quit option on the menu. The menu should
continue to display until the users enters a 'Q' for quit. If
the user selects an incorrect menu option, you should print
an appropriate error message and present the menu again.
Sample Output
linux3[92]% gcc -ansi -Wall proj2.c
linux3[93]% ls
a.out proj2.c
linux3[94]% a.out
Welcome to Math Helper v0.1!
Your greeting goes here. It should contain a very
detailed explanation of the program.
M - Print a Multiplication Table
G - Find the Greatest Common Divisor
R - Raise a Number to a Power
Q - Quit
Enter your menu selection: M
Enter the maximum multiplier/multiplicand you would
like to see in the multiplication table: 8
Multiplication Table with a maximum multiplier/multiplicand of 8:
1 2 3 4 5 6 7 8
--------------------------------
1 | 1 2 3 4 5 6 7 8
2 | 2 4 6 8 10 12 14 16
3 | 3 6 9 12 15 18 21 24
4 | 4 8 12 16 20 24 28 32
5 | 5 10 15 20 25 30 35 40
6 | 6 12 18 24 30 36 42 48
7 | 7 14 21 28 35 42 49 56
8 | 8 16 24 32 40 48 56 64
M - Print a Multiplication Table
G - Find the Greatest Common Divisor
R - Raise a Number to a Power
Q - Quit
Enter your menu selection: M
Enter the maximum multiplier/multiplicand you would
like to see in the multiplication table: 4
Multiplication Table with a maximum multiplier/multiplicand of 4:
1 2 3 4
----------------
1 | 1 2 3 4
2 | 2 4 6 8
3 | 3 6 9 12
4 | 4 8 12 16
-------------------------------------
M - Print a Multiplication Table
G - Find the Greatest Common Divisor
R - Raise a Number to a Power
Q - Quit
Enter your menu selection: G
Enter the first integer: 35
Enter the second integer: 20
The greatest common divisor of 35 and 20 is 5.
-------------------------------------
M - Print a Multiplication Table
G - Find the Greatest Common Divisor
R - Raise a Number to a Power
Q - Quit
Enter your menu selection: G
Enter the first integer: 31
Enter the second integer: 19
The greatest common divisor of 31 and 19 is 1.
-------------------------------------
M - Print a Multiplication Table
G - Find the Greatest Common Divisor
R - Raise a Number to a Power
Q - Quit
Enter your menu selection: R
Enter the base number: 4
Enter the power: 2
4 raised to the power 2 is 16.
-------------------------------------
M - Print a Multiplication Table
G - Find the Greatest Common Divisor
R - Raise a Number to a Power
Q - Quit
Enter your menu selection: R
Enter the base number: 5
Enter the power: 3
5 raised to the power 3 is 125.
-------------------------------------
M - Print a Multiplication Table
G - Find the Greatest Common Divisor
R - Raise a Number to a Power
Q - Quit
Enter your menu selection: T
T is not a valid menu choice.
-------------------------------------
M - Print a Multiplication Table
G - Find the Greatest Common Divisor
R - Raise a Number to a Power
Q - Quit
Enter your menu selection: Y
Y is not a valid menu choice.
-------------------------------------
M - Print a Multiplication Table
G - Find the Greatest Common Divisor
R - Raise a Number to a Power
Q - Quit
Enter your menu selection: Q
Thank you for using Math Helper v0.1.
linux3[95]%
Submitting the Program
YOUR
PROGRAM MUST COMPILE ON - gl.umbc.edu
Note:
Correct execution of the program is 20 points of the project grade.
Style is 20 points.
Correctness is 40 points. Documentation is 20 points.
Your program should be in a file called
proj2.c and comply with one of the
Indentation Styles and
C Coding Standards.
Also see
sample grade form from a previous semester.
Here is a sample submission command. Note that the project name starts
with uppercase 'P'.
submit cs104_0301 Proj2 proj2.c
To verify that your project was submitted, you can execute the
following command at the Unix prompt. It will show the file that
you submitted in a format similar to the Unix 'ls' command.
submitls cs104_0301 Proj2
|