Problem Write a C++ program that will allow a research lab manager to monitor th
ID: 3754272 • Letter: P
Question
Problem Write a C++ program that will allow a research lab manager to monitor the access to a research lab. Each member of the lab has access provided by their personal ID Card Your program will provide information about the timing of the arrivals and departures of the lab staff Your program will be provided with a dataset where each row records an event, which s represented by the following information: 1) ID number a positive integer number 2) Person's name - a string 3) Time of the event . a string in "O1:23AM-format ("dd:dd:AM" or "dddd:PM") Each event records the use of an ID card to either enter or exit the lab. A given data set corresponds to one day and is already sorted by ID number. You should assume that the lab is empty at the beginning of the day and events are consistent- a given person cannot enter or exit without the event being recorded, a given person cannot enter the lab twice without exiting once in between, etc The program should first read the events from a text file named "dataset t. It will contain up to 100 events. See the sample file on the class website. Then, it should offer the user a menu with the following options: 1. Display the events sorted by ID number 2. Display the events sorted by the time of event. 3. Print the person's name given his/her ID number 4. Find out whether some person is still in the lab given his/her ID number 5. Quit The program should perform the selected operation and then re-display the menu. Do not change the menu numbers associated with the operations. Display an error message if the user enters an inappropriate number For options 1 and 2, display the information for each event on a single, separate line. The values should line up in columns (use setw). Headers for the table are optional For the Lookup operations, label the output values appropriately. For options 3 and 4, If the person is not found, display an appropriate message. This program must be done in a Linux or Unix environment, using a command line compiler lke g++. Do not use codeblocks, edlipse, or Xcode to compile "Your program must compile and run, otherwise you will receive a score of 0. "The program must be modular (use top-down design), with significant work done "Use a partially filled array of structures to store the events: by functions. Each function should perform a single, well-defined task. Use a counter variable to count the number of events that are read in from the file and use this value as the size of the array for the search and sort functions. Your program should work for an input file with any number of events up to 100. You MUST use binary search for option 3, Lookup name by ID. TRACS. Please look at this code before you start implementing your program output from running my solution on that file (output2.bt). You may use (and modify) the code from the book. See the Resources tool in 'I will put a sample input file on the class website (dataset.tt) and the consoleExplanation / Answer
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct data {
int id;
string name;
string time;
};
struct data dataArrayId[1024] = {0,"",""};
struct data dataArrayTime[1024];
int ReadFile()
{
int i =0;
ifstream infile;
infile.open("dataset.txt");
while(!infile.eof())
{
infile >> dataArrayId[i].id;
infile >> dataArrayId[i].name;
infile >> dataArrayId[i++].time;
}
return i;
}
void Display(int events)
{
for(int i =0 ; i< events ; i++)
cout << dataArrayId[i].id << " " << dataArrayId[i].name << " " << dataArrayId[i].time << endl;
}
void SortByID(int events)
{
struct data temp;
{
};
for(int i =0; i< events-1 ; i++)
{
for(int j =0; j< events-i-1; j++)
{
if(dataArrayId[j].id > dataArrayId[j+1].id)
{
temp = dataArrayId[j];
dataArrayId[j] = dataArrayId[j+1];
dataArrayId[j+1] = temp;
}
}
}
}
int main()
{
int op = 0 ;
int events =0;
int id=0;
events = ReadFile() + 1;
int persionId=0;
int count=1 ;
while(op != 5)
{
cout << "1.Display the events sorted by ID number. " << "2.Display the events sorted by the time of event. " << "3.Print the person's name given his/her ID number. "<< "4.Find out whether some person is still in the lab given his/her ID number. " << "5.Quit" << endl;
cin >> op;
switch(op)
{
case 1:
SortByID(events);
Display(events);
break;
case 2:
/*need to make function */
break;
case 3:
cout << "Enter ID";
cin >> id;
for(int i =0 ; i< events ; i++)
{
if(dataArrayId[i].id == id)
{
cout << dataArrayId[i].id << "Name : " << dataArrayId[i].name << endl;
break;
}
else
continue;
}
break;
case 4:
for(int i = 0 ; i< events; i++)
{
count = 1;
persionId = dataArrayId[i].id;
for( i = i+1; i < events ; i++)
{
if(persionId == dataArrayId[i].id)
count++;
}
if(count%2 != 0)
{
if(i != events )
cout << dataArrayId[i-1].name << "is in lab" << endl;
}
}
break;
case 5:
exit(0);
break;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.