Fill in this C++ code: Fill in the parts of the functions relating to the Transc
ID: 3832815 • Letter: F
Question
Fill in this C++ code:
Fill in the parts of the functions relating to the Transcript variable
In initializeStudent, you should add code to read in the students’ courses and grades. From the grades entered, you should compute the student’s gpa.
In printStudent, you should add code to print out the students’ courses and grades, and their gpa.
In mergeStudent, you should add code that will include all courses from both students (but with no duplicates) and compute the new gpa, and store these values into the returned Student. The idea of the mergeStudent function is that there may be two duplicate variables representing the same student, and you want to come up with a new variable based on those.
#include <iostream>
using namespace std;
// Date
struct Date {
int month;
int day;
int year;
};
// Transcript
struct Transcript {
string classes[100];
double grades[100];
int class_count;
double gpa;
};
// student
struct Student {
string name;
int id;
string major;
Transcript tran;
int age;
Date dob;
};
// function declarations
Student mergeStudent(Student s1, Student s2);
void printStudent(Student s);
void initializeStudent(Student& st);
// for testing
int main() {
const int n = 100;
//You may wish to make this smaller for testing.
Student freshmen[n];
for(int i = 0; i < n; i++) {
initializeStudent(freshmen[i]);
}
cout << freshmen[0].name << endl;
for(int i = 0; i < n; i++){
printStudent(freshmen[i]);
}
cout << endl;
return 0; }
// printing student information
void printStudent(Student s) {
cout << "Name is: " << s.name << endl;
cout << "ID is: " << s.id << endl;
cout << "major is:" << s.major << endl;
cout << "Birthday is: " << s.dob.month << "/" << s.dob.day << "/" << s.dob.year << endl;
cout << "Age is: " << s.age;
//Add stuff for transcript
// TODO
}
// initializing student
void initializeStudent(Student& st) {
string dummy;
cout << "Enter a name" << endl;
getline(cin, st.name); // getline reads a line
cout << "Enter an id" << endl;
cin >> st.id;
getline(cin, dummy);
cout << "enter a major" << endl;
getline(cin, st.major);
cout << "Enter age: " << endl;
cin >> st.age;
cout << "Enter birthday month, day, year as numbers: " << endl;
cin >> st.dob.month >> st.dob.day >> st.dob.year;
//Fill in stuff for transcript
// TODO
}
// Merging
Student mergeStudent(Student s1, Student s2) {
Student ret = {"no name", 0, ""};
if(s1.id == s2.id){
ret.id = s1.id;
if(s1.age > s2.age) {
ret.major = s1.major;
}
else {
ret.major = s2.major;
}
if(s1.name.length() > s2.name.length())
ret.name = s1.name;
else
ret.name = s2.name;
//Fill in stuff for transcript
// TODO
}
return ret;
}
Explanation / Answer
#include <iostream>
using namespace std;
// Date
struct Date {
int month;
int day;
int year;
};
// Transcript
struct Transcript
{
string classes[100];
double grades[100];
int class_count;
double gpa;
};
// student
struct Student
{
string name;
int id;
string major;
Transcript tran;
int age;
Date dob;
};
// function declarations
Student mergeStudent(Student s1, Student s2);
void printStudent(Student s);
void initializeStudent(Student& st);
// for testing
int main()
{
const int n = 100;
//You may wish to make this smaller for testing.
Student freshmen[n];
for(int i = 0; i < n; i++) {
initializeStudent(freshmen[i]);
}
cout << freshmen[0].name << endl;
for(int i = 0; i < n; i++){
printStudent(freshmen[i]);
}
cout << endl;
return 0; }
// printing student information
void printStudent(Student s)
{
cout << "Name is: " << s.name << endl;
cout << "ID is: " << s.id << endl;
cout << "major is:" << s.major << endl;
cout << "Birthday is: " << s.dob.month << "/" << s.dob.day << "/" << s.dob.year << endl;
cout << "Age is: " << s.age;
// stuff for transcript
for(int i=0; i<10;i++)
{
cout<< st.tran.classes[i];
cout<< st.tran.grades[i];
}
cout<<"Class count is: "<<st.tran.class_count;
cout<<"GPA is: "<<st.tran.gpa;
}
// initializing student
void initializeStudent(Student& st)
{
string dummy;
cout << "Enter a name" << endl;
getline(cin, st.name); // getline reads a line
cout << "Enter an id" << endl;
cin >> st.id;
getline(cin, dummy);
cout << "enter a major" << endl;
getline(cin, st.major);
cout << "Enter age: " << endl;
cin >> st.age;
cout << "Enter birthday month, day, year as numbers: " << endl;
cin >> st.dob.month >> st.dob.day >> st.dob.year;
//stuff for transcript
cout << "Enter class and grades: " << endl;
for(int i=0; i<10;i++)
{
getline(cin, st.tran.classes[i]);
getline(cin, st.tran.grades[i]);
}
cin>>st.tran.class_count;
cin>>st.tran.gpa;
}
// Merging
Student mergeStudent(Student s1, Student s2)
{
Student ret = {"no name", 0, ""};
if(s1.id == s2.id)
{
ret.id = s1.id;
if(s1.age > s2.age)
{
ret.major = s1.major;
}
else
{
ret.major = s2.major;
}
if(s1.name.length() > s2.name.length())
ret.name = s1.name;
else
ret.name = s2.name;
// stuff for transcript
}
ret.tran.gpa = = (s1.tran.gpa+s2.tran.gpa) / 2;
return ret;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.