I NEED HELP WITH THIS PROGRAM. THIS IS WHAT I HAVE SO FAR, AND I DUNNO WHY ITS N
ID: 3658414 • Letter: I
Question
I NEED HELP WITH THIS PROGRAM. THIS IS WHAT I HAVE SO FAR, AND I DUNNO WHY ITS NOT LIKE THE NAMES IN THE QUOTES IN THE MAIN FILE, AND ITS ALSO NOT LIKING THE << ON THE COUTs. ANY HELP IS APPRECIATED. Header file: #ifndef EMPLOYEE_H #define EMPLOYEE_H #include using namespace std; class Employee { // Private members. private: string name, department, position; int idNumber; // Public members. public: Employee(); // Default constructor. Employee(string EmpName, int idNum, int EmpID, string Dept, string Position) Employee(string EmpName, int idNum); void setName (string EmpName); void setIDNum (int idNum); void setDesc (string Desc); void setPos (string Pos); void getName(string); //const {return EmpName;} void getIDNum(); //const {return idNum;} void getDesc(); //const {return Desc;} void getPos(); //const {return Pos;} }; #endif Implementation file: #include "Employee.h" // Constructor 1 with arguments as parameters. Employee::Employee() { name = " "; idNumber = 0; department = " "; position = " "; } // Constructor 2 with arguments as parameters. Employee::Employee (string EmpName, int idNum, int EmpID, string Dept, string Position) { name = EmpName; idNumber = 0; department = " "; position = " "; } // Mutator function for name. void Employee::setName (string EmpName) { name = EmpName; } // Mutator function for idNum. void Employee::setIDNum (int idNum) { idNumber = idNum; } // Mutator function for department. void Employee::setDesc (string Desc) { department = Desc; } // Mutator function for position. void Employee::setPos (string Pos) { position = Pos; } Main file: #include "Employee.h" #include using namespace std; int main(void) { Employee e1, e2, e3; // Three employee objects called a, b, c Employee e1 ("Susan Meyers", "47899", "Accounting", "Vice President"); Employee e2 ("Mark Jones", "39119", "IT", "Programmer"); Employee e3 ("Joy Rodgers", "81774", "Manufacturing", "Engineer"); // Display the data in table format. cout << "Name: ID Number: Department: Position:" << endl; cout << e1.getName() << " " << e1.getIDNum() << " " << e1.getDesc() << " " << e1.getPos() << endl; cout << e2.getName() << " " << e2.getIDNum() << " " << e2.getDesc() << " " << e2.getPos() << endl; cout << e3.getName() << " " << e3.getIDNum() << " " << e3.getDesc() << " " << e3.getPos() << endl; }Explanation / Answer
There are couple errors in your program. I have included it in my CAP comments in the codes below:
// Employee.h file
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include <string> // INCLUDE STRING LIBRARY???
using namespace std;
class Employee {
// Private Members.
private:
string name, department, position;
int idNumber;
// Public Members.
public:
Employee(); // Default constructor
Employee(string EmpName, int idNum, int EmpID, string Dept, string Position);
Employee(string EmpName, int idNum);
// NEW CONSTRUCTOR THAT TAKES 4 ARGUMENTS
Employee(string EmpName, int idNum, string Dept, string Pos);
void setName(string EmpName);
void setIDNum(int idNum);
void setDept(string Desc); // I WOULD CHANGE IT TO Dept INTSTEAD OF Desc
void setPos(string Pos);
string getName();
int getIDNum();
string getPos();
string getDept(); // I WOULD CHANGE IT TO THIS
};
#endif
// Employee.cpp file
#include "Employee.h";
// Default constructor
Employee::Employee()
{
name = "";
idNumber = 0;
department = "";
position = "";
}
Employee::Employee(string EmpName, int idNum, int EmpID, string Dept, string Position)
{
name = EmpName;
// WHY NOT TAKE THE VALUE PASSED IN?
//idNumber = 0;
idNumber = idNum;
// WHY NOT TAKE THE VALUE PASSED IN?
//department = "";
department = Dept;
// WHY NOT TAKE THE VALUE PASSED IN?
//position = "";
position = Position;
// AND I DON't SEE WHERE EmpID IS USED
}
// MISSING ANOTHER IMPLEMENTATION OF ANOTHER CONSTRUCTOR???
Employee::Employee(string EmpName, int idNum)
{
name = EmpName;
idNumber = idNum;
}
// NEW CONSTRUCTOR
Employee::Employee(string EmpName, int idNum, string Dept, string Pos)
{
name = EmpName;
idNumber = idNum;
department = Dept;
position = Pos;
}
// Mutator function for name
void Employee::setName(string EmpName)
{
name = EmpName;
}
string Employee::getName()
{
return name;
}
// Mutator function for idNum
void Employee::setIDNum(int idNum)
{
idNumber = idNum;
}
int Employee::getIDNum()
{
return idNumber;
}
// Mutator function for department
void Employee::setDept(string Dept)
{
department = Dept;
}
string Employee::getDept()
{
return department;
}
// Mutator function for position
void Employee::setPos(string Pos)
{
position = Pos;
}
string Employee::getPos()
{
return position;
}
// Main file
#include "Employee.h";
#include <iostream> // NEED TO INCLUDE THIS AS WELL??
using namespace std;
int main()
{
// YOU DON'T NEED THIS LINE SINCE YOU'RE CREATING THOSE
// OBJECTS AGAIN LATER ON ANYWAY
//Employee e1, e2, e3; // Three employee objects
// YOUR PROBLEM IS, YOU DON'T HAVE THE MATCHING CONSTUCTORS
// THE ONLY CONSTRUCTORS YOU HAVE EITHER TAKE 2 ARGUMENTS OR
// 5 ARGUMENTS.
// BUT THE WAY YOU CREATE OBJECTS TAKE 4 ARGUMENTS
//
// AND YOU INPUT THE IDNUMBER AS STRING, WHICH YOU INDICATED
// AS INT IN YOUR .H FILE
/*
Employee e1("Susan Meyers", "47899", "Acounting", "Vice President");
Employee e2("Mark Jones", "39119", "IT", "Programmer");
Employee e3(......
*/
Employee e1("Susan Meyers", 47899, "Acounting", "Vice President");
Employee e2("Mark Jones", 39119, "IT", "Programmer");
Employee e3("Joy Rodgers", 81774, "Manufacturing", "Engineer");
// Display data
cout << "Name: ID Number: Department: Position:" << endl;
cout << e1.getName() << " " << e1.getIDNum() << " " << e1.getDept() << " " << e1.getPos() << endl;
cout << e2.getName() << " " << e2.getIDNum() << " " << e2.getDept() << " " << e2.getPos() << endl;
cout << e3.getName() << " " << e3.getIDNum() << " " << e3.getDept() << " " << e3.getPos() << endl;
system("PAUSE"); // FOR MYSELF DEBUGGING, IGNORE IT
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.