Question

In: Computer Science

Please create a C++ program that will ask a high school group that is made of...

Please create a C++ program that will ask a high school group that is made of 5 to 17 students to sell candies for a fund raiser. There are small boxes that sell for $7 and large ones that sell for $13. The cost for each box is $4 (small box) and $6 (large box). Please ask the instructor how many students ended up participating in the sales drive (must be between 5 and 17). The instructor must input each student’s First name that sold items and enter the number of each box sold each (small or large). Calculate the total profit for each student and at the end of the program, print how many students participated and the total boxes sold for each (small and large) and finally generate how much profit the group made.

Solutions

Expert Solution

Profit for small box = 7 - 4 = $3

Profit for large box = 13 - 6 = $7

C++ code:

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

int main(){

    cout << "Enter the number of students participated (must be from 5 to 17) in the sales drive: ";
    int n; cin >> n;
    vector<string> names;
    vector<int> S;
    vector<int> L;

    cout << "Enter number of boxes each student sold small and large separated by a space" << endl;
    string name;
    int s, l;
    
    // Take input
    for (int i = 0; i < n; i++){
        cin >> name >> s >> l;
        names.push_back(name);
        S.push_back(s);
        L.push_back(l);
    }
    cout << endl;


    // Print the profits made by each student
    int profit = 0;
    for (int i = 0; i < n; i++){
        cout << "Student " << names[i] << " has made profit of $" << S[i]*3 + L[i]*7 << endl;
        profit += S[i]*3 + L[i]*7;
    }

    // Print the output
    cout << "The total number of students participated: " << n << endl;
    cout << "The number of small boxes sold: " << accumulate(S.begin(), S.end(), 0) << endl;
    cout << "The number of large boxes sold: " << accumulate(L.begin(), L.end(), 0) << endl;
    cout << "The total profit made by the group: $" << profit << endl;
    return 0;
}


Please refer to the following pictures for the source code:

Sample execution of the above code:


Related Solutions

Please create a c++ program that will ask a high school group that is made of...
Please create a c++ program that will ask a high school group that is made of 5 to 17 students to sell candies for a fund raiser. There are small boxes that sell for $7 and large ones that sell for $13. The cost for each box is $4 (small box) and $6 (large box). Please ask the instructor how many students ended up participating in the sales drive (must be between 5 and 17). The instructor must input each...
Please create a C++ program that will ask a high school group that is made of...
Please create a C++ program that will ask a high school group that is made of 5 to 17 students to sell candies for a fund raiser. There are small boxes that sell for $7 and large ones that sell for $13. The cost for each box is $4 (small box) and $6 (large box). Please ask the instructor how many students ended up participating in the sales drive (must be between 5 and 17). The instructor must input each...
Create a C++ program that will ask the user for how many test scores will be...
Create a C++ program that will ask the user for how many test scores will be entered. Setup a while loop with this loop iteration parameter. (no fstream) The data needs to include the student’s first name, student number test score the fields should be displayed with a total width of 15. The prompt should be printed with a header in the file explaining what each is: ex. First Name student number Test Score 1) mike 6456464   98 2) phill...
C++ polymorphism. Create a program that issues a quiz through the terminal. The quiz will ask...
C++ polymorphism. Create a program that issues a quiz through the terminal. The quiz will ask a variety of C++ questions to the user and prompt them for a response. The response will differ based on the type of question, such as true or false, multiple-choice, or fill in the blank. Part 1: Designing the Quiz Design this program using a polymorphic vector of questions. Create a Question base class that will serve to point to three different derived classes:...
Using (C programming language) Create a health monitoring program, that will ask user for their name,...
Using (C programming language) Create a health monitoring program, that will ask user for their name, age, gender, weight, height and other health related questions like blood pressure and etc. Based on the provided information, program will tell user BMI, blood pressure numbers if they fall in healthy range or not and etc. Suggestions can be made as what should be calorie intake per day and the amount of exercise based on user input data. User should be able to...
C++ Create a program that simulates a coin being flipped. Ask the user to guess between...
C++ Create a program that simulates a coin being flipped. Ask the user to guess between heads and tails. Let the user input 0 for heads and 1 for tails. Use a random generator to get random guesses every time. If the user guesses correctly, give them 1pt. Use a counter and initialize it to 0.   If the user does not guess correctly, subtract a point. Create a menu that allows the user to continue guessing, view the current score...
Please use C language and use link list to do this program. This program should ask...
Please use C language and use link list to do this program. This program should ask user to enter two fraction polynomials. Then user chocie if he want add it or multiple it. I need you please to test it to see if it work with these two fraction polynomials 1-  Left Poly Pointer: 1/1x2 + 3/4x + 5/12 2-Right Poly Pointer: 1/1x4 – 3/7x2 + 4/9x + 2/11 AND AFTER ADDING 3- Resulting Poly Pointer: 1/1x4 + 4/7x2 + 43/36x...
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
Create a small program that contains the following. ask the user to input their name ask...
Create a small program that contains the following. ask the user to input their name ask the user to input three numbers check if their first number is between their second and third numbers
In c++ create a program that asks for tire shop sales numbers made by 0 to...
In c++ create a program that asks for tire shop sales numbers made by 0 to 20 employees Premium tires sell for $300 and standard tires sell for $250 The wholesale cost of premium tires is $120 and the standard is $100 The program must ask for each employee's name and then the amount of premium and standard tires sold. Output the name and the total profit each employee made for the shop Output the total profits earned between all...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT