In: Computer Science
following:
It prints the student’s id and GPA. If the student’s GPA is greater than or equal to 3.8, it prints “an honor student”.
#include<bits/stdc++.h>
using namespace std;
class Course // creation of class
{
int *num_of_stud; // int pointer to hold no of students
int* id = NULL; // int pointer to hold the array of ids
double* gpa = NULL; // int pointer to hold the grades array
Course(int n) // constructor which initializes all variables and arrays
{
*num_of_stud = n;
id = new int[n];
gpa = new double[n];
for(int i=0; i<n; i++)
{
id[i] = 0;
gpa[i] = 0.0;
}
}
void read_data() // function to read the data
{
for(int i=0; i<*num_of_stud; i++)
{
cin>>id[i];
cin>>gpa[i];
}
}
void print_info() // function to print the data according to the question
{
for(int i=0; i<*num_of_stud; i++)
{
cout<<"ID of student "<<i+1<<" : "<<id[i]<<endl;
cout<<"Grade : "<<gpa[i]<<endl;
if(gpa > 3.8)
cout<<"an honour student"<<endl;
}
}
};
int main()
{
// write your code inside main() accordingly
}
here is the code for the above problem
created the required class
declared all necessary pointer variables and arrays
defined each asked function as well
can tell me if you want me to write something in main() as well