当前栏目: c/c++
查看分类

C语言代写-Best Pizza Value Assignment

For this assignment you will finish writing a program that asks for the size and price of several pizzas, and prints the pizza that is the best value. The pizza that is the best value is the one that has the lowest price per square inch.

The portion of the program that asks for user input and prints the result is already written for you. You will need to implement 3 functions in pizza.c to finish the functionality of the program.

Code Organization

There is a Makefile provided with this assignment, so you can compile the project by running make. This produces the executable best_pizza_valuewhich you can run with ./best_pizza_value.

The struct used in this assignment is pizza_details, which is defined in pizza.h like so:

struct pizza_details {

    unsigned int size;

    double price;

};

As mentioned in the last assignment dealing with money, double is in general not a great type to use for monetary values, but it will work for our purposes here.

main() builds an array of struct pizza_details instances, and passes it to best_value_pizza(). The prototype and documentation for this function are in pizza.h, you must implement the function in pizza.c.

In addition to best_value_pizza(), you must implement two helper functions: circle_area() and price_per_square_inch(). These will be very simple functions. The purpose of writing these functions is for organization. By moving these calculations into their own functions, best_value_pizza()will be less cluttered with calculation details. Your best_value_pizza() function must use price_per_square_inch() when figuring out how good of a value the pizza is, and price_per_square_inch() must use circle_area() when calculating the price per square inch.

In circle_area(), use the M_PI constant as the value of π. This is defined in math.h, which is already included for you in pizza.h. Note that M_PI is not part of the C standard, but is an extension added by GCC. This is why the Makefile for this project uses std=-gnu99 instead of std=-c99.

Note that circle_area() takes the radius of a circle as an argument, while the diameter is stored in struct pizza_details. This is because the area of a circle is typically expressed using the radius, but pizzas are usually marketed using the diameter of the pizza.

In best_pizza_value() you need to keep track of the pizza with the lowest price per square inch as you loop through the pizzas. To avoid re-calculating the price per square inch of the best pizza so far in every iteration of the loop, it is a good idea to have another variable to keep track of the price per square inch of the best pizza so far.

Submission

Push your modified pizza.c to git-keeper. All 3 of your functions will be tested. In addition to passing the tests, you will be graded on the following:

  • best_pizza_value() does not do any price per square inch calculations directly, but rather calls price_per_square_inch()
  • price_per_square_inch() does not calculate the area of the pizza directly, but rather calls circle_area()
  • Proper style

 

(以上发布均为题目,为保证客户隐私,源代码绝不外泄!!)