| | |
Employee Class
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jul 2009
Posts: 26
Reputation:
Solved Threads: 0
Hello once again. I'm trying to do one last project, but unlike the others, that usually i struggle with some common errors, this time i have problems figuring out how its supposed to be created.
This is the question:
Write a class named Employee that has the following member variables:
name, idnumber, department, position
and have the following constructors.
-one that accepts values as arguments and assigns them to the appropiate member variables, employee name, employee id, department, position
-accepts the following values as arguments and assigns them to the appropiate member variables name, id. the department and position fields should be assigned and empty string ("")
-a default constructor that assigns empty strings ("") to the name, department, and position member variables and 0 to the idnumber member variable.
Write appropriate mutator functions that store values in these member variables. once you have written the class, write a separete program that creates three employee objects to hold the data :
" susan meyers, 47899, accounting, vice president"
"Mark jones, 39119, IT, programmer"
"Joy Rogers, 81774, manufacturing, Engineer"
The program should store this data in the three objects and then display the data for eac h employee on the screen
This is what i think could be included in the first program:
The second part, the second program i think holds something like:
As to how to have two separete programs combined to make one ???never done anything as advanced as this, PLEASE HELP.
This is the question:
Write a class named Employee that has the following member variables:
name, idnumber, department, position
and have the following constructors.
-one that accepts values as arguments and assigns them to the appropiate member variables, employee name, employee id, department, position
-accepts the following values as arguments and assigns them to the appropiate member variables name, id. the department and position fields should be assigned and empty string ("")
-a default constructor that assigns empty strings ("") to the name, department, and position member variables and 0 to the idnumber member variable.
Write appropriate mutator functions that store values in these member variables. once you have written the class, write a separete program that creates three employee objects to hold the data :
" susan meyers, 47899, accounting, vice president"
"Mark jones, 39119, IT, programmer"
"Joy Rogers, 81774, manufacturing, Engineer"
The program should store this data in the three objects and then display the data for eac h employee on the screen
This is what i think could be included in the first program:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; class Employee { private: string Name; int IdNumber; string Department; string Position; public: Employee(string AssignName,int AssignIdNumber,string AssignDepartment,string AssignPosition) { Name=AssignName; IdNumber=AssignIdNumber; Department=AssignDepartment; Position=AssignPosition; } Employee(string AssignName,int AssignIdNumber) { Name=AssignName; IdNumber= AssignIdNumber; Department=""; Position=""; } Employee() { Name=""; IdNumber=0; Department=""; Position=""; } string getName() const; int getIdNumber() const; string getDepartment() const; string getPosition () const; }; string Employee::getName() const { return Name; } int Employee::getIdNumber() const { return IdNumber; } string Employee::getDepartment() const { return Department; } string Employee::getPosition() const { return Position; }
The second part, the second program i think holds something like:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include "EmployeeClass" using namespace std; int main() { Employee Name[3] ={ "Susan Meyer", "Mark Jones", "Joy Rogers"}; Employee Idnumber[3] ={ 47899, 39119,81774}; Employee Department[3] = { "Accounting", "IT", "Manufacturing"}; Employee Position[3] = {"Vice President", "Programmer", "Engineer"}; return 0; }
As to how to have two separete programs combined to make one ???never done anything as advanced as this, PLEASE HELP.
Well, You have misunderstood the basic concept of a
So by this code you are actually creating about 12 Employee data types.
Where as you only need to make 3 .......
Just getback to http://cplus.about.com/od/learning1/ss/cppobjects.htm
This small tutorial on classes and i think you will get to know what exactly is going wrong in your code.
class C++ Syntax (Toggle Plain Text)
Employee Name[3] ={ "Susan Meyer", "Mark Jones", "Joy Rogers"}; Employee Idnumber[3] ={ 47899, 39119,81774}; Employee Department[3] = { "Accounting", "IT", "Manufacturing"}; Employee Position[3] = {"Vice President", "Programmer", "Engineer"};
Where as you only need to make 3 .......
Just getback to http://cplus.about.com/od/learning1/ss/cppobjects.htm
This small tutorial on classes and i think you will get to know what exactly is going wrong in your code.
•
•
Join Date: Jul 2009
Posts: 26
Reputation:
Solved Threads: 0
Let me know if im starting to turn towards the right direction. I think this is a good way to just have 3 employee data types. Let me know if i did this correct and how to link both programs. Thanks so much.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include "EmployeeClass" using namespace std; int main() { const int NUM_WORKERS = 3; employeedata EMPLOYEE[NUM_WORKERS] ={ employeedata("Susan Meyers", 47899, "Accounting", "Vice President"), employeedata("Mark Jones", 39119, "IT", "Programmer"), employeedata("Joy Rogers", 81774, "Manufacturing", "Engineer")}; cout << " NAME ID NUMBER DEPARTMENT POSITION\n"; cout << "-------------------------------------------\n"; for (int i = 0; i < NUM_WORKERS; i++) { cout << setw(8) << EMPLOYEE[i].getName(); cout << setw(8) << EMPLOYEE[i].getIdnumber(); cout << setw(8) << EMPLOYEE[i].getDepartment(); cout << setw(8) << EMPLOYEE[i].getPosition() << endl; } return 0; }
•
•
Join Date: Jul 2009
Posts: 26
Reputation:
Solved Threads: 0
I finally got the file to open i think i no longer get that error now these are the errors i get:
error C2065: 'employeedata' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'EMPLOYEE'
error C2065: 'EMPLOYEE' : undeclared identifier
error C2059: syntax error : '{'
error C2143: syntax error : missing ';' before '{'
error C2143: syntax error : missing ';' before '}'
error C3861: 'employeedata': identifier not found
error C3861: 'employeedata': identifier not found
error C3861: 'employeedata': identifier not found
error C2065: 'EMPLOYEE' : undeclared identifier
C2228: left of '.getName' must have class/struct/union
error C2065: 'EMPLOYEE' : undeclared identifier
error C2228: left of '.getIdnumber' must have class/struct/union error C2065: 'EMPLOYEE' : undeclared identifier
error C2228: left of '.getDepartment' must have class/struct/union
error C2065: 'EMPLOYEE' : undeclared identifier
error C2228: left of '.getPosition' must have class/struct/union
This program is called Data Two:
This is the Other file and what i have changed it those far. This one is called Employee Class
Hopefully this can give you guys some info as to how clustered my mind is right now. That is why i need the help BAD. Thanks.
error C2065: 'employeedata' : undeclared identifier
error C2146: syntax error : missing ';' before identifier 'EMPLOYEE'
error C2065: 'EMPLOYEE' : undeclared identifier
error C2059: syntax error : '{'
error C2143: syntax error : missing ';' before '{'
error C2143: syntax error : missing ';' before '}'
error C3861: 'employeedata': identifier not found
error C3861: 'employeedata': identifier not found
error C3861: 'employeedata': identifier not found
error C2065: 'EMPLOYEE' : undeclared identifier
C2228: left of '.getName' must have class/struct/union
error C2065: 'EMPLOYEE' : undeclared identifier
error C2228: left of '.getIdnumber' must have class/struct/union error C2065: 'EMPLOYEE' : undeclared identifier
error C2228: left of '.getDepartment' must have class/struct/union
error C2065: 'EMPLOYEE' : undeclared identifier
error C2228: left of '.getPosition' must have class/struct/union
This program is called Data Two:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> #include "Employee Class.cpp" using namespace std; int main() { const int NUM_WORKERS = 3; employeedata EMPLOYEE[NUM_WORKERS] ={ employeedata("Susan Meyers", 47899, "Accounting", "Vice President"), employeedata("Mark Jones", 39119, "IT", "Programmer"), employeedata("Joy Rogers", 81774, "Manufacturing", "Engineer")}; cout << " NAME ID NUMBER DEPARTMENT POSITION\n"; cout << "-------------------------------------------\n"; for (int i = 0; i < NUM_WORKERS; i++) { cout << setw(8) << EMPLOYEE[i].getName(); cout << setw(8) << EMPLOYEE[i].getIdnumber(); cout << setw(8) << EMPLOYEE[i].getDepartment(); cout << setw(8) << EMPLOYEE[i].getPosition() << endl; } return 0; }
This is the Other file and what i have changed it those far. This one is called Employee Class
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> using namespace std; class Employee { private: string Name; int IdNumber; string Department; string Position; public: Employee(string AssignName,int AssignIdNumber,string AssignDepartment,string AssignPosition) { Name=AssignName; IdNumber=AssignIdNumber; Department=AssignDepartment; Position=AssignPosition; } Employee(string AssignName,int AssignIdNumber) { Name=AssignName; IdNumber= AssignIdNumber; Department=""; Position=""; } Employee() { Name=""; IdNumber=0; Department=""; Position=""; } void setName(string); void setIdNumber(int); void setDepartment(string); void setPosition(string); string getName() const; int getIdNumber() const; string getDepartment() const; string getPosition () const; }; void Employee::setName(string NA) { Name = NA; } void Employee::setIdNumber(int ID) { IdNumber = ID; } void Employee::setDepartment(string DEP) { Department = DEP; } void Employee::setPosition (string POS) { Position = POS; } string Employee::getName() const { return Name; } int Employee::getIdNumber() const { return IdNumber; } string Employee::getDepartment() const { return Department; } string Employee::getPosition() const { return Position; }
Hopefully this can give you guys some info as to how clustered my mind is right now. That is why i need the help BAD. Thanks.
Fields must be initialized with constructor.
C++ Syntax (Toggle Plain Text)
int main() { Employee a[3]={Employee("A",1,"A","A"),Employee("B",2,"B","B"),Employee("C",3,"C","C")}; for(int i=0;i<3;i++) { cout << "\n" << a[i].getName(); } return 0; }
•
•
Join Date: Jul 2009
Posts: 26
Reputation:
Solved Threads: 0
I have been working on this all night, i'm like right there in getting it to work, could you guys tell me what these errors mean, and how to fix them so that i can get this program working. Thanks you.
This is what i have for the file employee class:
This is what i have for the file Data Two:
The ERRORS:
warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. : see declaration of 'strcpy'
warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead.see declaration of 'strcpy'
error C2665: 'EmployeeData::EmployeeData' : none of the 4 overloads could convert all the argument types cpp(50): could be 'EmployeeData::EmployeeData(char *,int,char,char)'
while trying to match the argument list '(const char [13], int, const char [11], const char [15])'
'EmployeeData::EmployeeData' : none of the 4 overloads could convert all the argument types
: could be 'EmployeeData::EmployeeData(char *,int,char,char) while trying to match the argument list '(const char [11], int, const char [3], const char [11])'
: error C2665: 'EmployeeData::EmployeeData' : none of the 4 overloads could convert all the argument typesclass.cpp(50): could be 'EmployeeData::EmployeeData(char *,int,char,char)'
while trying to match the argument list '(const char [11], int, const char [14], const char [9])'
This is what i have for the file employee class:
C++ Syntax (Toggle Plain Text)
#ifndef EmployeeClass #define EmployeeClass #include < cstring> const int DEFAULT_SIZE = 51; class EmployeeData { private: char *name; int idnumber; char department; char position; //private member function void createName(int size, char *value) {//Allocate the default amount of memory for name name = new char [size]; //store a value in the memory strcpy(name, value);} public: //Constructor #1 EmployeeData() {//Store an empty string in the name attribute. createName(DEFAULT_SIZE, ""); //initialize idnumber department position idnumber = 0; department = 0; position = 0;} //Constructor #2 EmployeeData(char *nam) {//allocate memory and store the description. createName(strlen(nam), nam); //initialize idnumber department position idnumber = 0; department = 0; position = 0;} //Constructor #3 EmployeeData(char *nam, int id, char d, char p) {//Allocate memory and store the description. createName(strlen(nam), nam); //Assign values to id deparment position idnumber = id; department = d; position = p;} //Destructor ~EmployeeData() { delete[] name;} //mutator functions void setName(char *n) {strcpy(name, n);} void setIdnumber(int id) {idnumber = id;} void setDepartment(char d) {department = d;} void setPosition(char p) {position =p;} //Accessor functions const char *getName() const {return name;} int getIdnumber() const {return idnumber;} char getDepartment() const {return department;} char getPosition() const {return position;} }; #endif
This is what i have for the file Data Two:
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <iomanip> #include "Employee Class.cpp" using namespace std; int main() { const int NUM_WORKERS = 3; EmployeeData EMPLOYEE[NUM_WORKERS] ={ EmployeeData("Susan Meyers", 47899, "Accounting", "Vice President"), EmployeeData("Mark Jones", 39119, "IT", "Programmer"), EmployeeData("Joy Rogers", 81774, "Manufacturing", "Engineer")}; cout << " NAME ID NUMBER DEPARTMENT POSITION\n"; cout << "-------------------------------------------\n"; for (int i = 0; i < NUM_WORKERS; i++) { cout << setw(8) << EMPLOYEE[i].getName(); cout << setw(8) << EMPLOYEE[i].getIdnumber(); cout << setw(8) << EMPLOYEE[i].getDepartment(); cout << setw(8) << EMPLOYEE[i].getPosition() << endl; } return 0; }
The ERRORS:
warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. : see declaration of 'strcpy'
warning C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead.see declaration of 'strcpy'
error C2665: 'EmployeeData::EmployeeData' : none of the 4 overloads could convert all the argument types cpp(50): could be 'EmployeeData::EmployeeData(char *,int,char,char)'
while trying to match the argument list '(const char [13], int, const char [11], const char [15])'
'EmployeeData::EmployeeData' : none of the 4 overloads could convert all the argument types
: could be 'EmployeeData::EmployeeData(char *,int,char,char) while trying to match the argument list '(const char [11], int, const char [3], const char [11])'
: error C2665: 'EmployeeData::EmployeeData' : none of the 4 overloads could convert all the argument typesclass.cpp(50): could be 'EmployeeData::EmployeeData(char *,int,char,char)'
while trying to match the argument list '(const char [11], int, const char [14], const char [9])'
![]() |
Similar Threads
- employee class (C++)
- Class (C++)
- How to Store two different class objects in Same array. - new to Java ..Need Help (Java)
- class recieving compiler errors in java (Java)
- Title : Declaring abstract class function Prototype or Signature (C#)
- Problem declaring class object array (C++)
- Parent / child class problems (C++)
- What is the difference between abstract class and interface (Java)
- HELP: class static function - compile errors (C++)
Other Threads in the C++ Forum
- Previous Thread: Bank program help!
- Next Thread: IsAdmin?
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph homeworkhelp iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg simple sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






