| | |
Please help me i dont understand whats wrong with my code
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
I have been working on this code and I can't get it to work any help out there? I am a new user and would really appreciate it if somebody can correct whats going wrong with it.
HELP PLEASEEE!!!!
C++ Syntax (Toggle Plain Text)
// DEBUG10-4 // PartTimeEmployee derives from Employee // Employees make $800 per week // PartTimeEmployees make $7.85 per hour #include<iostream> #include<string> using namespace std; class Employee { protected: string firstName; string lastName; double salary; public: Employee(string, string); void showEmployee(); void setData(); string getfirstName(); string getlastName(); }; Employee::Employee(string first, string last) { firstName = firstName; lastName = lastName; salary = 800; }; void Employee::setData() { cout<<"Enter Employee's first name "; cin>>firstName; cout<<"Enter last name "; cin>>lastName; salary = 800; } void Employee::showEmployee() { cout<<firstName<<" "<<lastName<< " Salary $"<<salary<<endl; } string Employee::getlastName() { return lastName; } string Employee::getfirstName() { return firstName; } class PartTimeEmployee : public Employee { public: PartTimeEmployee(string, string); }; PartTimeEmployee::PartTimeEmployee(string first, string last) : Employee(first,last) { salary = 7.85; } int main() { const int NUMEMPS = 3; string first; string last; Employee workers(first, last); int x; for(x = 0; x < NUMEMPS; ++x) { Employee temp; char pt; temp.setData(); cout<<"Is employee part time - y or n? "; cin>>pt; if(pt = 'y') { PartTimeEmployee tempPartTime(temp.getfirstName(), temp.getlastName()); temp = tempPartTime; } workers[NUMEPS] = temp; } cout<<endl<<"Employees: "<<endl; for(x = 0; x <= NUMEMPS; ++x) workers[NUMEMPS].showEmployee(); system("pause"); }
Last edited by Narue; Mar 13th, 2008 at 11:35 am. Reason: Added code tags, please do it yourself next time.
good point well in the int main section of the coding i got everything else to work so far but it doesn't read the employee and I know I need to read the number of employees. I also know that I declared it as string from the class employee from the top. SO... in tail I need to debug the bottom part of the code to make it read the number of employees i just need to run three
I changed several things in your class, so you'll want to find and study what I did. Your approach in main has some subtle issues, so rather than walk you through it bit by bit, I simply wrote my own version for you to use as a template:
C++ Syntax (Toggle Plain Text)
// DEBUG10-4 // PartTimeEmployee derives from Employee // Employees make $800 per week // PartTimeEmployees make $7.85 per hour #include<iostream> #include<string> using namespace std; class Employee { protected: string firstName; string lastName; double salary; public: Employee(); Employee(string, string); void showEmployee(); void setData(); string getfirstName(); string getlastName(); }; Employee::Employee() { salary = 0; } Employee::Employee(string first, string last) { firstName = first; lastName = last; salary = 800; }; void Employee::setData() { cout<<"Enter Employee's first name "; cin>>firstName; cout<<"Enter last name "; cin>>lastName; salary = 800; } void Employee::showEmployee() { cout<<firstName<<" "<<lastName<< " Salary $"<<salary<<endl; } string Employee::getlastName() { return lastName; } string Employee::getfirstName() { return firstName; } class PartTimeEmployee : public Employee { public: PartTimeEmployee(string, string); }; PartTimeEmployee::PartTimeEmployee(string first, string last) : Employee(first,last) { salary = 7.85; } int main() { const int NUMEMPS = 3; Employee workers[NUMEMPS]; for ( int i = 0; i < NUMEMPS; i++ ) { workers[i].setData(); // Clean up leftovers from setData() cin.ignore ( 80, '\n' ); cout<<"Is the employee part-time? (y/n): "; if ( cin.get() == 'y' ) { workers[i] = PartTimeEmployee ( workers[i].getfirstName(), workers[i].getlastName() ); } // Clean up leftovers from cin.get() cin.ignore ( 80, '\n' ); } cout<<"Employees:\n"; for ( int i = 0; i < NUMEMPS; i++ ) workers[i].showEmployee(); cin.get(); }
I'm here to prove you wrong.
![]() |
Similar Threads
- Help Please (C++)
- ASP.NET problem (ASP.NET)
- ASP and SQL ? (MS SQL)
Other Threads in the C++ Forum
- Previous Thread: Socket help for PPC
- Next Thread: problem in dynamic input for string
| Thread Tools | Search this Thread |
api application array arrays beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll email encryption error file forms fstream function functions game generator getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linux loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive return sorting string strings struct studio template templates text tree unix url vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






