-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccount.cpp
More file actions
128 lines (110 loc) · 3.01 KB
/
Copy pathaccount.cpp
File metadata and controls
128 lines (110 loc) · 3.01 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Employee
{
private:
int employeeID;
string employeeName;
string employeeDepartment;
public:
// Constructors with default values
// defalut contructor
Employee() : employeeID(0), employeeName("#"), employeeDepartment("#") {}
Employee(int id, const string &name, const string &department) : employeeID(id), employeeName(name), employeeDepartment(department) {}
// Accessor methods
int getEmployeeID() const
{
return employeeID;
}
string getEmployeeName() const
{
return employeeName;
}
string getEmployeeDepartment() const
{
return employeeDepartment;
}
// Mutator method to update the employee's name
void setEmployeeName(const string &name)
{
employeeName = name;
}
// Display employee details
void display() const
{
cout << "Employee ID: " << employeeID << endl;
cout << "Employee Name: " << employeeName << endl;
cout << "Employee Department: " << employeeDepartment << endl;
}
};
int main()
{
vector<Employee> employees;
while (true)
{
cout << "Menu:" << endl;
cout << "a. Create new Employee record" << endl;
cout << "b. Update name based on ID" << endl;
cout << "c. Print All Employees" << endl;
cout << "d. Exit" << endl;
cout << "Enter your choice: ";
char choice;
cin >> choice;
switch (choice)
{
case 'a':
{
int id;
string name, department;
cout << "Enter Employee ID: ";
cin >> id;
cout << "Enter Employee Name: ";
cin >> name;
cout << "Enter Employee Department: ";
cin >> department;
employees.push_back(Employee(id, name, department));
}
break;
case 'b':
{
int searchID;
cout << "Enter Employee ID to update name: ";
cin >> searchID;
bool found = false;
for (Employee &emp : employees)
{
if (emp.getEmployeeID() == searchID)
{
string newName;
cout << "Enter new Employee Name: ";
cin >> newName;
emp.setEmployeeName(newName);
found = true;
break;
}
}
if (!found)
{
cout << "Employee not found." << endl;
}
}
break;
case 'c':
cout << "Employee List:" << endl;
for (const Employee &emp : employees)
{
emp.display();
cout << endl;
}
break;
case 'd':
cout << "Exiting program." << endl;
return 0;
default:
cout << "Invalid choice. Please try again." << endl;
}
}
return 0;
}