Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++: You’ve been given a skeleton of the code, but you need to fill in the pa

ID: 3832570 • Letter: I

Question

In C++:

You’ve been given a skeleton of the code, but you need to fill in the parts of the functions relating to the Transcript variable; note that in addition to initializeStudent and printStudent, I’ve also incorporated a mergeStudent function. You will modify printStudent, initializeStudent, and mergeStudent to handle the parts of the Student relating to their Transcript. 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;

};

// Transcriptstruct

Transcript {    

string classes[100];    double grades[100];    int class_count;    double gpa;

};
// studentstruct

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++) {        i

nitializeStudent(freshmen[i]);    }       

cout << freshmen[0].name << endl;    

for(int i = 0; i < n; i++){        

printStudent(freshmen[i]);    

}

    cout << endl;   

return 0;}

// printing student informationvoid

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 studentvoid

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   }
// MergingStudent

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

// s.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include <string>
#include <iostream>
using namespace std;
// Date
struct Date {
   int month;
   int day;
   int year;
};
// Transcriptstruct
struct Transcript{
   string classes[100]; double grades[100]; int class_count; double gpa;
};
// studentstruct
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

// printing student informationvoid
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;
   cout << "classes and their corresponding grades" << endl;
   for (int i = 0; i < s.tran.class_count; i++)
   {

       cout << s.tran.classes[i] << s.tran.grades[i] << endl;
   }

   cout << "gpa is:" << s.tran.gpa << endl;
}
   //Add stuff for transcript // TODO}
   // initializing studentvoid
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;
   int i = 0;
   while (true)
   {
       cout << "enter class and grades an enter 0 to end" << endl;
       cin >> st.tran.classes[0] >> st.tran.grades[0];

       if (st.tran.classes[0] == "0")
       {
           break;
       }
       st.tran.class_count++;

   }
   double gp=0;
   for (int i = 0; i < st.tran.class_count; i++)
   {
       gp = gp + st.tran.grades[i];
   }
   st.tran.gpa = gp / st.tran.class_count;

}
       //Fill in stuff for transcript // TODO }
       // MergingStudent
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;

       string str = "";

       for (int i = 0; i < s1.tran.class_count; i++)
       {
           for (int j = 0; j < s2.tran.class_count; j++)
           {
               if (s1.tran.classes[i] == s2.tran.classes[j])
               {
                   str = s1.tran.classes[i];
               }
           }
       }
       //Fill in stuff for transcript // TODO

       for (int i = 0; i < s1.tran.class_count; i++)
       {
           ret.tran.classes[ret.tran.class_count++] = s1.tran.classes[i];
       }

       for (int i = 0; i < s2.tran.class_count; i++)
       {
           if (s2.tran.classes[i] != str)
           {
               ret.tran.classes[ret.tran.class_count++] = s2.tran.classes[i];


           }

       }
       return ret;

   }

}

       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;
       }