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

a) Define a class named Student. It must have the following private member varia

ID: 3843908 • Letter: A

Question

a) Define a class named Student. It must have the following private member variables

i) A long integer to store ID

ii) A string to store name

iii) A double to store GPA Write a constructor function that allows initializing while creating an object

b) In addition to the constructor functions

i) Add an accessor function of void return type to access the value of all three private member variables. Your accessor function will display the value of the variables inside function.

ii) Add a mutator function of void return type to set/change the value of all three private member variables. Your mutator function will prompt the user for the value of the member variables.

c) Create two objects in your main function—one with values for the initializing/parametrized constructor function, and one without. Use your name, student ID and GPA value of 4.0 to initialize the object using the initializing constructor. Demonstrate the use of accessor function for the first object, and both accessor and mutator functions for the second object.

Here is my code so far. How can I change this to meet the criteria above? I need to make the 3 get functions be 1 void function that prompts the user to enter in values for each variable.

Explanation / Answer

#include <iostream>
#include <cstring>
using namespace std;

class Student
{
public:
Student();
Student(unsigned long int id, string name, double gpa);
void setVars();
void getVars();
private:
unsigned long int id;
string name;
double gpa;
};

Student::Student()//default constructor
{
id = 0;
name = " ";
gpa = 0.0;
}

Student::Student(unsigned long int id, string name, double gpa)//argument constructor
{
this->id = id;
this->name = name;
this->gpa = gpa;
}

void Student::setVars() // mutator
{
unsigned long int id;
string name;
double gpa;
  
  
cout<<" Enter the value of id : ";
cin>>id;
this->id= id;
  
  
cout<<" Enter the value of name : ";
getline(cin,name);
this->name=name;
  
cout<<" Enter the value of gpa : ";
cin>>gpa;
this->gpa=gpa;
}

void Student::getVars() //accessor
{
cout<<" ID : "<<id;
cout<<" Name : "<<name;
cout<<" GPA : "<<gpa;
}

int main()
{
Student student1(12345678, "First Last", 4.0);
  
cout<<" Student 1: ";
student1.getVars();

Student student2;

student2.setVars();
  
cout<<" Student 2: ";
student2.getVars();
  


return 0;
}

output:


Student 1:
ID : 12345678
Name : First Last
GPA : 4
Enter the value of id : 12345679
Enter the value of name : John Smith
Enter the value of gpa : 4.5
Student 2:
ID : 12345679
Name : John Smith
GPA : 4.5