Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating Lazy Delete method in Employee Code #6

Open
SharafEldein opened this issue Oct 21, 2020 · 0 comments
Open

Updating Lazy Delete method in Employee Code #6

SharafEldein opened this issue Oct 21, 2020 · 0 comments

Comments

@SharafEldein
Copy link

Problem :

ArabicCompetitiveProgramming/18-Programming-4kids/11_homework_10_answer_employees_v1.cpp

Here is my code without Lazy Delete Method:

#include
#include
#include
using namespace std;

const int MAX = 50;

int salary[MAX];
int age[MAX];
char gendrL[MAX];
string name[MAX];
int added = 0;

int main() {
while (true)
{
int choice = -1;
cout << "\n1) Add Employee Data \n";
cout << "2) Print All Employees \n";
cout << "3) Remove employee by age \n";
cout << "4) Update Employee salary \n\n";

	cin >> choice;
	
	while (choice < 1 || 4 < choice)
	{
		cout << "Invalid Choice. \n";
		cin >> choice;
	}

	switch (choice)
	{
	case 1:
		cout << "Enter  Name, Age, Salary, and Gender Letter(M/F) :   ";
		cin >> name[added] >> age[added] >> salary[added] >> gendrL[added];
		added++;
		break;
	case 2:
		cout << setw(10) << "NAME" << setw(12) << "Salary" << setw(10) << "Age" << setw(10) << "Gender" << "\n";
		for (int i = 0; i < 45; i++)
			cout << '-';
		cout << endl;

		for (int i = 0; i < added; i++) {
			cout << i + 1 << setw(10) << name[i] << setw(10) << salary[i] << setw(10) << age[i] << setw(10) << gendrL[i] << "\n";
		}
		break;
	case 3:
		int start, end;
		cout << "Enter Starting and Ending age:  ";
		cin >> start >> end;
		for (int i = 0; i < added; i++)
		{
			if (age[i] <= end && age[i] >= start) {
				for (int j = i; j < added; j++)
				{
					age[j] = age[j + 1];
					name[j] = name[j + 1];
					salary[j] = salary[j + 1];
					gendrL[j] = gendrL[j + 1];
				}
				added--;
				i--;
			}
		}
		break;
	
	case 4:
		string updateName;
		int updateSalary;
		int oldSalary = 0;
		cout << "Enter Employee Name, and Updated Salary:	";
		cin >> updateName >> updateSalary;

		for (int i = 0; i < added; i++)
			if (name[i] == updateName){
				oldSalary = salary[i];
				salary[i] = updateSalary;
			}
		break;
	}
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant