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

C++ Program on Classe s Write a complete (yet brief) specification (student.h),

ID: 3813926 • Letter: C

Question

C++ Program on Classes

Write a complete (yet brief) specification (student.h), implementation (student.cpp) and driver (studentDriver.cpp) files for a Student class. Include a comment at the top of each file indicating the filename.

The class should store the last name (string) and ID number (int). Additionally, add a method isEqual() that takes a Student as an argument and returns true if the students have the same names and IDs, and false otherwise.

Have the driver code use a default and a parameterized constructor and make a call to isEqual().

Furthermore, your class needs to have getter and setter methods for each data member and an include guard. Use const appropriately. Use comments to label required components.

Explanation / Answer

Here is your code below. In driver program, I have created three objects of Student class, with all of them having same ids but a and b have different last_names and a and c have same last names: -

student.h

// fileName student.h providing prototype/specification of class student

#ifndef STUDENT_H
#define STUDENT_H
#include<iostream>
#include<string>
using namespace std;
class Student
{
public:
Student(); // default constructor
Student(string name,int id); // parametrized constructor
bool isEqual(Student s); // used for comparing two Students .. return true if equal else false
void setName(string name);// setter for last_name
void setId(int id);//setter for id
string getName() const;//getter for name
int getId() const;//getter for id
private:
string lastName;
int idNum;
};
#endif STUDENT_H

student.cpp

// fileName student.cpp providing implementation of class student methods
#include<iostream>
#include<string>
#include <ctype.h>
#include "student.h"

using namespace std;
Student::Student()
{
lastName ="";
idNum=0;
}
Student::Student(string name,int id)
{
this->lastName = name;
this->idNum =id;
}
string Student::getName() const
{
return lastName;
}
void Student::setName(string name)
{
this->lastName = name;
}
int Student::getId() const
{
return idNum;
}
void Student::setId(int id)
{
this->idNum = id;
}
bool Student::isEqual(Student s){
   if((this->lastName == s.getName()) && (this->idNum == s.getId())){ // checking name and id if equal return true else false
       return true;
   } else {
       return false;
   }
}

studentdriver.cpp

// fileName studentdriver.cpp providing main function to test the functionality
#include <iostream>
#include "student.h"
/* run this program using the console pauser */

int main(void) {
  
   Student a;
   Student b("Salil",2603);
   Student c("Bansal",2603);
   a.setName("Bansal");
   a.setId(2603);
  
   bool aEqualsB = a.isEqual(b);
   bool bEqualsC = b.isEqual(c);
   bool aEqualsC = a.isEqual(c);

   cout<<"Is Student a equals to b:"<<std::boolalpha<<aEqualsB<<endl; //std::boolalpha setting flag boolalpha to print true,false in place of 1,0.
   cout<<"Is Student b equals to c:"<<std::boolalpha<<bEqualsC<<endl;
   cout<<"Is Student a equals to c:"<<std::boolalpha<<aEqualsC<<endl;
system("pause");

return 0;

}

output is as follows: -

Is Student a equals to b:false
Is Student b equals to c:false
Is Student a equals to c:true
Press any key to continue . . .

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