Question

In: Computer Science

Outside of main declare two constant variables: an integer for number of days in the week...

Outside of main declare two constant variables: an integer for number of days in the week and a double for the revenue per pizza (which is $8.50). Create the function prototypes.

Create main

Inside main:

  1. Declare an integer array that can hold the number of pizzas purchased each day for one week.
  2. Declare two additional variables one to hold the total sum of pizzas sold in a week and one to hold the average pizzas sold per day
  3. Using an appropriate loop, ask the user to enter in the number of pizza for each day
    1. The program must test the entry value.
    2. If the number entered is negative, the program must display an error message and allow for the reentry of the value for that day. The program will continue to ask for a valid response until a valid response is entered.
    3. If the number is valid (greater than or equal to zero), the program will then prompt for the next value until the loop ends.
    4. Extra Credit will be given if the validation test is done via a function call.
  4. Send the array to a function that displays a title for the report as well as the number of pizzas sold for each day.
  5. Send the array to a function that calculates the sum total of pizzas sold for the week; the function returns the sum total back to main().
  6. Send the array to a function that calculates the average number of pizzas sold for the week; the function returns the average back to main().
  7. Display the following:
    1. The total number of pizzas sold for the week
    2. The average number of pizzas sold per day
    3. The total revenue from the pizza sold for the week
    4. The average revenue per day
  8. Display a thank you/goodbye message.
  9. Comment your code.

Submit the .cpp file and a screen shot in Canvas

Screen Shots:

please write the code for c++

Solutions

Expert Solution

CODE SCREENSHOTS:

OUTPUT SCREENSHOT:

CODE:

#include <bits/stdc++.h>
using namespace std;

const int days = 7;          // days in the week
const double revenue = 8.50; // revenue per pizza

bool check(int temp) // checks if the entered value is positive
{
    return (temp >= 0); // returns true for positive
}

void display(int a[]) // for the report display
{
    cout << endl
         << endl
         << "PIZZA REPORT\n\n";
    for (int i = 0; i < days; i++)
    {
        cout << "Day " << i + 1 << ": " << a[i] << " pizza(s) sold\n"; // pizzas sold each day
    }
}

int calcSum(int a[]) // calculate total sum
{
    int sum = 0;
    for (int i = 0; i < days; i++)
        sum += a[i];

    return sum;
}

int calcAvg(int a[]) // calculate avg pizzas sold in a day
{
    int sum = calcSum(a);
    return sum / days; // returns int cause pizza is a whole
}

double calcTotalRevenue(int a[]) // calculate total revenue
{
    double sum = 0;
    for (int i = 0; i < days; i++)
        sum += a[i] * revenue;
    return sum;
}

double calcAvgRevenue(int a[]) // calculate avg revenue in a day
{
    double sum = calcTotalRevenue(a);
    return sum / days;
}

int main()
{
    int a[days];
    int sum; // total sum of pizzas sold in a week
    int avg; // average pizzas sold per day
    int temp;
    double totalRevenue; // The total revenue from the pizza sold for the week
    double avgRevenue;   // The average revenue per day
    cout << "\nEnter the values: \n";
    // Input values
    for (int i = 0; i < days; i++)
    {
        cout << "Day " << i + 1 << ": ";
        cin >> temp;
        if (!check(temp))
        {
            cout << "Enter a positive value\n";
            cout << "Day " << i + 1 << ": ";
            cin >> temp;
        }
        a[i] = temp;
    }
    display(a);
    sum = calcSum(a);
    avg = calcAvg(a);
    totalRevenue = calcTotalRevenue(a);
    avgRevenue = calcAvgRevenue(a);
    cout << "\nThe total number of pizzas sold for the week:  " << sum;
    cout << "\nThe average number of pizzas sold per day:  " << avg;
    cout << "\nThe total revenue from the pizza sold for the week:  " << totalRevenue;
    cout << "\nThe average revenue per day:  " << avgRevenue;
    cout << "\n\nTHANK YOU";
    return 0;
}

Please comment in case of doubts or queries.
Kindly upvote :)


Related Solutions

Write a program (in Q0.c) to do the following: In main(), declare an integer x. Print...
Write a program (in Q0.c) to do the following: In main(), declare an integer x. Print the address of x (using the address-of operator). Pass x as an argument to a function void fooA(int* iptr). (Hint: can you pass x itself directly?) In fooA(int* iptr), print the value of the integer pointed to by iptr, the address pointed to by iptr, and the address of iptr itself. In the main function, following the call to fooA(...) , print the value...
Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter,...
Create an object called Circle. Declare the following integer variables for the object Circle, radius, diameter, and pi is declared as double. Create the following for the Circle object: ● Implicit constructor (default constructor) ● Void method Calculate (double pi, int radius) to calculate the area of the Circle object. The method must include a system.out statement that displays the area value. Use the following formula to calculate area of the circle: Area = pi * (r * r) Your...
myLinkedList.java>>>>>>>> public class MyLinkedList implements MiniList<Integer>{ /* Private member variables that you need to declare: **...
myLinkedList.java>>>>>>>> public class MyLinkedList implements MiniList<Integer>{ /* Private member variables that you need to declare: ** The head pointer ** The tail pointer */ public class Node { // declare member variables (data and next) // finish these constructors public Node(int data, Node next) {} public Node(int data) {} // HINT: use this() with next = null } // Initialize the linked list (set head and tail pointers) public MyLinkedList() {} @Override public boolean add(Integer item) { return false; }...
Declare local variables under main() program Prompts the user to enter 5 test scores Define a...
Declare local variables under main() program Prompts the user to enter 5 test scores Define a function to calculate the average score: this should accept 5 test scores as argument and return the avg Define a function to determine the letter grade: this should accept a test score as argument and return a letter grade based on the following grading scale. Score         Letter Grades 90-100                A 80-89                   B 70-79                   C 60-69                   D Below 60            F
C++ Given Code: #include <iostream> #include <string> using namespace std; int main() { //declare variables to...
C++ Given Code: #include <iostream> #include <string> using namespace std; int main() { //declare variables to store user input bool cont = true; //implement a loop so that it will continue asking until the user provides a positive integer // the following provides ONLY part of the loop body, which you should complete { cout <<"How many words are in your message? \n"; cout <<"Enter value: "; // get user input integer here    cout <<"\nInvalid value. Please Re-enter a...
Y is a Binomial random variable where, Y = The number of days in a week...
Y is a Binomial random variable where, Y = The number of days in a week someone goes to the gym. Where a week has 7 days and the probability of someone going to the gym on any given day is .65.  What is the probability that someone goes to the gym at least 3 days out of the week? Hint: This is a cumulative probability, so you need to add up the probabilities of Y equaling all the possible values...
The discussion for this week will focus on the importance of the two main topics of...
The discussion for this week will focus on the importance of the two main topics of this chapter (photosynthesis and cellular respiration) to each other. There is a unique balance between these two energy cycles, and your postings should address something specific that addresses this idea. For instance, you can focus on one of the following: the history of these processes (which one we think started first and how that eventually led to the other one), different types of interactions,...
in C++ In the main function, declare a two-dimensional matrix array 5 by 5, read data...
in C++ In the main function, declare a two-dimensional matrix array 5 by 5, read data from a file named “data.txt”. Suppose the data in the file are integers between 0 and 9. Write your main function to print out the left bottom below the diagonal of the matrix and keep the triangle shape. Note the numbers on the diagonal are not included in the output. An example is given as follows. (25 points) Suppose the original matrix is 1...
In the main function, declare a two-dimensional matrix array 5 by 5, read data from a...
In the main function, declare a two-dimensional matrix array 5 by 5, read data from a file named “data.txt”. Suppose the data in the file are integers between 0 and 9. Write your main function to print out the left bottom below the diagonal of the matrix and keep the triangle shape. Note the numbers on the diagonal are not included in the output. An example is given as follows. (25 points) Suppose the original matrix is 1 2 3...
C++ On linux Write a C++ program using the IPC. Declare two variables a=5 and b=6...
C++ On linux Write a C++ program using the IPC. Declare two variables a=5 and b=6 in writer process. Now their product (a*b) will be communicated to the reader process along with your name. The reader process will now calculate the square root of the number and display it along with your name.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT