Dec 5, 2017 at 2:16am UTC
this is the work "students at a school volunteered to sell fresh baked cookies to raise funds to increase the number of computers in the computer lab. Each student reported the number of boxes he/she sold. Write a program that wil output the total number of boxes of cookies sold, the total revenue generated by selling the cookies and the saverage number of boxes sold by each student. The programmer do not know the exact number of volunteers involved, we assume that -1 that will mark the end of the data.
Assume the data input is in the following form: student's name followed by a space and the number of boxes sold by the student
Last edited on Dec 5, 2017 at 3:59am UTC
Dec 5, 2017 at 2:37am UTC
Are you reading the data from a file?
Dec 5, 2017 at 2:39am UTC
idk, i need to make a c++ program based on the informations given
Dec 5, 2017 at 2:40am UTC
and i need to forward the source file
Dec 5, 2017 at 2:55am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
#include <iostream>
#include <string>
using namespace std;
struct student
{
string name;
int boxesSold;
float totalMade;
};
float calcAverageBoxes(student [], int );
float calctotalRev(student [], int );
int calcTotalBoxes(student [], int );
int main()
{
int numStudents;
float averageBoxesSold;
float totalRevenue;
float totalBoxesSold;
cout << "How many students were there?" << endl;
cout << " >>> " ;
cin >> numStudents;
student info[numStudents];
for (int i = 0; i < numStudents; i++)
{
cout << "Enter name of first student: " ;
getline(cin, info[i].name);
cout << "Boxes sold for student " << i+1 << ": " ;
cin >> info[i].boxesSold;
cout << "Total made for student " << i+1 << ": " ;
cin >> info[i].totalMade;
}
averageBoxesSold = calcAverageBoxes(info, numStudents);
totalRevenue = calctotalRev(info, numStudents);
totalBoxesSold = calcTotalBoxes(info, numStudents);
for (int i = 0; i < numStudents; i++)
{
cout << "Name: " << info[i].name << endl;
cout << "Boxes sold: " << info[i].boxesSold << endl;
cout << "Total made: " << info[i].totalMade << endl;
}
cout << endl << "Total Revenue: " << totalRevenue << endl;
cout << "Average boxes sold: " << averageBoxesSold << endl;
cout << "Total boxes sold: " << totalBoxesSold << endl;
return 0;
}
float calcAverageBoxes(student info[], int numStudents)
{
float x = 0.0;
for (int i = 0; i < numStudents; i++)
{
x = x + info[i].boxesSold;
}
return x/numStudents;
}
float calctotalRev(student info[], int numStudents)
{
float x = 0.0;
for (int i = 0; i < numStudents; i++)
{
x = x + info[i].totalMade;
}
return x;
}
int calcTotalBoxes(student info[], int numStudents)
{
int x = 0;
for (int i = 0; i < numStudents; i++)
{
x = x+info[i].boxesSold;
}
return x;
}
Haven't tested, not sure it fully works.
Cheers and goodluck
Last edited on Dec 5, 2017 at 2:56am UTC
Dec 5, 2017 at 2:58am UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
#include <iostream>
#include <string>
using namespace std;
struct student
{
string name;
int boxesSold;
float totalMade;
};
float calcAverageBoxes(student [], int );
float calctotalRev(student [], int );
int calcTotalBoxes(student [], int );
int main()
{
int numStudents;
float averageBoxesSold;
float totalRevenue;
float totalBoxesSold;
cout << "How many students were there?" << endl;
cout << " >>> " ;
cin >> numStudents;
student info[numStudents];
for (int i = 0; i < numStudents; i++)
{
cout << "Enter name of student " << i+1 << ": " ;
cin.ignore();
getline(cin, info[i].name);
cout << "Boxes sold for student " << i+1 << ": " ;
cin >> info[i].boxesSold;
cout << "Total made for student " << i+1 << ": " ;
cin >> info[i].totalMade;
}
averageBoxesSold = calcAverageBoxes(info, numStudents);
totalRevenue = calctotalRev(info, numStudents);
totalBoxesSold = calcTotalBoxes(info, numStudents);
for (int i = 0; i < numStudents; i++)
{
cout << "Name: " << info[i].name << endl;
cout << "Boxes sold: " << info[i].boxesSold << endl;
cout << "Total made: " << info[i].totalMade << endl;
}
cout << endl << "Total Revenue: " << totalRevenue << endl;
cout << "Average boxes sold: " << averageBoxesSold << endl;
cout << "Total boxes sold: " << totalBoxesSold << endl;
return 0;
}
float calcAverageBoxes(student info[], int numStudents)
{
float x = 0.0;
for (int i = 0; i < numStudents; i++)
{
x = x + info[i].boxesSold;
}
return x/numStudents;
}
float calctotalRev(student info[], int numStudents)
{
float x = 0.0;
for (int i = 0; i < numStudents; i++)
{
x = x + info[i].totalMade;
}
return x;
}
int calcTotalBoxes(student info[], int numStudents)
{
int x = 0;
for (int i = 0; i < numStudents; i++)
{
x = x+info[i].boxesSold;
}
return x;
}
Fixed a few things
Last edited on Dec 5, 2017 at 2:58am UTC
Dec 5, 2017 at 3:14am UTC
Thank you so much bro, i owe you