CMSC 201
Programming Project One
M & B Concrete
Out: Wednesday 9/26/01
Due: Before Midnight, Wednesday 10/3/01
|
The Objective
The objective of this assignment is to get you started writing programs
in C in a UNIX environment. Its main emphasis is design, so we will be
designing the project together in class. You should keep in mind all of the
design techniques that we've covered in class, including top-down design,
writing functions that do only one thing, writing functions to be general, and
using symbolic constants instead of having "magic numbers" within your code.
This project will also give you practice writing functions, loops, and a
switch statement.
The Background
M & B Concrete is a small home improvement company that specializes in
building concrete sidewalks, driveways and patios. The owner of the company
has hired you to write a program that he can use to find the cost of the
cement and its delivery for each project. This will help him in the bidding
process for all of his jobs.
Concrete is delivered by a mixer truck and is purchased by the "yard". When
speaking about concrete, the phrase "a yard of concrete" actually means one
cubic yard of concrete. The current price of concrete is $ 3.50 per yard.
If the order is small, then there is a delivery charge of $ 50.00. Orders of
25 or more yards of concrete have free delivery.
M & B uses standard thicknesses for each of their products. Sidewalks are
always 4 inches thick, driveways are 6 inches thick, and patios are 6 inches
thick.
After printing a greeting for the user, we should present the user with
a menu of pricing choices.
The choices available to the user are :
- Price a Sidewalk
- Price a Driveway
- Price a Patio
- Quit
After that item has been priced, the menu should be presented again so that
the user can continue to price other projects.
The Task
Design (to be done in class) and code a project that after printing a greeting
to the user, presents the user with a menu which allows him to choose to
price a sidewalk, a driveway or a patio.
The user's choice will determine which thickness to use in the calculations
of the volume of cement necessary. After getting the menu choice, the user
should be prompted for both the length and the width of the item. These
dimensions are to be given in feet and inches.
Rules about Dimensions:
- Dimensions are always given in feet and inches. The feet are always
given as whole numbers, but there may be fractions of an inch.
Example: A dimension of 4 feet 6.75 inches is acceptable.
- You may never allow the user to have a dimension of 0 or less.
Once the dimensions are obtained, the program needs to calculate the number
of yards of cement that need to be ordered and present the user with that
number, the cost per yard, whether or not there was a delivery charge and the
amount of that charge, and the total cost of the cement (including delivery).
After accomplishing the requsted task, the user should be presented with the
menu again, so that s/he can continue to make choices.
The program should not terminate until the user has chosen quit from the
menu.
Sample Run
linux3[72] % gcc -Wall -ansi proj1.c
linux3[73] % a.out
Your greeting goes here
1 - Price a Sidewalk
2 - Price a Driveway
3 - Price a Patio
4 - Quit
Enter your choice : 1
Pricing your sidewalk :
Please enter the length in feet and inches
feet : 27
inches : 0
Please enter the width in feet and inches
feet : 3
inches : 0
Your project requires 1 yard(s) of concrete at $ 3.50 per yard
The delivery charge is $ 50.00
Total cost : $ 53.50 plus tax
1 - Price a Sidewalk
2 - Price a Driveway
3 - Price a Patio
4 - Quit
Enter your choice : 1
Pricing your sidewalk :
Please enter the length in feet and inches
feet : 27
inches : 0
Please enter the width in feet and inches
feet : 3
inches : 1.5
Your project requires 2 yard(s) of concrete at $ 3.50 per yard
The delivery charge is $ 50.00
Total cost : $ 57.00 plus tax
1 - Price a Sidewalk
2 - Price a Driveway
3 - Price a Patio
4 - Quit
Enter your choice : 2
Pricing your driveway :
Please enter the length in feet and inches
feet : 100
inches : 0
Please enter the width in feet and inches
feet : 20
inches : 0
Your project requires 38 yard(s) of concrete at $ 3.50 per yard
There is no delivery charge for an order this large.
Total cost : $ 133.00 plus tax
1 - Price a Sidewalk
2 - Price a Driveway
3 - Price a Patio
4 - Quit
Enter your choice : 3
Pricing your patio :
Please enter the length in feet and inches
feet : 25
inches : 9
Please enter the width in feet and inches
feet : 15
inches : 3
Your project requires 8 yard(s) of concrete at $ 3.50 per yard
The delivery charge is $ 50.00
Total cost : $ 78.00 plus tax
1 - Price a Sidewalk
2 - Price a Driveway
3 - Price a Patio
4 - Quit
Enter your choice : 0
0 is not a valid choice
Enter your choice : 5
5 is not a valid choice
Enter your choice : 2
Pricing your driveway :
Please enter the length in feet and inches
feet : 0
inches : 0
A dimension of 0 is not allowed.
Try again
feet : -2
Dimensions must be positive !
Try Again
feet : 15
inches : -5
Dimensions must be positive !
Try Again
inches : 0
Please enter the width in feet and inches
feet : 0
inches : 0
A dimension of 0 is not allowed.
Try again
feet : -7
Dimensions must be positive !
Try Again
feet : -1
Dimensions must be positive !
Try Again
feet : 10
inches : -3
Dimensions must be positive !
Try Again
inches : 3.5
Your project requires 3 yard(s) of concrete at $ 3.50 per yard
The delivery charge is $ 50.00
Total cost : $ 60.50 plus tax
1 - Price a Sidewalk
2 - Price a Driveway
3 - Price a Patio
4 - Quit
Enter your choice : 4
linux3[74]
Although your output need not be identical to the above,
all information (including the greeting) must be present.
Please be aware that this is definitely NOT a complete
test of the program. Your testing should be much more extensive.
Input Guarantees
- Graders will use only numeric input.
- Graders will enter only integers as menu choices.
- Graders will enter only integers as the number of feet for
any dimension.
Further Specifications
- Do NOT use separate compilation for this project. You should
have one single source code file named proj1.c
- Since we are designing this project together in class, you MUST
use the following constants and the following function prototypes.
You may not alter them in any way.
#define WALK 1 /*Menu choice for pricing a sidewalk */
#define DRIVE 2 /*Menu choice for pricing a driveway */
#define PATIO 3 /*Menu choice for pricing a patio */
#define QUIT 4 /*Menu choice for quitting the program */
#define MIN_RESPONSE 1 /*Minimum menu choice possible */
#define MAX_RESPONSE 4 /*Maximum menu choice possible */
#define WALK_THK 4 /*Std. thickness (in.) of a sidewalk */
#define DRIVE_THK 6 /*Std. thickness (in.) of a driveway */
#define PATIO_THK 6 /*Std. thickness (in.) of a patio */
#define CUFT_PER_CUYD 27.0 /*Conversion factor: 27 cuft/cuyd */
#define IN_PER_FT 12.0 /*Conversion factor: 12 inches/foot */
#define PRICE_PER_YARD 3.50 /*Current cost of cu. yard of concrete */
#define DELIVERY 50.00 /*Current delivery charge */
#define MIN_YARDS 25 /*Minimum # of cubic yards necessary */
/*to waive the delivery charge */
void PrintGreeting (void);
void PrintMenu (void);
int GetMenuResponse (int min, int max);
float GetDimension (void);
float ConvertInchesToFeet (float inches);
int FindWholeYards (float length, float width, float thickness);
float FindCubicFeet (float length, float width, float thickness);
float FindCubicYards (float cubicFeet);
float FindCost (int yards, float pricePerYard, int minYards,
float delivery);
int HasDeliveryCharge (int yards, int minYards);
void PrintResults (float cost, int yards, float pricePerYard,
int minYards, float deliveryCharge);
Submitting the Program
Your C source code file MUST be called proj1.c.
To submit your project, type the following at the Unix prompt.
Note that the project name starts with uppercase 'P'.
submit cs201 Proj1 proj1.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 cs201 Proj1