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

Define a class in C++ whose purpose it is to represent a student of a University

ID: 3800172 • Letter: D

Question

Define a class in C++ whose purpose it is to represent a student of a University and write a simple main() driver program to instantiate several objects of this class, populate each object, and display the information for each object.

the defintion of the student class should be written in an individual header (i.e. student.h) file and the implementation of the methods of the student class should be written in a corresponding source (i.e. student.cpp) file.

The class should be designed around the following characteristics:

The name of the class should be Student.

The class should be composed of the following (data) members:

- student id

- first name

- last name

- middle initial

- date of birth in numeric {month, day, year} form

- gender, one of {Male, Female}

Note that the data type of each member should be appropriate to the type of data being stored.


and at least the following methods:

- Default Constructor

- Constructor to initialize the object with at least the name and date of birth of the student.

- A method to populate the data members from external (user) input.

- Mutator methods for each data member or logical groupings, as necessary. Note that these methods should ensure the integrity of the object and should not allow data to be saved that is not appropriate for that data member. Example, month must be in {1..12}.

- Display method to display the contents of the data members.

Explanation / Answer

student.h file

#include <string>
using namespace std;

class Student
{
private:
int studentid;
string firstname;
string middleinitial;
string lastname;
string dateofbirth;
string gender;
public:
Student();
Student(int studentid, string firstname,string middleinitial,string lastname,string dateofbirth,string gender);
void setStudent(int studentid, string firstname,string middleinitial,string lastname,string dateofbirth,string gender);
int getstudentid();
string getfirstname();
string getmiddleinitial();
string getlastname();
string getdateofbirth();
string getGender();
void display();
};

student.cpp file

#include "student.h"
#include <iostream>
using namespace std;

Student :: Student()
{
studentid = 0;
firstname = "";
middleinitial = "";
lastname = "";
dateofbirth ="";
gender = "";
}
Student :: Student(int studentid, string firstname,string middleinitial,string lastname,string dateofbirth,string gender)
{
this -> studentid = studentid;
this -> firstname = firstname;
this -> middleinitial = middleinitial;
this -> lastname = lastname;
this -> dateofbirth = dateofbirth;
this -> gender = gender;
}

void Student :: setStudent(int studentid, string firstname,string middleinitial,string lastname,string dateofbirth,string gender)
{
this -> studentid = studentid;
this -> firstname = firstname;
this -> middleinitial = middleinitial;
this -> lastname = lastname;
this -> dateofbirth = dateofbirth;
this -> gender = gender;
}

int Student :: getstudentid()
{
return studentid;
}

string Student :: getfirstname()
{
return firstname;
}

string Student :: getmiddleinitial()
{
return middleinitial;
}
string Student :: getlastname()
{
return lastname;
}
string Student :: getdateofbirth()
{
return dateofbirth;
}
string Student :: getGender()
{
return gender;
}

void Student :: display()
{
cout << "studentid : " << studentid << endl;
cout << "firstname : " << firstname << endl;
cout << "middleinitial : " << middleinitial << endl;
cout << "lastname : " << lastname << endl;
cout << "dateofbirth : " << dateofbirth << endl;
cout << "Gender : " << gender << endl;
}
int main()
{
Student s;
int studentid;
string firstname;
string middleinitial;
string lastname;
string dateofbirth;
string gender;

cout << "Enter studentid ";
cin >> studentid;
cout << "Enter firstname ";
cin >> firstname;
cout << "Enter middleinitial ";
cin >> middleinitial;
cout << "Enter lastname ";
cin >> lastname;
cout << "Enter dateofbirth ";
cin >> dateofbirth;
cout << "Enter gender ";
cin >> gender;
s.setStudent(studentid, firstname,middleinitial,lastname,dateofbirth,gender);
s.display();
return 0;
}

/*

sample output :
Enter studentid 1234
Enter firstname trump   
Enter middleinitial john
Enter lastname donald   
Enter dateofbirth 14-06-1946
Enter gender male   
studentid : 1234
firstname : trump   
middleinitial : john
lastname : donald   
dateofbirth : 14-06-1946
Gender : male */

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