Basic Employee Database for School Project

Hello guys,
I have a basic program due today. This is the Text of the project. For some reason ,I keep getting an error code. The code is posted below the text of the project. i would appreciate if someone can help me out with whats wrong with my code. Thanks! At the very minimum, since this code is due today, I need it at least to have a base class and declaration so I can receive at least 70 out of the 100 points.

"
Project #1 DUE Feb 25 4:15 pm.
This is a database of employees and managers.
Base class EMPLOYEE has these private data members: NAME, SALARY, YEAR_HIRED.
Each of these should be a an array of size 10.
Derived class MANAGER has one private data member STAFF of size 5.
Declare one instance of EMPLOYEE and 2 instances of MANAGER.
Assign employees #1- 5 to Manager1 and employees #6-10 to Manager2.
Employees have name, salary, year_hired. Managers have name, salary, year_hired, staff.

Main program should initialize 10 employees and allow user to output employee records and make changes. User should also be able to list all employees on staff of a given manager as a report.
Class should be in header file. If this is complete by deadline 100 pts.
"

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <iostream>
#include <string>
#include <conio.h>

using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

class employee{
	private:
		float salary{10};
		char name{10};
		double year_hired{10};
		
	public:
		void getemptdetails()
		{
		
		cout << "\n Enter the employee name." <<endl;
		cin >> name;
		cout <<" \n Enter the year hired" << endl;
		cin >> year_hired;
		cout << "\n Enter the salary of the employee." <<endl;
		cin >> salary;
	}
	 void showemptdata()
	 {
	 
	 	cout << " \n The name of the employee:" << name;
	 	cout << " \n The salary of the employee:" << salary;
	 	cout << " \n The year hired of the employee:" << year_hired;
	 }
};
		int main()
		{
			//create object for class
			employee e1;
			e1.getemptdetails(); //call member functions 
			e1.showemptdata();
			_getch();
		}
		
		

		
		




   
	 (System "pause")
	return 0;
}
Last edited on
Remove line 40.

Line 51 is supposed to be system(“pause”);

Both lines 39 and 51 exists for one reason: Keep the console open when run from the debugger. So both lines are unnecessary and can be omitted. But at least you should remove one of them.
For some reason, it only lets me input the name, and everything else won't work. I have no error codes, however. Any ideas why this may be?
Your member variable name is a single char. As soon as you enter a second character it will go to the next input and raises an error.

So change line 11 to something like:

char name[100]; // Note: []

It can take 99 character plus the terminating 0.
it only lets me input the name,

That's because you've declared name as a single char with an initial value of 10. So If you enter "Bert" at line 10, the program stores 'B' in name and leaves "ert" in the input buffer. When it gets to line 21 it tries to read "ert" into year_hired and fails.

First, the assignment isn't clear, at least not to me:
Each of these should be a an array of size 10.
Huh? Salary and year_hired sound like individual numbers, not arrays. Does this mean they should be stored as char arrays?
Declare one instance of EMPLOYEE and 2 instances of MANAGER.
Assign employees #1- 5 to Manager1 and employees #6-10 to Manager2.
Huh? Should there be one EMPLOYEE instance or ten?

This is a good reason to always start programming assignments early. You want to be sure you understand the problem precisely.

Okay, let's assume that there are 10 EMPLOYEEs and the year_hired and salary are numbers. Salary should be a double because 30,495.43 is a legal value. Year should be an unsigned because -33 and 2016.75 are not valid values:
1
2
3
4
5
class employee {
  private:
    double salary
    char name {10};
    unsigned year_hired;


thank you for the prompt response. I plan on starting earlier and coming back here often as I learn more and more in C++.

The new code is below. The only problem I get now is it only takes one employee's information and displays it, instead of doing it ten times.

#include <iostream>
#include <string>
#include <conio.h>

using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

class employee{
private:
float salary;
char name[10];
unsigned year_hired;

public:
void getemptdetails()
{

cout << "\n Enter the employee name." <<endl;
cin >> name;
cout <<" \n Enter the year hired." << endl;
cin >> year_hired;
cout << "\n Enter the salary of the employee." <<endl;
cin >> salary;
}
void showemptdata()
{

cout << " \n The name of the employee:" <<name;
cout << " \n The salary of the employee:" <<salary;
cout << " \n The year hired of the employee:" <<year_hired;
}
};
int main()
{
//create object for class
employee e1;
e1.getemptdetails(); //call member functions
e1.showemptdata();
_getch();











system("pause");
return 0;
}
Last edited on
BUMP
When posting code, please use code tags. Highlight the code then click on the <> button to the right of the edit window.

The problem now is that your main program gets the details for one employee only. Create an array of employees (or a vector) and then use a for loop to get the info for each one.

For some reason folks, I think I"m very close....I tried making it to 10 employees displayed. Works for the first 2 numbers, then I get crazy numbers after the first 2 employees are entered..not enabling me to properly type a third employee in and so on. Any ideas where I went wrong with my code?


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

#include <iostream>
#include <string>
#include <conio.h>

using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

class employee{
private:
float salary;
char name[10];
unsigned year_hired;

public:
void getemptdetails()
{

cout << "\n Enter the employee name." <<endl;
cin >> name;
cout <<" \n Enter the year hired." << endl;
cin >> year_hired;
cout << "\n Enter the salary of the employee." <<endl;
cin >> salary;
}
void showemptdata()
{

cout << " \n The name of the employee:" <<name;
cout << " \n The salary of the employee:" <<salary;
cout << " \n The year hired of the employee:" <<year_hired;
}
};
int main()
{
//create object for class
employee e1;
e1.getemptdetails(); //call member functions 
e1.showemptdata();
_getch();
employee e2;
e2.getemptdetails();
e2.showemptdata();
_getch();
employee e3;
e3.getemptdetails();
e3.showemptdata();
_getch();
employee e4;
e4.getemptdetails();
e4.showemptdata();
_getch();
employee e5;
e5.getemptdetails();
e5.showemptdata();
_getch();
employee e6;
e6.getemptdetails();
e6.showemptdata();
_getch();
employee e7;
e7.getemptdetails();
e7.showemptdata();
_getch();
employee e8;
e8.getemptdetails();
e8.showemptdata();
_getch();
employee e9;
e9.getemptdetails();
e9.showemptdata();
_getch();
employee e10;
e10.getemptdetails();
e10.showemptdata();
_getch(); 












system("pause");
return 0;
}

Topic archived. No new replies allowed.