Need help accessing variables of a member array I need to ca

Need help accessing variables of a member array. I need to calculate the gpa of a set number of grades. I have already read the elements to the array \"courses\" using function: void Student::readCourseArray(), (I think correctly) but can\'t figure out how to get access to the \"letterGrade\" elements in order to calculate gpa. Any help is greatly appreciated.

Insturctions for the gpa function:

Define the function computeGPA()

Should not return a value

Should not print anything

Go through the array and compute the student’s GPA. Here’s how to calculate the GPA:Calculate the points for each course by multiplying the credit hour for that course by the point grade for the course.

A letter grade can be converted to point grade. A point grade is the numerical value for a letter grade. A is 4, B is 3, C is 2, D is 1, F is 0.

GPA is (total of all points)/(total of all credit hours)

For example, suppose a student had these grades:

A in a 3-hour course

B in a 3-hour course

A in a 2-hour course

The GPA for this student would be calculated like this:

((A * 3) + (B * 3) + (A * 2) ) / (3 + 3 + 2) =

convert the letter grades to point grades:

((4 * 3) + (3 * 3) + (4 * 2) ) / (3 + 3 + 2) =

and do math:

(12 + 9 + 8) / (3 + 3 + 2) = 29 / 8 = 3.625 GPA

What I have so far:

#include
#include
using namespace std;
class Course
{
  
public:
   // Public read functions
   void readCourseNum(int n) {courseNumber = n;}
   void readCreditHours(double c) { creditHours = c; }
   void readCourseName(string n) { courseName = n; }
   void readLetterGrade(char g) { letterGrade = g; }
  
private:
   int courseNumber;
   double creditHours;
   string courseName;
   char letterGrade;
};
class Student
{
private:
   string firstName, lastName, A_Number;
   int numCourses;
   double gpa;
   Course *courses;
public:
  
   Student();
   ~Student();
   double totalGradePoints();
   int getNumCourses() { return numCourses; };
   void computeGPA();
   void readStudent();
   void readCourseArray();
   void setFirstName(string n) { firstName = n; }
   void setLastName(string l) { lastName = l; }
   void setA_Number(string a) { A_Number = a; }
   void setNumCourses(int num) { numCourses = num; }
};
Student::Student()
{
   firstName = \" \";
   lastName = \" \";
   A_Number = \" \";
   numCourses = 0;
   gpa = 0.0;
   courses = NULL;
}
Student::~Student()
{
   delete [] courses;
}
void Student::computeGPA()
{
}
void Student::readStudent()
{
   cout << \"Enter student A-number: \";
   cin >> A_Number;
   setA_Number(A_Number);
   cout << \"Enter student first name: \";
   cin >> firstName;
   setFirstName(firstName);
   cout << \"Enter student last name: \";
   cin >> lastName;
   setLastName(lastName);
   cout << \"Enter student number of courses: \";
   cin >> numCourses;
   setNumCourses(numCourses);
}
void Student::readCourseArray()
{ // Dynamically allocated array for course information
   courses = new Course[numCourses];
   int num;
   double cHours;
   string cName;
   char grade;
   for (int i = 0; i < numCourses; i++)
   {
       cout << \"Enter class \" << i + 1 << \" number: \";
       cin >> num;
       courses[i].readCourseNum(num);      // call to public read function
       cout << \"Enter class \" << i + 1 << \" name: \";
       cin >> cName;
       courses[i].readCourseName(cName);
       cout << \"Enter class \" << i + 1 << \" hours: \";
       cin >> cHours;
       courses[i].readCreditHours(cHours);
       cout << \"Enter class \" << i + 1 << \" grade: \";
       cin >> grade;
       courses[i].readLetterGrade(grade);
   }
}
int main()
{
   Student stu;
   double gradePoints;
   stu.readStudent();
   stu.readCourseArray();


  
   return 0;
}

double Student::totalGradePoints()
{
   int num = getNumCourses();
   for (int i = 0; i < num; i++)
   {
       if (courses[i].letterGrade == \'A\')
   }
   return 0.0;
}

Solution

// C++ code
// you cannot access memeber of other class until derived from other class or declared public


#include <fstream> // file processing
#include <iostream> // cin and cout
#include <cctype> // toupper
#include <iomanip> // setw
#include <cstring> // cstring functions strlen, strcmp, strcpy stored in string.h
#include <string.h> // string class

#define stricmp strcasecmp
#define strnicmp strncasecmp

using namespace std;
class Course
{
  
public:
// Public read functions
void readCourseNum(int n) {courseNumber = n;}
void readCreditHours(double c) { creditHours = c; }
void readCourseName(string n) { courseName = n; }
void readLetterGrade(char g) { letterGrade = g; }
  
public:
int courseNumber;
double creditHours;
string courseName;
char letterGrade;
};

class Student : public Course
{
private:
string firstName, lastName, A_Number;
int numCourses;
double gpa;
Course *courses;
public:
  
Student();
~Student();
double totalGradePoints();
int getNumCourses() { return numCourses; };
double computeGPA();
void readStudent();
void readCourseArray();
void setFirstName(string n) { firstName = n; }
void setLastName(string l) { lastName = l; }
void setA_Number(string a) { A_Number = a; }
void setNumCourses(int num) { numCourses = num; }
};

Student::Student()
{
firstName = \" \";
lastName = \" \";
A_Number = \" \";
numCourses = 0;
gpa = 0.0;
courses = NULL;
}
Student::~Student()
{
delete [] courses;
}

double Student::computeGPA()
{
int totalhours = 0;
int num = getNumCourses();
for (int i = 0; i < num; i++)
{
totalhours = totalhours + courses[i].creditHours;
}

gpa = gpa/totalhours;
}

void Student::readStudent()
{
cout << \"Enter student A-number: \";
cin >> A_Number;
setA_Number(A_Number);
cout << \"Enter student first name: \";
cin >> firstName;
setFirstName(firstName);
cout << \"Enter student last name: \";
cin >> lastName;
setLastName(lastName);
cout << \"Enter student number of courses: \";
cin >> numCourses;
setNumCourses(numCourses);
}
void Student::readCourseArray()
{ // Dynamically allocated array for course information
courses = new Course[numCourses];
int num;
double cHours;
string cName;
char grade;
for (int i = 0; i < numCourses; i++)
{
cout << \"Enter class \" << i + 1 << \" number: \";
cin >> num;
courses[i].readCourseNum(num); // call to public read function
cout << \"Enter class \" << i + 1 << \" name: \";
cin >> cName;
courses[i].readCourseName(cName);
cout << \"Enter class \" << i + 1 << \" hours: \";
cin >> cHours;
courses[i].readCreditHours(cHours);
cout << \"Enter class \" << i + 1 << \" grade: \";
cin >> grade;
courses[i].readLetterGrade(grade);
}
}

double Student::totalGradePoints()
{
gpa = 0;
int num = getNumCourses();
for (int i = 0; i < num; i++)
{
if (courses[i].letterGrade == \'A\')
gpa = gpa + 4*courses[i].creditHours;
else if (courses[i].letterGrade == \'B\')
gpa = gpa + 3*courses[i].creditHours;
else if (courses[i].letterGrade == \'C\')
gpa = gpa + 2*courses[i].creditHours;
else if (courses[i].letterGrade == \'D\')
gpa = gpa + 1*courses[i].creditHours;
else if (courses[i].letterGrade == \'F\')
gpa = gpa + 0*courses[i].creditHours;


}
return gpa;
}


int main()
{
Student stu;
double gradePoints;
stu.readStudent();
stu.readCourseArray();

double gpa = stu.totalGradePoints();
gpa = stu.computeGPA();


cout << \"GPA: \" << gpa << endl;
return 0;
}


/*
output:

Enter student A-number: 32
Enter student first name: ayush
Enter student last name: verma
Enter student number of courses: 3
Enter class 1 number: 11
Enter class 1 name: akash
Enter class 1 hours: 34
Enter class 1 grade: A
Enter class 2 number: 12
Enter class 2 name: john
Enter class 2 hours: 12
Enter class 2 grade: B
Enter class 3 number: 13
Enter class 3 name: eoin
Enter class 3 hours: 23
Enter class 3 grade: C
GPA: 3.15942


*/

Need help accessing variables of a member array. I need to calculate the gpa of a set number of grades. I have already read the elements to the array \
Need help accessing variables of a member array. I need to calculate the gpa of a set number of grades. I have already read the elements to the array \
Need help accessing variables of a member array. I need to calculate the gpa of a set number of grades. I have already read the elements to the array \
Need help accessing variables of a member array. I need to calculate the gpa of a set number of grades. I have already read the elements to the array \
Need help accessing variables of a member array. I need to calculate the gpa of a set number of grades. I have already read the elements to the array \
Need help accessing variables of a member array. I need to calculate the gpa of a set number of grades. I have already read the elements to the array \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site