Well ...this is a real challenge .....i got everything else working OK...but ...
I have to get the average and maximum value out of a group of people thru two functions .I have problems passing value to function and processing it after is there ...
Any help will be very appreciated.
This is my code :
#include <iostream>
#include <cstdlib>
using namespace std;
//functions prototypes
float averagegrade(St udent[],int)
int maxgradestudent (Student [],int)
//classes declaration
class Person
{
public:
Person(void);
~Person(void);
void Setfirstname(ch ar []);
char * Getfirstname(vo id);
void Setlastname(cha r []);
char * Getlastname(voi d);
private:
char Firstname[30];
char Lastname [30];
};
class Student : public Person
{
public:
Student(void);
~Student(void);
void Setnid(char[]);
char * getNID(void);
void SetGrade(float) ;
float GetGrade(void);
private:
float grade;
char NID [30];
};
void main()
{
Student studentInfo[100];
float studentGrade;
int i,numStudents;
char firstName[30];
char lastName[30];
char NID [30];
float ave =0.0;
int maxgrade;
//check for errors
do
{
cout << "Enter the number of students:";
cin >> numStudents;
if ((numStudents < 1) || (numStudents > 100))
{
cout << "Incorrect value. Try again...\n";
}
} while ((numStudents < 1) || (numStudents > 100));
//Enter info for students:
for (i=0;i<numStude nts;i++)
{
cout << "Student #"<<i+1 << endl;
cout << " Enter the Student's first name :";
cin >> firstName;
cout << " Enter the Student's last name :";
cin >> lastName;
cout << "Enter the student's nid:";
cin >> NID;
cout << "Enter the student's grade:";
cin >> studentGrade;
//send data to functions
studentInfo[i].Setfirstname(f irstName);
studentInfo[i].Setlastname(la stName);
studentInfo[i].Setnid(NID);
studentInfo[i].SetGrade(stude ntGrade);
//average call fuction (i dont know if is correct):
ave= averagegrade(st udentInfo[i],ave);
//maximum call function :
maxgrade= maxgradestudent (studentInfo[i],maxgrade); }
cout << "\n\n";
for (i=0;i<numStude nts;i++)
{
cout << "The average grade is " << studentInfo[i].GetGrade() << endl;
cout << "The student with the highest grade is :" << studentInfo[i].Getfirstname() <<" ";
cout << studentInfo[i].Getlastname()< < "NID:"<< studentInfo[i].getNID()<<"gra de:"<<studentIn fo[i].GetGrade()<<"\ n";
}
//functions
//constructor
}
Person::Person( void)
{
strcpy(Firstnam e,"");
}
//destructor
Person::~Person (void)
{
strcpy(Firstnam e,"");
}
//function for first name
void Person::Setfirs tname(char firstname[])
{
strcpy(Firstnam e,firstname);
}
//function for Last name
void Person::Setlast name(char lastname[])
{
strcpy(Lastname ,lastname);
}
char * Person::Getfirs tname(void)
{
return Firstname;
}
char * Person::Getlast name(void)
{
return Lastname;
}
//nid function
Student::Studen t(void)
{
strcpy (NID,"");
}
Student::~Stude nt(void)
{
strcpy (NID,"");
}
void Student::Setnid (char Nid[])
{
strcpy (NID,Nid);
}
char * Student::getNID (void)
{
return NID;
}
//function for grade:
void Student::SetGra de(float studentGrade)
{
grade = studentGrade;
}
float Student::GetGra de(void)
{
return grade;
}
//function for average grade:
?