Please, help me and check my program:i want to use the maxAge() member function to get the max age entered from the function MAIN using the while loops which i stored into the object students.Main.cpp, Age.h and Age.cpp included.
Practice.cpp
#include<iostream>
using namespace std;
#include<string>
#include "Age.h"
int main (){
Age students;
int age;
int sum=0;
int max =0;
int min =0;
do{ cout << "Enter the age of the students here " << endl;
cin >> age;
students.setAge(age);
sum=sum+students.getAge();
if(students.getAge()>max){
//max= students.mAge(); **this is working but i don,t wanna use it.**
}
max = students.maxAge(students);
}while(age!=0);
cout << "The total age of the students are " << sum << endl;
students.ageAverage(sum);
cout << " The biggest Age in the roll is " << max << endl;
system("pause");
return 0;
}
Age.h
#include<iostream>
#include<string>
using namespace std;
class Age
{
private :
int age;
public:
Age(void);
void setAge(int age);
int getAge();
void ageAverage(int sum);
int maxAge(Age object);
int minAge(Age object);
};
Age.cpp
#include<iostream>
#include<string>
#include "Age.h"
Age::Age(void) {
}
void Age::setAge(int age){
this->age=age;
}
int Age::getAge(){
return age;
}
void Age::ageAverage(int sum){
int average;
average=sum/2;
cout << "The Average Age is " << average << endl;
}
int Age::maxAge(Age object){
int max=0;
do{
if(object.getAge()>max){
max=object.getAge();
}
}while(object.getAge()!=0);
return max;
}
Thanks
Aucun commentaire:
Enregistrer un commentaire