Hey guys i'm new to this forum ;so here's the thing i need help with my code. I am required to :
Add to the class EECE230Student a private static variable which is used to count the number of objects generated. For this purpose, you need to perform the following:
a. Declare and initialize the variable and add a reader to read this variale .
b. Modify the constructors as needed and add a destructor .
c. Add also a copy constructor which uses a call by reference.
please guys this is really urgent.
#include <iostream>
using namespace std;
class EECE230Student {
int id;
int section;
int quiz1;
int quiz2;
int finalExam;
static int count;
public:
EECE230Student();
EECE230Student(int id, int section);
void set(static int counter ){
counter = count;
}
void set(int iden, int sect);
void set(int quizOne, int quizTwo, int finalTest);
int get_id();
int get_section();
int get_quiz1();
int get_quiz2();
int get_finalExam();
double quizAverage();
double finalGrade();
void displayGrade();
};
void bubble(EECE230Student a[],int size );
void print (EECE230Student a[],int size );
double classAverage (EECE230Student a[]);
int main(){
EECE230Student ast[4];
ast[0].set(1,1);
ast[0].set(10,20,30);
ast[1].set(2,1);
ast[1].set(40,50,60);
ast[2].set(3,1);
ast[2].set(70,80,90);
ast[3].set(4,1);
ast[3].set(35,55,75);
for(int i=0; i<4 ; i++){
ast[i].displayGrade();
}
bubble(ast,4);
print(ast,4);
cout << "class average :" << classAverage(ast) << endl;
system("pause");
return 0;
}
EECE230Student::EECE230Student(){
quiz1=0;
quiz2=0;
finalExam=0;
}
EECE230Student::EECE230Student(int id, int section){
id=0;
section=0;
}
void EECE230Student::set(int iden, int sect){
id=iden;
section=sect;
}
void EECE230Student::set(int quizOne, int quizTwo, int finalTest){
quiz1=quizOne;
quiz2=quizTwo;
finalExam=finalTest;
}
int EECE230Student::get_id(){
return id;
}
int EECE230Student::get_section(){
return section;
}
int EECE230Student::get_quiz1(){
if(quiz1 < 0 && quiz1 > 100)
return false;
return quiz1;
}
int EECE230Student::get_quiz2(){
if(quiz2 < 0 && quiz2 > 100)
return false;
return quiz2;
}
int EECE230Student::get_finalExam(){
if(finalExam < 0 && finalExam > 100 )
return false;
return finalExam;
}
double EECE230Student::quizAverage(){
return (quiz1+quiz2)/2.0;
}
double EECE230Student::finalGrade(){
return (quizAverage()+finalExam)/2.0;
}
void EECE230Student::displayGrade(){
cout << " id: " << id << " final grade : " << finalGrade() << endl;
}
void bubble(EECE230Student a[],int size ){
for(int i=0; i<4 ;i++ )
for(int j = i+1 ; j<size ; j++ )
if(a[i].finalGrade() > a[j].finalGrade())
swap(a[i],a[j]);
}
void print (EECE230Student a[],int size)
{
for(int k=0; k<size;k++)
cout<< a[k].finalGrade() << " " ;
}
double classAverage (EECE230Student a[]){
double sum=0;
double average;
for(int i=0; i<4; i++ ){
sum = sum + a[i].finalGrade();
}
average = sum / 4.0;
return average;
}