C++ Classes Create a complete (yet brief) specification (student.h), implementat
ID: 3814540 • Letter: C
Question
C++ Classes
Create a complete (yet brief) specification (student.h), implementation (student.cpp) and driver (studentDriver.cpp) files for a Student class. The class should store a last name (string) and ID number (int). 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(). Your class needs to have getter and setter methods for each data member and an include guard. Use const appropriately.
C++ Classes Write a complete (yet brief) specification (student.h), implementation (student, cpp) and driver (studentDriver.cpp) files for a Student class. The class should store a last name (string) and ID number (int). Add a method isEqual0 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 isEqual0. Furthermore, your class needs to have getter and setter methods for each data member and an include guard. Use const appropriatelyExplanation / Answer
Student.h
#include<iostream>
#include <string>
using namespace std;
class Student
{
private:
int ID;
string name;
public:
Student();
Student(int ID, string name);
void setStudent(int ID, string name);
int getID();
string getName();
void print();
void isEqual(Student s2) ;
};
Student.cpp
#include "Student.h"
Student :: Student()
{
ID = 0;
name = "";
}
Student :: Student(int ID, string name)
{
this -> ID = ID;
this -> name = name;
}
void Student :: setStudent(int ID, string name)
{
this -> ID = ID;
this -> name = name;
}
int Student :: getID()
{
return ID;
}
string Student :: getName()
{
return name;
}
void Student :: print()
{
cout << "ID : " << ID << endl;
cout << "Name : " << name << endl;
}
void Student ::isEqual(Student s2)
{
if(name.compare(s2.getName())!=0)
cout<<name<<" is not equal to "<<s2.getName();
else
cout<<name<<"is equal to"<<s2.getName();
}
StudentDemo.cpp
#include "Student.h"
int main()
{
int ID;
string name;
Student s;
cout << "Enter ID ";
cin >> ID;
cout << "Enter name ";
cin >> name;
s.setStudent(ID, name);
s.print();
Student s2;
cout << "Enter ID ";
cin >> ID;
cout << "Enter name ";
cin >> name;
s2.setStudent(ID, name);
s2.print();
s.isEqual(Student s2);
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.