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

This programming example further illustrates the concepts of inheritance and com

ID: 3800841 • Letter: T

Question

This programming example further illustrates the concepts of inheritance and composition.

The mid-semester point at your local university is approaching. The registrar’s office wants to prepare the grade reports as soon as the students’ grades are recorded. However, some of the students enrolled have not yet paid their tuition.

If a student has paid the tuition, the grades are shown on the grade report together with the grade point average (GPA).

If a student has not paid the tuition, the grades are not printed. For these students, the grade report contains a message indicating that the grades have been held for nonpayment of the tuition. The grade report also shows the billing amount.

The registrar’s office and the business office want your help in writing a program that can analyze the students’ data and print the appropriate grade reports. The data is stored in a file in the following form:

The first line indicates the number of students enrolled and the tuition rate per credit hour. The students’ data is given thereafter.

A sample input file is as follows:

The first line indicates that the input file contains three students’ data, and the tuition rate is  per credit hour. Next, the course data for student Lisa Miller is given: Lisa Miller’s ID is , she has paid the tuition, and she is taking four courses. The course number for the mathematics class she is taking is MTH345, the course has four credit hours, her mid-semester grade is A, and so on.

The desired output for each student is in the following form:

It is clear from this output that the courses must be ordered according to the course number. To calculate the GPA, we assume that the grade A is equivalent to four points, B is equivalent to three points, C is equivalent to two points, D is equivalent to one point, and F is equivalent to zero points.

Explanation / Answer

#include <bits/stdc++.h>
using namespace std;
class Student
{
   public:string cname,cid,gradid;
   int grade;


};

void bubblesort (Student a[], int n) // n = SIZE;
{
bool sorted = false;
for (int i = 0; i < n-1 && !sorted; i++)
{
sorted = true;
for (int j = 0; j < (n-1-i); j++)
{
if (a[j].cid.compare(a[j+1].cid)>0)
{
swap (a[j], a[j+1]);
sorted = false;
}
}
}
}

int main(int argc, char const *argv[])
{
   int n,Rate,sid;
   int no_of_course;
   char paid;
   string fname,lname;

   fstream file("input.txt");

   fstream output("out.txt");


       while(file>>n>>Rate)
       {

       for (int j = 0; j < n; ++j)
       {
          
               file>>fname>>lname>>sid>>paid>>no_of_course;
           output<<"Student Name: "<<fname<<" "<<lname<<endl;
           output<<"Student ID: "<<sid<<endl;
           output<<"Number of courses enrolled :"<<no_of_course<<endl;
           float total_credits=0;
           Student s[no_of_course];
          

           if(paid=='N')
           {
                   output<<"Grades have been held for nonpayment of the tuition"<<endl;
                   output<<"Amount to be paid tuition rate per credit hour "<<Rate<<endl;
                   for (int i = 0; i < no_of_course; ++i)
                       {
                           string cname,cid,gradid;
                           int grade;
                          
                          
                           file>>cname>>cid>>grade>>gradid;

                          
                       }
           }

           else
       {
          
           output<<"Course No Course Name Credits Grade ";

          
           for (int i = 0; i < no_of_course; ++i)
           {
               string cname,cid,gradid;
               int grade;
              
              
               file>>(s[i].cname)>>(s[i].cid)>>(s[i].grade)>>(s[i].gradid);

              
           }

           bubblesort (s,no_of_course);

           float gpa=0;
           for (int i = 0; i < no_of_course; ++i)
           {
              
               output<<s[i].cid<<" "<<s[i].cname<<" "<<s[i].grade<<" "<<s[i].gradid<<endl;
              
               total_credits+=s[i].grade;
               if(s[i].gradid.compare("A")==0)
               {
                       gpa+=4;
                      
               }

               if(s[i].gradid.compare("B")==0)
               {
                   gpa+=3;
                  
               }

               if(s[i].gradid.compare("C")==0)
               {
                   gpa+=2;
                  
               }

               if(s[i].gradid.compare("D")==0)
               {
                   gpa+=1;
                  
               }
              
           }
           output<<"Total number of credits : "<<total_credits<<endl;
          
           output<<"Mid-Semister GPA: "<<gpa/(float)no_of_course<<endl;
       }
   }
   }
       file.close();
       output.close();
  
   return 0;
}

===========================================================================

input.txt

3 345
Lisa Miller 890238 Y 4
Math MTH345 4 A
Physics PHY357 3 B
ComputerSci CSC478 3 B
History HIS356 3 A
Lisa Miller 890238 N 4
Math MTH345 4 A
Physics PHY357 3 B
ComputerSci CSC478 3 B
History HIS356 3 A
Lisa Miller 890238 Y 4
Math MTH345 4 A
Physics PHY357 3 B
ComputerSci CSC478 3 B
History HIS356 3 A

===================================================

out.txt

Student Name: Lisa Miller
Student ID: 890238
Number of courses enrolled :4
Course No   Course Name       Credits       Grade
CSC478       ComputerSci       3       B
HIS356       History       3       A
MTH345       Math       4       A
PHY357       Physics       3       B
Total number of credits : 13
Mid-Semister GPA: 3.5
Student Name: Lisa Miller
Student ID: 890238
Number of courses enrolled :4
Grades have been held for nonpayment of the tuition
Amount to be paid tuition rate per credit hour 345
Student Name: Lisa Miller
Student ID: 890238
Number of courses enrolled :4
Course No   Course Name       Credits       Grade
CSC478       ComputerSci       3       B
HIS356       History       3       A
MTH345       Math       4       A
PHY357       Physics       3       B
Total number of credits : 13
Mid-Semister GPA: 3.5

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