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. (15 points)
#include <iostream>
#include<string>
using namespace std;
/* macros to define selling price and cost price of small and large boxes */
#define SMALL_BOX_COST_PRICE 4
#define LARGE_BOX_COST_PRICE 6
#define SMALL_BOX_SELLING_PRICE 7
#define LARGE_BOX_SELLING_PRICE 13
/* structure to save information for each student */
struct studentInfo
{
int smallBox;
int largeBox;
int profit;
string name;
};
int main()
{
studentInfo arrayStudentInfo[17]; /*maximum 17 students can be there*/
int numStudents;
int totalSmallBox=0;
int totalLargeBox=0;
int totalProfit = 0;
cout<<"Please enter number of students participating in drive ::";
while(true) /*infinite loop to make sure that number of students are between 5 and 17 */
{
cin>>numStudents;
if(numStudents>=5 && numStudents<=17) /* if number of students entered is correct, break to come out of loop*/
{
break;
}
cout<<"Number of students must be between 5 & 17 ::";
}
/* loop to get student info */
for(int i=0;i<numStudents;i++)
{
cout<<"Enter information for student#"<<i+1;
cout<<"\nEnter name :: ";
cin>>arrayStudentInfo[i].name;
cout<<"Enter number of small boxes sold :: ";
cin>>arrayStudentInfo[i].smallBox;
cout<<"Enter number of large boxes sold :: ";
cin>>arrayStudentInfo[i].largeBox;
/*calculate student profit by subtacting cost price from selling price */
arrayStudentInfo[i].profit = arrayStudentInfo[i].smallBox * SMALL_BOX_SELLING_PRICE + arrayStudentInfo[i].largeBox * LARGE_BOX_SELLING_PRICE - (arrayStudentInfo[i].smallBox * SMALL_BOX_COST_PRICE + arrayStudentInfo[i].largeBox * LARGE_BOX_COST_PRICE);
}
/* loop to calculate total small boxes , large boxes and profit */
for(int i=0;i<numStudents;i++)
{
totalSmallBox = totalSmallBox + arrayStudentInfo[i].smallBox;
totalLargeBox = totalLargeBox + arrayStudentInfo[i].largeBox;
totalProfit = totalProfit + arrayStudentInfo[i].profit;
}
cout<<"\nTotal number of students participated are :: "<<numStudents;
cout<<"\nTotal number of small boxes sold are :: "<<totalSmallBox;
cout<<"\nTotal number of largeBox boxes sold are :: "<<totalLargeBox;
cout<<"\nTotal profit made by group is :: "<<totalProfit;
return 0;
}
Please upvote if u like answer otherwise comment for clarification.
Get Answers For Free
Most questions answered within 1 hours.