Question
EDIT: PLEASE ANSWER MY QUESTION I DON'T HAVE MUCH TIME, JUST WRITE A NEW CODE SIMILAR TO MINE IF U WANT! Hey! i've see multiple
EDIT: PLEASE ANSWER MY QUESTION I DON'T HAVE MUCH TIME, JUST WRITE A NEW CODE SIMILAR TO MINE IF U WANT!
Hey! i've see multiple answers to this question but none have met my level that i want(i need much simpler), so here's the question
Write a C++ program(as simple as possible using only struct/classes, setters/getters, pointers, arrays and all the simple stuff (NO libraries/vectors/override)) : Consider that a system has two entities, Student and Course. The student has the following properties: student name, number, SSN and GPA. Similarly, the course has the following properties: course name, course number, credit hours and a set of students who are currently registering on the course.
need to implement the following :
- In course, the number of students that are registering this course is decided at the time when instantiating the course object.
- Need a boolean function to compare 2 students objects and The statement is true if the objects have the same GPA and Name.
- Write a getStudentpByName method in class course that takes a student name and returns a list of all students who share the same name.
- Write a getStudentByGPA method in class course that takes a GPA and returns a list of Students in that course who have the same GPA.
And most importantly i need also to implement everything in Main and make sure everything works
Now i wrote a code myself(down below) but it's obviously not complete but it has no error. So all is required is branch 2 + check my code and edit it if needed + implementing everything in main(calling branches 2,3,4 in main and show they work properly)
that's all thanks <3
#include
class Student{
char name[20]; int stno; int ssn; double gpa; public: Student(){ }
Student (char name[],int stno,int s, double g){
strcpy(this->name,name); this->stno=stno; this->ssn=s; //optional this->gpa=g; //optional } char *getName(){ return name; }
void setName(char n[]){ strcpy(name,n); } void setStno(int i){ stno=i; }
int getStno(){ return stno; } void setSsn(int s){ ssn=s; }
int getSsn(){ return ssn; } void setGPA(double g){ gpa=g; }
double getGPA(){ return gpa; }
};
class Course { char cname[20]; int cno; int CH; Student *s; int n; public:
Course(char cname[],int cno,int CH, int n){
strcpy(this->cname,cname);
this->cno=cno;
s=new Student [n];
char sname[20]; int stno;int ssn; double gpa;
for (int i=1;i<=n;i++){
cout <<"Enter values for student #"<
cin>>sname>>stno>>ssn>>gpa;
s[i].setName(sname); s[i].setStno(stno); s[i].setSsn(ssn); s[i].setGPA(gpa);
} }
char *getName(){ return cname; }
void setName(char n[]){ strcpy(cname,n); }
void setCno(int c){ cno=c; }
int getCno(){ return cno; } void setCH(int d){ CH=d; }
int getCH(){ return CH; } Student * getStudent(){ return s; }
void setStudent(char sname[], int sno,int ssn, double gpa){ delete s; s = new Student(sname,sno,ssn,gpa); } Student *getStudentByName(char *n1){ int c=0; Student *ar; for (int i=0;i if(strcmp(s[i].getName(),n1)==0) c++; ar= new Student[c+1]; for (int i=0,j=0;i if(strcmp(s[i].getName(),n1)==0){ ar[j]=s[i]; j++; } return ar; } Student *getStudentByGPA(double g) {
int c=0;
for (int i=0;i
if (s[i].getGPA()>=g)
c++;
Student *temp = new Student[c+1];
int j=0;
for (int i=0;i
if (s[i].getGPA()==g)
temp[j++]=s[i];
Student *ss=new Student("noname",0,0,-1);
temp[j]=*ss;
return temp; } };
int main() { Course c1("CSE",1,3,3);
return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started