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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.