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

C++ program: please start off with using this private class ^_^ ________________

ID: 670285 • Letter: C

Question

C++ program: please start off with using this private class ^_^ _________________ class Students { Private: char name[20]; char grade [10]; float Gpa; public: ------- -------
}; ____________ Implement an object-oriented student database using the given data. Each line in the data file should contain a student’s name in col. 1-20, class standing in col. 21-30, and GPA in col. 31-34. Use the following data in your input file. ______________________________ NAME CLASS GPA _____________________________ Koran, Korn Junior 3.50    Smith, Sam Junior 2.14 Johnson, Jim Junior 3.05 Johnson, Jane Junior 3.75 Potter, Pam Senior 2.98 Brown, Bill Sophomore 2.55 Crooks, Cathy Freshman 1.99 Gregg, Howard Freshman 2.44
Nicholas, Judy Senior 3.69 White, Bob Sophomore 1.64 ____________________________

** Your program should be able to read from a file the above data into an array and sort the array by the student’s name in an ascending order. Selection sort algorithm is strongly recommended on the array of objects.
**And also the record office would like to have a sorted class list for each class, freshman, sophomore, junior, and senior.
** Print out the following: A. The sorted master list with the average GPA of the entire college. B. The freshman list with the average GPA of the freshmen.
C. The sophomore list with the average GPA of the sophomores.
D. The junior list with the average GPA of the juniors.
E. The senior list with the average GPA of the seniors. Make sure that you print the original data first. C++ program: please start off with using this private class ^_^ _________________ class Students { Private: char name[20]; char grade [10]; float Gpa; public: ------- -------
}; ____________ Implement an object-oriented student database using the given data. Each line in the data file should contain a student’s name in col. 1-20, class standing in col. 21-30, and GPA in col. 31-34. Use the following data in your input file. ______________________________ NAME CLASS GPA _____________________________ Koran, Korn Junior 3.50    Smith, Sam Junior 2.14 Johnson, Jim Junior 3.05 Johnson, Jane Junior 3.75 Potter, Pam Senior 2.98 Brown, Bill Sophomore 2.55 Crooks, Cathy Freshman 1.99 Gregg, Howard Freshman 2.44
Nicholas, Judy Senior 3.69 White, Bob Sophomore 1.64 ____________________________

** Your program should be able to read from a file the above data into an array and sort the array by the student’s name in an ascending order. Selection sort algorithm is strongly recommended on the array of objects.
**And also the record office would like to have a sorted class list for each class, freshman, sophomore, junior, and senior.
** Print out the following: A. The sorted master list with the average GPA of the entire college. B. The freshman list with the average GPA of the freshmen.
C. The sophomore list with the average GPA of the sophomores.
D. The junior list with the average GPA of the juniors.
E. The senior list with the average GPA of the seniors. Make sure that you print the original data first. C++ program: please start off with using this private class ^_^ _________________ class Students { Private: char name[20]; char grade [10]; float Gpa; public: ------- -------
}; ____________ Implement an object-oriented student database using the given data. Each line in the data file should contain a student’s name in col. 1-20, class standing in col. 21-30, and GPA in col. 31-34. Use the following data in your input file. ______________________________ NAME CLASS GPA _____________________________ Koran, Korn Junior 3.50    Smith, Sam Junior 2.14 Johnson, Jim Junior 3.05 Johnson, Jane Junior 3.75 Potter, Pam Senior 2.98 Brown, Bill Sophomore 2.55 Crooks, Cathy Freshman 1.99 Gregg, Howard Freshman 2.44
Nicholas, Judy Senior 3.69 White, Bob Sophomore 1.64 ____________________________

** Your program should be able to read from a file the above data into an array and sort the array by the student’s name in an ascending order. Selection sort algorithm is strongly recommended on the array of objects.
**And also the record office would like to have a sorted class list for each class, freshman, sophomore, junior, and senior.
** Print out the following: A. The sorted master list with the average GPA of the entire college. B. The freshman list with the average GPA of the freshmen.
C. The sophomore list with the average GPA of the sophomores.
D. The junior list with the average GPA of the juniors.
E. The senior list with the average GPA of the seniors. Make sure that you print the original data first. C++ program: please start off with using this private class ^_^ _________________ class Students { Private: char name[20]; char grade [10]; float Gpa; public: ------- -------
}; ____________ Implement an object-oriented student database using the given data. Each line in the data file should contain a student’s name in col. 1-20, class standing in col. 21-30, and GPA in col. 31-34. Use the following data in your input file. ______________________________ NAME CLASS GPA _____________________________ Koran, Korn Junior 3.50    Smith, Sam Junior 2.14 Johnson, Jim Junior 3.05 Johnson, Jane Junior 3.75 Potter, Pam Senior 2.98 Brown, Bill Sophomore 2.55 Crooks, Cathy Freshman 1.99 Gregg, Howard Freshman 2.44
Nicholas, Judy Senior 3.69 White, Bob Sophomore 1.64 ____________________________

** Your program should be able to read from a file the above data into an array and sort the array by the student’s name in an ascending order. Selection sort algorithm is strongly recommended on the array of objects.
**And also the record office would like to have a sorted class list for each class, freshman, sophomore, junior, and senior.
** Print out the following: A. The sorted master list with the average GPA of the entire college. B. The freshman list with the average GPA of the freshmen.
C. The sophomore list with the average GPA of the sophomores.
D. The junior list with the average GPA of the juniors.
E. The senior list with the average GPA of the seniors. Make sure that you print the original data first.

Explanation / Answer

#include <iostream>
#include <fstream>
using namespace std;
struct student
{
char name[20];
char clas[10];
float gpa;
};

int main()
{
inti,j=0;
string line="Koran, Korn Junior 3.50";
ifstream infile("data.txt");
struct student list[100];
char buf[10];
while(getline(infile, line))
{
for(i=0;i<20;i++)
list[j].name[i]=line[i];
list[j].name[i]='';
for(i=0;i<10;i++)
list[j].clas[i]=line[i+20];
list[j].clas[i]='';
for(i=0;i<4;i++)
buf[i]=line[i+30];
buf[i]='';
list[j].gpa=atof(buf);
cout<<list[j].name<<endl<<endl;
cout<<list[j].clas<<endl;
cout<<list[j].gpa<<endl;
j++;
}
  
printmaster(list,j);
printFreshman(list,j);
printSophomore(list,j);
printJunior(list,j);
printSenior(list,j);   
}

void sort(struct student list[], int n) {
int i, j, minIndex;
struct student tmp;
for (i = 0; i < n - 1; i++) {
minIndex = i;
for (j = i + 1; j < n; j++)
if (strcmp(list[j].name,list[minIndex].name)<0)
minIndex = j;
if (minIndex != i) {
tmp = list[i];
list[i] = list[minIndex];
list[minIndex] = tmp;
}
}
}

void printmaster(struct student list, int n)
{
float sum = 0;
for(int i=0;i<n;i++)
{
cout<<list[i].name<<" ";
cout<<list[i].clas<<" ";
cout<<list[i].gpa<<endl;
sum+=list[i].gpa;
}
cout<<"average Gpa of all ="<<sum/n<<endl;;
}
void printFreshman(struct student list, int n)
{
float sum = 0;
for(int i=0;i<n;i++)
{
if(strcmp(list[i].class,"Freshman ")==0)
{
cout<<list[i].name<<" ";
cout<<list[i].clas<<" ";
cout<<list[i].gpa<<endl;
sum+=list[i].gpa;
}
}
cout<<"average Gpa of Freshman ="<<sum/n<<endl;;
}
void printSophommmore(struct student list, int n)
{
float sum = 0;
for(int i=0;i<n;i++)
{
if(strcmp(list[i].class,"Sophomore ")==0)
{
cout<<list[i].name<<" ";
cout<<list[i].clas<<" ";
cout<<list[i].gpa<<endl;
sum+=list[i].gpa;
}
}
cout<<"average Gpa of Sophomore ="<<sum/n<<endl;;
}
void printJunior(struct student list, int n)
{
float sum = 0;
for(int i=0;i<n;i++)
{
if(strcmp(list[i].class,"Junior ")==0)
{
cout<<list[i].name<<" ";
cout<<list[i].clas<<" ";
cout<<list[i].gpa<<endl;
sum+=list[i].gpa;
}
}
cout<<"average Gpa of Junior ="<<sum/n<<endl;;
}
void printSenior(struct student list, int n)
{
float sum = 0;
for(int i=0;i<n;i++)
{
if(strcmp(list[i].class,"senior ")==0)
{
cout<<list[i].name<<" ";
cout<<list[i].clas<<" ";
cout<<list[i].gpa<<endl;
sum+=list[i].gpa;
}
}
cout<<"average Gpa of senior ="<<sum/n<<endl;;
}

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