Answer to Question #322601 in C++ for 11111

Question #322601

A company wants you to write a C++ program to maintain the contact details of its employees. Employee has a name, email, phone number, education, address, office phone extension, room number. The number of employees in the company are 21 but the program should be scalable to handle more employees. The company admin will use this system and he should be able to add, update, delete, search, print individual employee record and to print list of all employees.

Your task is to tell me that how would you do that, by using algorithm (psedocode or flow chart).

 

1
Expert's answer
2022-04-02T09:58:39-0400
#include<iostream>
#include<string>
#include<map>

using namespace std;


void Menu()
{
	cout << "\nChoose from the following:"
		<< "\nA - Add employee"
		<< "\nP - Print the all employee"
		<< "\nD - Delete the employee"
		<< "\nU - Update the employee"
		<< "\nS - Search the employee"
		<< "\np -  Print the employee"
		<< "\nE - Exit program";
	cout << "\nMake a select: ";
}


struct Employee
{
	string email;
	int phone;
	string education;
	string address;
	int office_phone;
	int roomNo;
};


void AddEmployee(map<string, Employee>& m)
{
	string name;
	Employee e;
	cout << "Enter a name of the employee: ";
	cin >> name;
	cout << "Enter an email: ";
	cin >> e.email;
	cout << "Enter a phone: ";
	cin >> e.phone;
	cout << "Enter an education: ";
	cin >> e.education;
	cout << "Enter an address: ";
	cin >> e.address;
	cout << "Enter an office phone: ";
	cin >> e.office_phone;
	cout << "Enter a room number: ";
	cin >> e.roomNo;
	m[name] = e;
}


void PrintEmployees(map<string, Employee>& m)
{
	map<string, Employee>::iterator it;
	for (it = m.begin(); it != m.end(); ++it)
	{
		cout << it->first << " " << it->second.email << " "
			<< it->second.phone << " " << it->second.education<<" "
			<< it->second.address<<" "<< it->second.office_phone<<" "
			<< it->second.roomNo<<endl;
	}
}


void DeleteEmployee(map<string, Employee>& m)
{
	string name;
	cout << "Please, enter a name of Employee: ";
	cin >> name;
	m.erase(name);
}


void UpdateEmployee(map<string, Employee>& m)
{
	string name;
	cout << "Enter a name of the employee: ";
	cin >> name;
	cout << "Enter an email: ";
	cin >> m[name].email;
	cout << "Enter a phone: ";
	cin >> m[name].phone;
	cout << "Enter an education: ";
	cin >> m[name].education;
	cout << "Enter an address: ";
	cin >> m[name].address;
	cout << "Enter an office phone: ";
	cin >> m[name].phone;
	cout << "Enter a room number: ";
	cin >> m[name].roomNo;
}


void PrintEmpl(map<string, Employee>& m)
{
	string name;
	cout << "Please, enter a name of Employee: ";
	cin >> name;
	cout << name << " " << m[name].email << " "
		<< m[name].phone << " " << m[name].education
		<< m[name].address << m[name].office_phone
		<< m[name].roomNo << endl;
}


bool SearchEmpl(map<string, Employee>& m)
{
	string name;
	cout << "Please, enter a name of Employee: ";
	cin >> name;
	map<string, Employee>::iterator it;
	it = m.find(name);
	if (it != m.end())
		return true;
	else
		return false;
}


int main()
{
	map<string, Employee> m;
	cout << "Please, enter a primary parameters: \n";
	for (int i = 0; i < 2; i++)
	{
		AddEmployee(m);
	}
	char choice;
	do
	{
		Menu();
		cin >> choice;
		switch (choice)
		{
		case 'A':case 'a':
		{
			AddEmployee(m);
			break;
		}
		case 'P':
		{
			PrintEmployees(m);
			break;
		}
		case 'D':case 'd':
		{
			DeleteEmployee(m);
			break;
		}
		case 'U':case 'u':
		{
			UpdateEmployee(m);
			break;
		}
		case 'p':
		{
			PrintEmpl(m);
			break;
		}
		case 'S':case 's':
		{
			if (SearchEmpl(m))
				cout << "Employee is found!\n";
			else
				cout << "Employee is not found!\n";
			break;
		}
		}
	} while (choice != 'E');
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS