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

Define alpha class named Student with private member variables long integer to s

ID: 3841474 • Letter: D

Question

Define alpha class named Student with private member variables long integer to store ID string to store name A double to store GPA Write a constructor function that allows initializing while creating an object. In addition to the constructor functions 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. Add alpha 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. Create two objects in your main function 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 part B different file It is required that all the IDs of the students be changed to 9 digits. The administration decides to do this by 100000000 to each ID. So a student with ID XXXXXXXX will now have ID 1XXXXXXXX. Assume all IDs before this change as 8 digits long or smaller. Modify your program in to accomplish this in the following two w Use a member function of void return type arid name update. Use an external nonmember function of void return type and name updgate, defined outside class. This external function CANNOT access the function you just created in (a). You'll need separate and matgator function to get and set the values for ID. Retain the code from to create two objects in your main function. Update the ID of the two Student objects you just created-use one function for each object. Use the access for function you created in to demonstrate that you have updated the ID. FILE CONTENTS HW1Probl.dat file contents John Harris 50000.00 113785 Lisa Smith 75000.487 254785 Adam Johnson 68500.10 321258 Sheila Smith 150000.50 165478 Tristen Major 75800.76 102596 Yannic Lennart 58000.55 369854 Lorena Emil 43000.00 225478 Tereza Santeri 48000.001 136478

Explanation / Answer

Part A:

#include <iostream>
#include <string>

using namespace std;

class Student {
private:
long ID;
string name;
float GPA;
public:
Student(long ID, const char name[], double GPA) {
this->ID = ID;
this->name = name;
this->GPA =GPA;
}
void accessor() {
cout << "ID: " << ID << endl;
cout << "Name: " << name << endl;
cout << "GPA: " << GPA << endl;
}
void mutator() {
cout << "Enter new ID: ";
cin >> ID;
cout << endl;
cout << "Enter new Name: ";
cin >> name;
cout << endl;
cout << "Enter new GPA: ";
cin >> GPA;
cout << endl;
}
};

int main()
{
Student* s1 = new Student(113785, "John Harris", 50000);
s1->accessor();
Student* s2 = new Student(254785, "Lisa Smith", 75000.4);
s2->accessor();
s2->mutator();
s2->accessor();
return 0;
}

OUTPUT:

PART B:

#include <iostream>
#include <string>

using namespace std;

class Student {
private:
long ID;
string name;
float GPA;
public:
Student(long ID, const char name[], double GPA) {
this->ID = ID;
this->name = name;
this->GPA =GPA;
}
void accessor() {
cout << "ID: " << ID << endl;
cout << "Name: " << name << endl;
cout << "GPA: " << GPA << endl;
}
void mutator() {
cout << "Enter new ID: ";
cin >> ID;
cout << endl;
cout << "Enter new Name: ";
cin >> name;
cout << endl;
cout << "Enter new GPA: ";
cin >> GPA;
cout << endl;
}
void update() {
ID = ID + 100000000;
}
long IDAccessor() {
return ID;
}
void IDMutator(long ID) {
this->ID = ID;
}
};

void update(Student* s) {
long ID = s->IDAccessor();
s->IDMutator(ID + 100000000);
}

int main()
{
Student* s1 = new Student(113785, "John Harris", 50000);
cout << "Original student s1"<<endl;
s1->accessor();
s1->update();
cout << endl << "Student s1, after using member update function" << endl;
s1->accessor();
  
Student* s2 = new Student(254785, "Lisa Smith", 75000.4);
cout << endl << "Original student s2"<<endl;
s2->accessor();
update(s2);
cout << endl << "Student s2, after using external update function" << endl;
s2->accessor();
return 0;
}

OUTPUT:

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