CSC 101 Programming Assignment 2:
Enhancements to Making Change;
Advanced Numeric Computations
This assignment has two parts. Part A involves some enhancements to
Programming Assignment 1 from last week. Part B is a new program involving
geometric computations with real numbers.
Program Specification, Part A
Update the solution to Programming Assignment 1 as follows:
Here are some sample runs of the updated change making program:
Sample 1: Change back for a $100 dollar bill
Sample 2: Error message for negative purchase amount.
Sample 3: Error message for negative tendered amount.
Sample 4: Error message for insufficient funds.
Input the amount of the purchase, in dollars and cents: 22.16
Input the amount tendered, in dollars and cents: 100.00
Total change due = $77.84
Change in twenties through pennies is:
3 twenties
1 ten
1 five
2 dollars
3 quarters
0 dimes
1 nickel
4 pennies
Input the amount of the purchase, in dollars and cents: -5
Inputs must not be negative.
Input the amount of the purchase, in dollars and cents: 5
Input the amount tendered, in dollars and cents: -1
Inputs must not be negative.
Input the amount of the purchase, in dollars and cents: 105.00
Input the amount tendered, in dollars and cents: 100.00
The amount tendered is insufficient by $5.00.
Program Specification, Part B
Acme Storage Containers, Inc. specializes in storage containers "of all shapes and sizes". They rent the containers for use at construction sites or other locations where someone needs temporary storage. When a container is returned by the renter, it must be fumigated and repainted inside and out.
The available container shapes are rectangular, domed, and cylindrical. They are available in a range of sizes. In order to determine how much fumigant and paint to buy for a returned container, the volume and surface area of the container must be computed. Your program will perform these computations.
The program starts by inputting one character to designate the container shape: 'r' for rectangular, 'd' for domed, and 'c' for cylindrical. Following the shape input, the program inputs two real numbers that specify the base and height dimensions of a container. For a rectangular container, the base is the length of one of the square sides of its floor; for the other two shapes, the base is the diameter of its floor. For all three shapes, the height measure is how tall the container is from floor to top.
The program outputs two real numbers for the volume and paintable surface areas for the selected container shape. The output is to three decimal points of precision. The paintable surface area is the total surface area both inside and out, minus the area of the bottom (one side) of the floor. For the purposes of these computations, you may assume that the thickness of the walls is negligible, so that both the inside and outside surface areas are the same.
For calculation purposes, the dome shape is defined as a hemispheroid. It has a circular base and a variable height. Its surface area and volume are defined with quadratic hemispheroidal formulae.
Here are three sample runs, one for each shape:
Input shape of container: r Input the base and height, separated by spaces: 4 8.5 Volume: 136.000 Paintable surface area: 320.000 Input shape of container: d Input the base and height, separated by spaces: 3.25 9 Volume: 49.775 Paintable surface area: 192.079 Input shape of container: c Input the base and height, separated by spaces: 6.5 4.25 Volume: 141.028 Paintable surface area: 273.122
If the program user enters a shape character other than 'r', 'd', or 'c', then
the program outputs the error message "The shape must be r, d, or c." and
terminates immediately without performing any further computation. If the user
enters a value less than or equal to zero for one or both of the numeric
inputs, then the program outputs the error message "The base and width must be
positive values." and terminates immediately without performing any further
computation.
Develop two separate C programs, one for Part A and another for Part B. The programs must be named make_change2.c and containers.c. They must compile error free with the following gcc commands:
gcc -ansi -pedantic -Wall -Werror make_change2.c -o make_change2
gcc -ansi -pedantic -Wall -Werror containers.c -o containers
Here's a special note if you are going to use the math library, and in particular the round library function from <math.h>. To compile on unix1 you need to add a couple extra compile flags, as follows:
gcc -ansi -pedantic -Wall -Werror -lm -D_ISOC99_SOURCE make_change2.c -o make_change2
For both parts of the assignment, you must follow the following program structuring rule:
Variables may only be declared inside function bodies, not outside of functions.
For Part A of Program 1, you should start work from your solution to
Programming Assignment 1. If you did not complete Assignment 1, you can use
the instructor's solution, in the file
101/solutions/programs/1/make_change.c
You can incrementally develop make_change2.c in the following steps:
int get_amount(double change, int denomination);
For Part B of the assignment, you must develop your solution by yourself, from scratch. Be sure to include all necessary documentation, i.e., top-level description, variable comments, and in-line code algorithm comments. The following is an incremental development strategy:
As you develop, test your programs incrementally, as you add each program
feature. A detailed test plan will be posted in the Program 2 testing
directory.
The C features necessary to complete this program are covered in chapters 2 through 4 of the book. You can find the formulae for computing volume and surfaces areas for the different shapes in a math book or web site that covers computational geometry.
volume = 2/3.0 * M_PI * pow(base/2, 2) * heightThis surface formula is the curved part of the dome, without the flat circular base. To get the total surface area of the dome, you need to add in the area of the circular base. And then remember from the specification above that the paintable surface area is the total surface area both inside and out, minus the area of the bottom (one side) of the floor.
surface = 2 * M_PI * base/2 * height
NO collaboration is allowed on this assignment. Everyone must do their own
individual work.
Use the handin command on unix1 as follows:
handin gfisher 101_prog2 make_change2.c containers.c