answersLogoWhite

0

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

11y ago

What else can I help you with?

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 can you program a TI-83 Plus to find area under a curve?

To program a TI-83 Plus to find the area under a curve, you can use the built-in integration functionality. Start by entering the function you want to integrate using the Y= menu. Then, create a new program by accessing the PRGM menu, selecting NEW, and entering your program name. In the program, use the fnInt command to calculate the integral, specifying the function, variable, lower limit, and upper limit. Finally, display the result using the Disp command.


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


How do you program a PCR-T465 cash register to print the store name?

To program a PCR-T465 cash register to print the store name, first access the programming mode by pressing the &quot;Mode&quot; key and then entering the password if required. Navigate to the store settings or &quot;Program&quot; section, select the option for &quot;Store Name,&quot; and then input the desired name using the numeric keypad. Finally, save the changes and exit the programming mode to ensure the store name is printed on receipts.