This programming example further illustrates the concepts of

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.

Can you convert this to a C++ code?

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#include
using namespace std;
class Student
{
public:string cname,cid,gradid;
int grade;


};

void bubblesort (Student a[], int n)
{
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(\"Chapter11_InputFile.txt\");

fstream output(\"Chapter11_OutputFile.txt\");


while(file>>n>>Rate)
{

for (int j = 0; j < n; ++j)
{
  
file>>fname>>lname>>sid>>paid>>no_of_course;
output<<\"Student Name: \"<

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

  
}
}

else
{
  
cout<<\"Course No\\tCourse Name\\t\\tCredits\\t\\tGrade\ \";

  
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)
{
  
cout<   
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;
  
}
  
}
cout<<\"Total number of credits : \"<   
cout<<\"Mid-Semister GPA: \"< }
}
}
file.close();
output.close();
  
return 0;
}

Solution

#include
using namespace std;
class Student
{
public:string cname,cid,gradid;
int grade;

};
void bubblesort (Student a[], int n)
{
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(\"Chapter11_InputFile.txt\");
fstream output(\"Chapter11_OutputFile.txt\");

while(file>>n>>Rate)
{
for (int j = 0; j < n; ++j)
{
  
file>>fname>>lname>>sid>>paid>>no_of_course;
output<<\"Student Name: \"<
if(paid==\'N\')
{
cout<<\"Grades have been held for nonpayment of the tuition\"< cout<<\"Amount to be paid tuition rate per credit hour \"< for (int i = 0; i < no_of_course; ++i)
{
string cname,cid,gradid;
int grade;
  
  
file>>cname>>cid>>grade>>gradid;
  
}
}
else
{
  
cout<<\"Course No\\tCourse Name\\t\\tCredits\\t\\tGrade\ \";
  
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)
{
  
cout<   
total_credits+=s[i].grade;
if(s[i].gradid.compare(\"A\")==4)
{
gpa+=4;
  
}
if(s[i].gradid.compare(\"B\")==3)
{
gpa+=3;
  
}
if(s[i].gradid.compare(\"C\")==2)
{
gpa+=2;
  
}
if(s[i].gradid.compare(\"D\")==1)
{
gpa+=1;
  
}
  
}
cout<<\"Total number of credits : \"<   
cout<<\"Mid-Semister GPA: \"< }
}
}
file.close();
output.close();
  
return 0;
}

This programming example further illustrates the concepts of inheritance and composition. The mid-semester point at your local university is approaching. The re
This programming example further illustrates the concepts of inheritance and composition. The mid-semester point at your local university is approaching. The re
This programming example further illustrates the concepts of inheritance and composition. The mid-semester point at your local university is approaching. The re
This programming example further illustrates the concepts of inheritance and composition. The mid-semester point at your local university is approaching. The re
This programming example further illustrates the concepts of inheritance and composition. The mid-semester point at your local university is approaching. The re

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site