Implementing member functions

I've been trying to implement the member functions given structure. How would I go about implementing the member function? Would I call it in the main? Thanks for looking and helping!


#include <iostream>
using namespace std;
struct student {
int credit[100], numCourses;
char grade [100];
void setGrades(int* creditIn, char* gradeIn, int numIn);
void addGrade (int creditIn, char gradeIn );
double getGPA();
};
int main() {
const int numStart = 5;
int startCredit[numStart] = { 3 , 4 , 3 , 2 , 4 };
char startGrade [numStart] = { 'A', 'A', 'B', 'C', 'B' };
student me, you;
me.setGrades(startCredit, startGrade, numStart);
you.setGrades(startCredit, startGrade, numStart);
me .addGrade(4, 'C'); me .addGrade(3, 'F');
you.addGrade(2, 'B'); you.addGrade(4, 'A');
cout << " I have a " << me .getGPA() << " GPA" << endl;
cout << "You have a " << you.getGPA() << " GPA" << endl;
return 0;
}
You can either define the implementation inline by replacing the semicolons after each function with curly braces, or you can define the functions in global scope by prefixing their name with student:: - choose whichever method you prefer.
Topic archived. No new replies allowed.