In: Computer Science
Q1) Please 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. The data will include the student’s
first name, Wayne State Access ID, midterm score and their favorite
team (i.e. – Doug, hg1702, 92, Wolverines * - John, hv2201, 99,
Warriors). Print out the completed test scores to a file
(midTermScores.txt) . Adjust the output as follows: (15
points)
a. Scores with the highest grade should be listed first as in
ascending order.
b. A letter grade should be in place of the numeric score using
standard grading (a = 90 – 100, b=80-90, c=70-80, d=60-70, f=below
60)
c. The fields should be displayed with a total width of 15.
d. The fields should be printed with a header in the file
explaining what each is:
i. First Name Access ID Test Score Favorite Team
ii. John hv2201 A Warriors
iii. Doug hg1702 A Wolverines
Q2) Please create a 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)
//Q1
#include<bits/stdc++.h>
using namespace std;
struct student
{
string name;
string ID;
string grade;
string team;
};
bool fn(struct student x,struct student y)
{
return x.grade<=y.grade;
}
int main()
{
int N,i;
ofstream file;
cout<<"Enter How many Test Score will be
entered"<<endl;
cin>>N;
cout<<"enter ""Firt_NAME,Wayne State
Access ID,midTermScores,Favorite_team"" for each student
"<<endl;
vector<struct student> v;
while(N--)
{
int score;
struct student s;
cin>>s.name>>s.ID>>score>>s.team;
if(score>=90&&score<=100)
s.grade="A";
if(score>=80&&score<90)
s.grade="B";
if(score>=70&&score<80)
s.grade="C";
if(score>=60&&score<70)
s.grade="D";
else
if(score<60)
s.grade="F";
v.push_back(s);
}
sort(v.begin(),v.end(),fn);
file.open ("midTermScores.txt");
cout<<"First Name Access_ID Test_Score
Favorite_Team";
for(i=0;i<v.size();i++)
{
cout<<i+1<<"
";
cout<<v[i].name<<v[i].ID<<v[i].grade<<v[i].team;
cout<<endl;
}
file.close();
return 0;
}
//Q2
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N,x,y,T_sum,sum,i,a,b;
string s;
cout<<"please enter number of student
participated in sales drive "<<endl;
cin>>N;
vector<pair<string,int>> v;
cout<<"Enter students First name and
number of each boxes sold each small and large"<<endl;
T_sum=0;
x=0;
y=0;
for(i=0;i<N;i++)
{
cin>>s>>a>>b;
x+=a;
y+=b;
sum=(a*3)+(b*7);
v.push_back(make_pair(s,sum));
T_sum+=sum;
}
cout<<"Total number of student
participated is"<<N<<endl;
cout<<"Numebr of small boxes sold is
"<<x<<" and Number of large boxes sold is
"<<y<<endl;
cout<<"total profit made by group is
"<<T_sum<<endl;
return
0;
}