Question
Circle and correct all syntax errors and logic error in following code include using namespace std Class Employee{ public // friend functions friend boolean equal(const
Circle and correct all syntax errors and logic error in following code
include
using namespace std
Class Employee{ public
// friend functions
friend boolean equal(const Employee& e1, const Employee e2);
// return true if two employees have the same id; false otherwise
friend istream& operator >> (istream& ins, Employee e);
// input es id and salary from istream ins
friend ostream& operator << (ostream& outs, const Employee& e);
// output es id and salary
// constructors
employee();
// initialize id to be 0 and salary to be 0.0
Employee(int id);
// initialize id to be given id and salary to be 0.0
Employee(int id, double salary);
// initialize id to be given id and salary to be given salary
// member functions
int get_id();
double get_salary();
void set_id(int id);
void set_salary(double salary);
private:
int _id;
double _salary;
}
int main() {
Employee employee1(1000, 23000.00);
Employee employee2;
cout << "Enter the information of the employee, id and salary, seperated by white space: ";
cin >> employee2;
cout << "The employee1's salary is $" << employee1.get_salary();
if(equal(employee1, employee2))
cout << "Two emplotees are the same guy.";
else
cout << "Two employees are different guys";
return 0;
}
bool Employee::equal(constant Employee& e1, constant Employee e2) {
return e1._id == e2._id;
}
istream& operator >> (istream& ins, Employee& e) {
ins >> e.id;
ins >> e.salary;
return ins;
}
ostream& operator >> (ostream& outs, const Employee& e) {
outs << "ID: " << e._id << ", Salary: " << e._salary;
}
// constructors
Employee::Employee():_id(0);_salary(0.0) {}
Employee::Employee(int id) {
_id = id;
_salary = 0.0;
}
Employee::Employee(int id, double salary)
{
id = _id;
salary = 0.0;
}
//member function
int Employee::get_id() {
return _id;
}
double Employee::get_salary() {
return _salary;
}
void set_id(int id) {
_id = id;
}
void Employee::set_salary(double salary) {
_salary = salary;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started