Code:
#include <stdio.h>
#define QUIT 6
#define TAX_RATE 0.065
void printmenu();
double itemShipping(double price, double weight, int quantity, int tax);
double weightChange(int minWalk, int minStand, int minDrink, int minEat);
void rollerCoaster(int trackLength, int maxTrainLength, int* pMaxPeople, int* pNumCars);
void printHeartDesign(int size, int ch);
void ucfidol(FILE* ifp);
int main ()
{
int ans;
//display menu and read the user's choice
printf("\n");
printmenu();
scanf("%d", &ans);
//continue until the user quits
while (ans != QUIT) {
//execute user's choice
if (ans == 1){
double price, weight;
int quantity, tax;
printf("What is the cost of the item to be purchased (in dollars)?\n");
scanf ("%lf", &price);
printf("What is the weight of the item (in pounds)?\n");
scanf ("%lf", &weight);
printf("How many of the item are you purchasing?\n");
scanf ("%d", &quantity);
printf("Is the item a taxed item? (1=yes, 0=no)\n");
scanf ("%d", &tax);
//calculate result and print
itemShipping (price, weight, quantity, tax);
printf("Your total purchase, with shipping, will cost $%.2lf.\n", itemShipping);
}
else if (ans == 2)
printf("%d", ans);
//weightChange ();
else if (ans == 3)
printf("%d", ans);
//rollerCoaster ();
else if (ans == 4)
printf("%d", ans);
//printHeartDesign ();
else if (ans == 5)
printf("%d", ans);
//ucfidol (FILE* ifp);
else if (ans != 6)
printf("This is an invalid choice. Please try again.\n");
//read the user's next choice
printf("\n");
printmenu();
scanf("%d", &ans);
}
// system("PAUSE");
return 0;
}
/* Pre-condition: None
Post-condition: Prints the menu.
*/
void printmenu() {
printf("Which of the following options would you like?\n");
printf("1) Gift Shop Shipping\n");
printf("2) Calorie Counter Application\n");
printf("3) Roller Coaster Design\n");
printf("4) Printing a Heart T-shirt\n");
printf("5) UCF Idol\n");
printf("6) Quit\n");
}
/*
Pre-condition: price, weight: a positive real numbers less than 100.
quantity: a positive integer less than 100.
tax: 0(if not taxed), 1(if taxed)
Post-condition: Given the four pieces of information as specified in
Program 2A, this function returns the total cost of
the corresponding order with shipping included.
*/
double itemShipping(double price, double weight, int quantity, int tax);
double order_weight, ship;
//calculate order weight
order_weight = weight * (double)quantity;
//determine shipping cost per pound
ship = 4;
if (order_weight >= 10)
ship = 2.5;
if (order_weight >= 30)
ship = 1.5;
if (order_weight >= 50 )
ship = .99;
//calculate price before tax
double sub_total = (order_weight * ship) + (price * quantity);
//calculate total price of order
double total_cost = sub_total * (1 + tax * TAX_RATE);
return total_cost;
/*
Pre-conditions: All four parameters are non-negative integers less
than 720.
Post-conditions: Returns the weight change (in pounds) of the person
who walked, stood, drank and ate for the number of
minutes designated, using the calculation from
Program 2B.
*/
double weightChange(int minWalk, int minStand, int minDrink, int minEat);
/*
Pre-condition: trackLength is positive and less than 10000.
maxTrainLength is in between 10 and 100, inclusive.
pMaxPeople points to a variable that will store the
maximum number of people for this train design.
pNumCars points to a variable that will store the
number of cars per train in the ideal design as
specified in Program 2C.
Post-condition: The variables pointed to by pMaxPeople and pNumCars
will store the maximum number of people and the number
of cars per train for this design, respectively.
*/
void rollerCoaster(int trackLength, int maxTrainLength, int* pMaxPeople, int* pNumCars);
/*
Pre-condition: size is in between 3 and 10 inclusive.
Post-condition:A heart with the given size will be printed, as
defined in Program 3B with the character ch.
*/
void printHeartDesign(int size, int ch);
/*
Pre-condition: ifp points to the beginning of a file that stores data
about UCF Idol shows, as specified in Program 4.
Post-condition: The results of all the shows in the file will be
printed to the screen and FILE pointed to by ifp will
be closed.
*/
void ucfidol(FILE* ifp);