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

Please help me!!!!! Write a C++ program that can help the instructor manage the

ID: 3778635 • Letter: P

Question

Please help me!!!!!
Write a C++ program that can help the instructor manage the information of all students in a class. ((You need to design two Classes)).

The first class one representing a student that includes relevant data fields such as first name, last name, SIU ID, score. You also need to create a file storing the information all students, named “students.txt”. Suppose each row of the file contains the information of one students in the following format and you can determine their values by your own.

Kang Chen 777777 88

The second Class represents the classroom, which contains the instructor name, location and time of the class, an array of students, and a series of member functions helping managing the class. You suppose the class has at most 30 students or use the dynamic std::vector to alleviate this limit. The series of member functions include:

Default constructor: The default constructor will set the instructor name to “Kang Chen”, the location to “Hall0101”, the class time to “MFW1PM-1:50PM”, and read the students.txt and store student information in the array of students.
ListCalssInfo: The function will print instructor name, class location and time, and the number of students in the class to console.
AddAStudent: The function will ask the instructor to input the information of the student. It will check whether a student with the same name (compare both first and last name) already exists. If yes, the inputted information will be used to update the student’s information. Otherwise a new student will be created.
DropAStudent: The function will ask the instructor to input the first and last name of the student. If such a student exists, the student’s information will be deleted. Otherwise, a prompt will be printed to the instructor saying ‘not exist’.
ListAllStudents: The function will list the information of all students one row by one row.
SaveStudentInfo: The function will write the information of all students stored in the array of students to the “students.txt” file. Each row of the file should contain the information of one student.
ListOneStudent: The function will ask the instructor to input the first and last name of the student. If such a student exists, it will list the information of the student. Otherwise, a prompt will be printed to the instructor saying ‘not exist’.
UpdateAStudent: The function will modify the information of a student. The program will ask the instructor to input the first and last name of the student. If such a student exists, it will further ask the instructor to further input other information of the student. Otherwise, a prompt will be printed to the instructor saying ‘not exist’.
CalculateStatistic: The function will calculate and print the maximal score, minimal score, average score, andmedium score of all students to the console.

In your main function, you need to declare an object of the classroom class, and print and execute a menu like the following:

ListCalssInfo
AddAStudent
DropAStudent
ListAllStudents
SaveStudentInfo
ListOneStudent
UpdateAStudent
CalculateStatistic

Exit Your program should allow the user to repetitively select an option from the menu. When an option is selected, the corresponding member function of your classroom object should be called to finish the corresponding task. Note that if “9 Exit” is selected, you have to call the SaveStudentInfo function before exit the problem. As a result, the updated information is always stored.

Explanation / Answer

Code:

#include<iostream>
#include<fstream>
#include<vector>
#include<sstream>
#include<algorithm>
#include<string>
using namespace std;
class student
{
   string firstname;
   string lastname;
   int SIU_ID;
   double score;
public:
   student()
   {
       firstname="";
       lastname="";
       SIU_ID=0;
       score=0.00;
   }
  
   student(string f,string l,int id,double s)
   {
       firstname=f;
       lastname=l;
       SIU_ID=id;
       score=s;
   }
   string getfirstname()
   {
       return firstname;
   }
   string getlastname()
   {
       return lastname;
   }
   int getid()
   {
       return SIU_ID;
   }
   double getScore()
   {
       return score;
   }
   void setfirstname(string f)
   {
       firstname=f;
   }
   void setlastname(string l)
   {
       lastname=l;
   }
   void setid(int id)
   {
       SIU_ID=id;
   }
   void setscore(double sc)
   {
       score=sc;
   }
   void print()
   {
       cout<<firstname<<" "<<lastname<<" "<<SIU_ID<<" "<<score<<endl;
             
   }
};
class classroom
{
   string instname;
   string location;
   string time;
   vector<student> s;
public:
   classroom()
   {
       instname="Kang Chen";
       location="Hall0101";
       time="MFW1PM-1:50PM";
       ifstream f;
       f.open("student.txt");
       string line;
       while(getline(f,line))
       {
           istringstream ss(line);
           string first;
           ss>>first;
           string last;
           ss>>last;
           int id;
           ss>>id;
           double score;
           ss>>score;
           student st(first,last,id,score);
           s.push_back(st);
       }
      
   }
   void ListClassInfo()
   {
       cout<<"Instructor name:"<<instname<<endl;
       cout<<"Location :"<<location<<endl;
       cout<<"time: "<<time;
       cout<<"Number of students: "<<s.size();
   }
   void AddAStudent()
   {
       cout<<"Enter thye student firstname"<<endl;
       string first;
       getline(cin,first);
       cout<<"Enter the student lastname"<<endl;
       string last;
       getline(cin,last);
       cout<<"Enter the student id"<<endl;
       int id;
       cin>>id;
       cout<<"Enter the score of student"<<endl;
       double score;
       cin>>score;
       bool found=false;
       int i=0;
       vector<student>::iterator iter;
       for (i=0; i<s.size(); i++)
       {
          
           if((s[i].getfirstname()==first)&&(s[i].getlastname()==last))
           {
               found=true;
               break;
           }
       }
       if(found==true)
       {
           s[i].setfirstname(first);
           s[i].setlastname(last);
           s[i].setid(id);
           s[i].setscore(score);
       }
       else
       {
           student st(first,last,id,score);
           s.push_back(st);

       }

   }
   void DropAStudent()
   {
       cout<<"Enter the first name of student"<<endl;
       string first;
       getline(cin,first);
       cout<<"Enter the last name of student"<<endl;
       string last;
       getline(cin,last);
       int i=0;
       bool found=false;
       for (i=0; i<s.size(); i++)
       {
          
           if((s[i].getfirstname()==first)&&(s[i].getlastname()==last))
           {
               found=true;
               break;
           }
       }
       if(found==true)
       {
           s.erase (s.begin()+i);
       }
       else
       {
           cout<<"Name does not exist"<<endl;

       }

   }
   void ListAllStudents()
   {
       for (int i=0; i<s.size(); i++)
       {
           s[i].print();
       }
   }
   void SaveStudentInfo()
   {
       ofstream out;
       out.open("out.txt",std::ofstream::out | std::ofstream::app);
       for (int i=0; i<s.size(); i++)
       {
           out<<s[i].getfirstname()<<" "<<s[i].getlastname()<<" "<<s[i].getid()<<" "<<s[i].getScore()<<endl;;
       }

   }
   void UpdateAStudent()
   {
       cout<<"Enter thye student firstname"<<endl;
       string first;
       getline(cin,first);
       cout<<"Enter the student lastname"<<endl;
       string last;
       getline(cin,last);
       int id;
       double score;
       bool found=false;
       int i=0;
       for (i=0; i<s.size(); i++)
       {
          
           if((s[i].getfirstname()==first)&&(s[i].getlastname()==last))
           {
               found=true;
               break;
           }
       }
       if(found==true)
       {
           cout<<"Enter the student id"<<endl;
           cin>>id;
           cout<<"Enter the score of student"<<endl;          
           cin>>score;
           s[i].setid(id);
           s[i].setscore(score);

       }
       else
       {
           cout<<"Name does not exist"<<endl;

       }
      
   }
   void CalculateStatistic()
   {
       int mark[30];
       std::vector<double>marks;
       int count=0;
       double min=100000000.00;
       double max=0;
       double total=0;
       for (int i=0; i<s.size(); i++)
       {
           if(min>s[i].getScore())
           {
               min=s[i].getScore();
           }
          
       }
       cout<<"The minimum score is "<<min<<endl;
       for (int i=0; i<s.size(); i++)
       {
           if(max<s[i].getScore())
           {
               max=s[i].getScore();
           }
          
       }
       cout<<"The maximum score is "<<max<<endl;

       for (int i=0; i<s.size(); i++)
       {
           total=total+s[i].getScore();
           marks.push_back(s[i].getScore());
          
       }
       double avg=total/s.size();
       cout<<"The average is "<<avg<<endl;
       sort(marks.begin(), marks.end());
       double median;
       if(marks.size()%2!=0)
       {
          
           median=marks[(marks.size()/2)+1];
       }
       else
       {
           median=(marks[(marks.size()/2)]+marks[(marks.size()/2)+1])/2.0;
       }
       cout<<"The maedian is "<<median;
   }

};
int main()
{
   int ch;
   classroom *cl=new classroom();;
   do
   {
   cout<<"1: ListClassInfo"<<endl;
   cout<<"2: AddAStudent"<<endl;
   cout<<"3: DropAStudent"<<endl;
   cout<<"4:ListAllStudents"<<endl;
   cout<<"5: SaveStudentInfo"<<endl;
   cout<<"6: UpdateAStudent"<<endl;
   cout<<"7: CalculateStatistic"<<endl;
   cout<<"8: Exit"<<endl;
   cout<<"Enter the option"<<endl;
   cin>>ch;
   switch(ch)
   {
       case 1: cl->ListClassInfo();
               break;
       case 2: cl->AddAStudent();
               break;
       case 3: cl->DropAStudent();
               break;
       case 4:cl->ListAllStudents();
               break;
       case 5:cl->SaveStudentInfo();
               break;
       case 6:cl->UpdateAStudent();
               break;
       case 7:cl->CalculateStatistic();
               break;
       case 8:cl->SaveStudentInfo();
               break;
   }


   }while(ch==8);
   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