Provided is a text file “schedule.txt.” It determines what I am doing at any giv
ID: 3752497 • Letter: P
Question
Provided is a text file “schedule.txt.” It determines what I am doing at any given time during the day. Your code will read those files, saving into 2 arrays the time and activity. Then a user can (1) put in a time, and the code will find and print the activity or (2) put in an activity, and print the time. Your task is in the following parts.
1) Write your search algorithm in pseudocode or a flowchart.
2) Write the code based on the pseudocode/flowchart.
3) Test the algorithm.
Along with this document, there are 2 files. The first is the daily schedule. The second is a template you can use. Abridge the template as you want. You must use the command line environment to run and test the code.
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 Dreaming Sleeping Snoring Nightmaring Stirring Snoozing Alarming Grooming Eating Driving Sitting Teaching Scarfing Whittling Lecturing Grading Napping Commuting Grilling Chilling Maxing Relaxing Snacking DozingExplanation / Answer
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void printMenu(){ //DO NOT TOUCH THIS PART
cout << endl << "---------------- ";
cout << "Enter 0 to exit ";
cout << "Enter 1 to search by number ";
cout << "Enter 2 to search by activity ";
}
int main(){
ifstream infile("Lab2_Schedule.txt");
int choice = 0;
int hour[24] = {0};
string activity[24] = {"Empty"};
int time_p;
string act;
int length=0;
for(int i = 0; i < 24; ++i)
{
if(!infile.eof()){
infile >> activity[i];
hour[i] = i;
length++;
}
else{
break;
}
}
do{
printMenu();
switch(choice){
case 1:
cout<<"Please enter the time :";
cin>>time_p;
cout<<"The activity at the time is: ";
if(time_p>length){
cout<<"Invalid time"<<endl;
}
cout<<activity[time_p]<<endl;
break;
case 2:
cout<<"Enter the activity :";
getline(cin, act);
cout<<"the time is: ";
for(int i =0; i< length; i++){
if(act == activity[i]){
cout << hour[i]<< endl;
}
}
break;
default:
break;
}
} while(choice != 0);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.