In: Computer Science
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.
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: