Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

QUESTION: Create a class named Student Add a static attribute named numStudents

ID: 3813065 • Letter: Q

Question

QUESTION:

Create a class named Student

Add a static attribute named numStudents

Add private attributes with public setters (only) for:

firstName (String)

lastName (String)

grades (int[4])

Create public methods:

getGPA that returns a double of the average of the values in the grades array (assume each student takes all four classes)

Create a default constructor that increments numStudents

Created an overloaded constructor that takes three arguments (fName, lName, int[]) and assigns them to the local private variables. Be sure to call the default constructor in the first line of the overloaded constructor.

Create student1 Object by calling the overloaded constructor for the student Jack Willson. Set the grades array with the values {4, 2, 3, 3}

Include a method to Display data members of Student Object.

Explanation / Answer

#include<bits/stdc++.h>
using namespace std;
class Student{
   public:
   static int numStudents;
       string firstName;
       string lastName;
       int grades[4];
  
       Student(){
           numStudents++;
       }
      
       Student(string fName, string lName, int a[]){
           firstName = fName;
           lastName = lName;
           grades[0] = a[0];
           grades[1] = a[1];
           grades[2] = a[2];
           grades[3] = a[3];
           Student();
       }
      
       double getGpa(){
           return ((grades[0] + grades[1] + grades[2] + grades[3])/4);
          
       }
      
       string getFName(){
           return this.firstName;
      
       }
      
       string getLName(){
           return this.lastName;
       }
      
      
};

int Student::numStudents = 0;

int main(){
   int b[] = {4, 2, 3, 3};
   Student student1("Jack", "Willson", b);
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote