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

C++ Design a class called StudentInfo . It should have member variables for the

ID: 3816547 • Letter: C

Question

C++

Design a class called StudentInfo. It should have member variables for the following information:

            Student Name (text)

            Student ID number (12 characters)

            Major (e.g., Computer Science, Business, etc)

Write appropriate member functions to store and retrieve information in the member variables above. The constructor should dynamically allocate enough memory to hold the student name. The destructor should release the memory.

Design another class called StudentGradeInfo. This class should be derived from the StudentInfo class. It should have member variables for at least the following information:

            Test grades (The class should hold up to 10 grades)

            Test average

Write appropriate member functions to store and retrieve information in the member variables above. I would suggest a member function to allow the addition of one grade at a time to Test grades.

The == operator should be overloaded to allow a comparison of two student ID numbers to see if they are equivalent. The << operator should be overloaded to output, neatly formatted, the information associated with a student, including the computed test average.

To demonstrate the classes above, create a class to maintain a GradeBook. The class should allow information on up to 50 students to be stored. Your GradeBook class should at least support operations to Add a student record to the book (i.e., the book entries do not have to be stored in alphabetical order), and to Sort by Student ID number and display all student records (all info associated with a student) in the GradeBook. To add a student to the book, the user should not have to specify a position, (i.e., the GradeBook should keep track of the last position and add to the end automatically).

You should write a main program that creates a grade book and presents a menu to the user that allows them to select either Add (A), or List (L), or Quit (Q). Add should allow the user to enter a student record (name, ID, major, and grades) and add it to the Gradebook list if the ID does not already exist in GradeBook. Do not accept input test scores less than 0 or greater than 100 (i.e., no extra credit).  List should list, sorted by ID number, all student records currently in the grade book. You should be able to add and list repeatedly until you select Q to quit.

Use good coding style and principles for all code and input/output formatting. All data in a class must be private. Put each class declaration in its own header file and its implementation in a separate .cpp file.

Explanation / Answer

Answer:

File Name: StudentInfo.h
#ifndef _STUDENT_INFO
#define _STUDENT_INFO
#include <string>
#include <string.h>
using namespace std;
class StudentInfo
{
private:
   char *studName;
   char studID[12];
   string studMajor;
public:
   StudentInfo();
   StudentInfo(char *name,char *ID, string major);
   StudentInfo(StudentInfo& st);
   ~StudentInfo();
   void setStudName(char * name);
   void setStudID(char *ID);
   void setStudMajor(string major);
   char* getStudName();
   char* getStudID();
   string getStudMajor();
};


#endif


File Name:StudentInfo.cpp
#include <iostream>
#include <string>
#include <string.h>
#include "StudentInfo.h"
using namespace std;
StudentInfo::StudentInfo()
{
}
StudentInfo::StudentInfo(char *name,char *ID, string major)
{
   studName=new char[strlen(name)];
   studName=name;
   strcpy(studID ,ID);
   studMajor=major;
}
StudentInfo::StudentInfo(StudentInfo& st)
{
   setStudName(st.getStudName());
   setStudID(st.getStudID());
   setStudMajor(st.getStudMajor());
}
StudentInfo::~StudentInfo()
{
   delete[] studName;
}
void StudentInfo::setStudName(char * name)
{
   delete[] studName;
   studName=new char[strlen(name)];
   studName = name;
}
void StudentInfo::setStudID(char *ID)
{
   strcpy(studID ,ID);
}
void StudentInfo::setStudMajor(string major)
{
   studMajor=major;
}
char* StudentInfo::getStudName()
{
   return studName;
}
char* StudentInfo::getStudID()
{
   return studID;
}
string StudentInfo::getStudMajor()
{
   return studMajor;
}


File Name:StudentGradeInfo.h
#ifndef _STUDENTGRADE_INFO
#define _STUDENTGRADE_INFO
#include "StudentInfo.h"
#include <string>
using namespace std;
class StudentGradeInfo:public StudentInfo
{
private:
   double testGrade[10];
   double testAverage;
   int cntt;
public:
   StudentGradeInfo();
   StudentGradeInfo(char *name,char *ID, string major,double *grades, int cct);
   StudentGradeInfo(StudentGradeInfo& st);
   void setStudName(char *name);
   void setStudID(char *ID);
   void setStudMajor(string major);
   void setStudentGrades(double *grades, int cct);
   char* getStudName();
   char* getStudID();
   string getStudMajor();
   int getNGrades();
   double getStudTestAvg();
   bool operator==(StudentGradeInfo& st2);
   friend ostream& operator<<(ostream& myOut, StudentGradeInfo& st2);
};

#endif


File Name: StudentGradeInfo.cpp
#include <iostream>
#include <string>
#include <string.h>
#include "StudentGradeInfo.h"
using namespace std;
StudentGradeInfo::StudentGradeInfo()
{      
   cntt=0;
   testAverage=0;
}
StudentGradeInfo::StudentGradeInfo(char *name,char *ID, string major,double *grades, int cct):StudentInfo(name,ID, major)
{
   cntt=cct;
   double mySum=0;
   for(int kk=0;kk<cntt;kk++)
   {

       testGrade[kk]=grades[kk];
       mySum = mySum + grades[kk];
   }
   testAverage = mySum /(double)cct;

}
StudentGradeInfo::StudentGradeInfo(StudentGradeInfo& st):StudentInfo(st.getStudName(),st.getStudID(), st.getStudMajor())
{
   cntt=st.getNGrades();
   testAverage = st.getStudTestAvg();
}
void StudentGradeInfo::setStudName(char *name)
{
   StudentInfo::setStudName(name);
}

void StudentGradeInfo::setStudID(char *ID)
{
   StudentInfo::setStudID(ID);
}
void StudentGradeInfo::setStudMajor(string major)
{
   StudentInfo::setStudMajor(major);
}
void StudentGradeInfo::setStudentGrades(double *grades, int cct)
{
   cntt=cct;
   double mySum=0;
   for(int kk=0;kk<cntt;kk++)
   {

       testGrade[kk]=grades[kk];
       mySum = mySum + grades[kk];
   }
   testAverage = mySum /(double)cct;

}
char* StudentGradeInfo::getStudName()
{
   return StudentInfo::getStudName();
}
char* StudentGradeInfo::getStudID()
{
   return StudentInfo::getStudID();
}
string StudentGradeInfo::getStudMajor()
{
   return StudentInfo::getStudMajor();
}
int StudentGradeInfo::getNGrades()
{
   return cntt;
}
double StudentGradeInfo::getStudTestAvg()
{
   return testAverage;
}
bool StudentGradeInfo::operator==(StudentGradeInfo& st2)
{
   if(strcmp(getStudID(),st2.getStudID())==0)
       return true;
   return false;
}
ostream& operator<<(ostream& myOut,StudentGradeInfo& st2)
{
   myOut<<"Student Name:"<<st2.getStudName()<<endl;
   myOut<<"ID:"<<st2.getStudID()<<endl;
   myOut<<"Major:"<<st2.getStudMajor()<<endl;
   myOut<<"Test Average:"<<st2.getStudTestAvg()<<endl;
   return myOut;
}

File Name: GradeBook.h
#ifndef _GRADE_BOOK
#define _GRADE_BOOK
#include "StudentGradeInfo.h"
#include "StudentInfo.h"
class GradeBook
{
private:
   StudentGradeInfo myBook[50];
   int studCntt;
public:
   GradeBook();
   void AddStudent(char *name,char *ID, string major,double *grades, int cct);
   void sortGradeBook();
   void printGradeBook();
};

#endif


File Name: GradeBook.cpp
#include <iostream>
#include <string>
#include <string.h>
#include "GradeBook.h"
using namespace std;
GradeBook::GradeBook()
{
   studCntt=0;
}
void GradeBook::AddStudent(char *name,char *ID, string major,double *grades, int cct)
{
   myBook[studCntt]=StudentGradeInfo(name,ID, major,grades, cct);
   studCntt++;
}
void GradeBook::sortGradeBook()
{
   StudentGradeInfo tpp;
   for(int kk=1;kk<studCntt;kk++)
   {
       for(int aa=0;aa<(studCntt-kk);aa++)
       {
           if(strcmp(myBook[aa].getStudID(),myBook[aa+1].getStudID())>0)
           {
               tpp=myBook[aa];
               myBook[aa]=myBook[aa+1];
               myBook[aa+1]=tpp;
           }
       }
   }
}
void GradeBook::printGradeBook()
{
   cout<<"Displaying GradeBook:"<<endl;
   for(int aa=0;aa<studCntt;aa++)
   {
       cout<<myBook[aa]<<endl;
   }
}

File Name: main.cpp
#include <iostream>
#include <string>
#include <string.h>
#include "StudentInfo.h"
#include "StudentGradeInfo.h"
#include "GradeBook.h"
using namespace std;
int main()
{
  
   GradeBook myGradeBook;

   while(1)
   {
       char *name=new char[50];
       char *ID=new char[12];
       double grades[10];
       int grad=0;
       string major;
       StudentInfo my;
       char myCh='Q';
       cout<<"MENU:"<<endl;
       cout<<"A Add"<<endl;
       cout<<"L List"<<endl;
       cout<<"Q Quit"<<endl;
       cout<<"Enter ur choice:";
       cin>>myCh;
       if(myCh=='Q' || myCh=='q')
           break;
       switch(myCh)
       {
       case 'A':
           cout<<"Enter student name, id, major:";
           cin>>name;          
           cin>>ID;          
           cin>>major;          
           cout<<"Enter the number of grades:";
           cin>>grad;
           cout<<"Enter the grades:"<<endl;
           for(int kk=0;kk<grad;kk++)
               cin>>grades[kk];
          
           my=StudentInfo(name,ID,major);
           cout<<my.getStudMajor();
           cout<<" "<<my.getStudName();
           myGradeBook.AddStudent(name,ID,major,grades,grad);
           myGradeBook.sortGradeBook();
           break;

       case 'L':
           myGradeBook.printGradeBook();
           break;
       default:
           cout<<"Invalid choice"<<endl;
       }
   }  
   system("pause");
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote