answersLogoWhite

0


Best Answer

Ideally you'd want to use a DBMS to store and retrieve the employee data, but we'll keep it simple and use some static data instead.

#include

#include

#include

#include

struct employee

{

std::string m_name;

unsigned m_id;

employee(std::string name, unsigned id): m_name(name), m_id(id) {}

};

std::vector employees;

void load_data ()

{

employees.push_back (employee ("Alan", 1));

employees.push_back (employee ("Brian", 2));

employees.push_back (employee ("Charles", 3));

employees.push_back (employee ("David", 4));

employees.push_back (employee ("Eric", 5));

}

unsigned input_id (std::string prompt)

{

unsigned id = 0;

while (1)

{

std::cout<

std::string input="";

getline (std::cin, input);

std::stringstream ss (input);

if (ss>>id)

break;

std::cout<<"Invalid input.\n";

}

return (id);

}

employee* locate (unsigned id)

{

for (unsigned i=0; i

{

if (employees[i].m_id == id)

return (&employees[i]);

}

return (NULL);

}

int main()

{

load_data ();

unsigned id=0;

do

{

if( id=input_id("Enter an employee ID (0 to exit)"))

{

if (employee* emp = locate( id ))

std::cout<m_name<<'\n'<

else

std::cout<<"There is no employee with that ID.\n"<

}

} while( id );

std::cout<

}

Example output

Enter an employee ID (0 to exit): 6

There is no employee with that ID.

Enter an employee ID (0 to exit): 5

Eric

Enter an employee ID (0 to exit): 2

Brian

Enter an employee ID (0 to exit): 0

User Avatar

Wiki User

10y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: C plus plus program that display an employees name by entering an id?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Write a program to display the name of days when a user enters a number?

write a program to display your name age class schoolname e-mail 2hobby based on choice


Write a program to display your name on computer screen?

Faisal


How do you write a c program to prints name?

Write a c program that reads your first name and surname when you enter them. Each part of your name should not be more than 12 characters. Finally, have the program display your full name.


What is the display name of the software program and the name of the document on which you are working?

There are thousands of different software programs. The programs name should be on the top of the page.


How do you create program that display your name?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { clrscr(); printf("Your name here"); getch(); }


Does A sheet tab display the name of a cell within a worksheet?

No. It can only display the name of the sheet.No. It can only display the name of the sheet.No. It can only display the name of the sheet.No. It can only display the name of the sheet.No. It can only display the name of the sheet.No. It can only display the name of the sheet.No. It can only display the name of the sheet.No. It can only display the name of the sheet.No. It can only display the name of the sheet.No. It can only display the name of the sheet.No. It can only display the name of the sheet.


Design an algorithm that will accept a perons name from the screen entered as surname first name separated by a comma Your program is to display the name as first name followed by three blanks?

Design an algorithm that will accept a perons's name from the screen entered as surname, first name, separated by a comma. Your program is to display the name as frist name, followed by three blanks, followed by the surname. -defining diagram -pseudocode algorithm


Can you change your username in RuneScape?

Not yet. But I think they're working on a program that will allow you to change your display name but keep your login id the same


What is Selena Gomez's display name?

Selena Gomez does not have a display name!!!


How do you run c programm with add two numbers?

1. Write the program 2. Compile and link it 3. Execute it by entering its name at command prompt


What is another name for monitor?

nothing


What box on the formula bar will allow you to select any cell by entering its cell number?

The Name Box, beside the formula bar, allows you to select a cell by entering its cell address.The Name Box, beside the formula bar, allows you to select a cell by entering its cell address.The Name Box, beside the formula bar, allows you to select a cell by entering its cell address.The Name Box, beside the formula bar, allows you to select a cell by entering its cell address.The Name Box, beside the formula bar, allows you to select a cell by entering its cell address.The Name Box, beside the formula bar, allows you to select a cell by entering its cell address.The Name Box, beside the formula bar, allows you to select a cell by entering its cell address.The Name Box, beside the formula bar, allows you to select a cell by entering its cell address.The Name Box, beside the formula bar, allows you to select a cell by entering its cell address.The Name Box, beside the formula bar, allows you to select a cell by entering its cell address.The Name Box, beside the formula bar, allows you to select a cell by entering its cell address.