Problem 2: Use table 1 to create a vector of structure named student to store th
ID: 3735155 • Letter: P
Question
Problem 2: Use table 1 to create a vector of structure named student to store the records of three students. The data structure should have the following fields: name, PID, homework, project, midterm and final exam. The name and PID fields are strings. The homework field is a vector of 7 homework grades. The project, midterm and final exam fields contain a single number (a) Set p2a student (1) (b) Set p2b student (2) (c) Set p2c student (3) student(2 Suc West A02 90 91 92 93 94 95 96 80 81 82 83 84 85 86 70 71 72 73 74 75 76 96 83 93 student (1 er A01 eld names student(3 ame ac A03 homework project midtermm final exam 95 73 90 97 93 96 Table 1: Students' record (d) Add a new field, named hw.average, to store the average homework grade. Set p2d student.hw averageExplanation / Answer
struct student
{
string name;
string PID;
vector<int> homework(7);
int project;
int midterm;
int final_exam;
}
Int main()
{
struct student p2a;
struct student p2b;
struct student p2c;
strcpy(p2a.name,”Peter Lee”);
strcpy(p2b.name,”Sue West”);
strcpy(p2c.name,”Jack Lew”);
strcpy(p2a.PID,”A01”);
strcpy(p2b.PID,”A02”);
strcpy(p2c.PID,”A03”);
p2a.homework(7)={90,91,92,93,94,95,96};
p2b.homework(7)={80,81,82,83,84,85,86};
p2c.homework(7)={70,71,72,73,74,75,76};
p2a.project=95;
p2b.project=96;
p2c.project=97;
p2a.midterm=73;
p2b.midterm=83;
p2c.midterm=93;
p2a.final_exam=90;
p2b.final_exam=93;
p2c.final_exam=96;
p2d={student.hw_average};
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.