Define a class named student with four member variables 3 st

Define a class named student with four member variables: 3 strings for student ID, First Name, and Last name. Write necessary accessor and mutator functions. Also, write a default constructor that sets student ID, first and last name to your own info. Write a test program to test the class. Add three constructors to the previous class. If you pass only one string that is the student ID. If your pass two strings, they are the first and last name. If you pass three strings, they are the ID, first and last name respectively.

Solution

#include <iostream>

using namespace std;

// Class Declaration
class Student
{
//Access - Specifier
private:

//Varibale Declaration
string studentId;
string firstName;
string lastName;

public :
// constructor to set all this three parameter
Student(string stdId, string fstName, string lstName);
Student(string stdId);
Student(string stdId, string fstName);

//Accessor functions
string getStudentId();
string getFirstName();
string getLastName();

//mutator functions
void setStudentId(string stdId);
void setFirstName(string frstName);
void setLastName(string lstName);
};

Student :: Student(string stdId, string frstName, string lstName){
studentId = stdId;
firstName = frstName;
lastName = lstName;
}
Student :: Student(string stdId){
studentId = stdId;
}
Student :: Student(string stdId, string frstName){
studentId = stdId;
firstName = frstName;
}
// Accessor functions
string Student :: getStudentId(){
return studentId;
}
string Student :: getFirstName(){
return firstName;
}
string Student :: getLastName(){
return lastName;
}
  
// mutator functions
void Student :: setStudentId(string stdId){
studentId = stdId;
}
void Student :: setFirstName(string fstName){
firstName = fstName;
}
void Student :: setLastName(string lstName){
lastName = lstName;
}
int main()
{
  

string stdId,frstName,lstName;
string countChoice;
  
do{
cout<<\"Enter the sudent Id (3 char):\";
cin>>stdId;
}while(stdId.length()!=3);
  
cout<<\"\ Enter the first Name : \";
cin>>frstName;
  
cout<<\"\ Enter the last Name : \";
cin>>lstName;
//you can use this constructor if(frstName.length()<1 && lstName.length()<1){
// Student student(stdId);
//}
//you can use this constructor if(lstName.length()<1) using else clause{
// Student student(stdId, frstName);
//}else{
Student student(stdId, frstName, lstName);
//}
do{
int choice;
cout<<\"\ do you want to edit record \ 1. Edit Id \ 2. Edit name \ 3. Edit last name or else to show record \";
cin>> choice;
switch(choice){

case 1: do{
cout<<\"\ Enter Students New Id (3 char) : \";
cin>>stdId;
}while(stdId.length()!=3);
student.setStudentId(stdId);
break;
  
case 2: cout<<\"\ Enter Student Name : \";
cin>>frstName;
student.setFirstName(frstName);
break;
case 3: cout<<\"\ Enter student last name : \";
cin>>lstName;
student.setLastName(lstName);
break;
default:
break;
}

cout<<\"Student Record : \";
cout<<\"\ Student Id : \"<<student.getStudentId();
cout<<\"\ First Name : \"<<student.getFirstName();
cout<<\"\ Last Name : \"<<student.getLastName();
cout<<\"\ want to change something : (y)\";
cin>>countChoice;
}while(countChoice ==\"y\" ||countChoice==\"Y\");
return 0;
}

 Define a class named student with four member variables: 3 strings for student ID, First Name, and Last name. Write necessary accessor and mutator functions. A
 Define a class named student with four member variables: 3 strings for student ID, First Name, and Last name. Write necessary accessor and mutator functions. A
 Define a class named student with four member variables: 3 strings for student ID, First Name, and Last name. Write necessary accessor and mutator functions. A

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site