Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a simple electronic runner’s journal that allows a user to log a list o

ID: 3535722 • Letter: C

Question

Create a simple electronic runner’s journal that allows a user

to log a list of runs. Your program must use

the “list†API in the C++ standard template library (STL). Your

program must keep track of a list of

attributes associated with each run in a global linked list data

structure. The program must implement at

least one class, which will hold the following class

variables:

• An integer variable to hold an identification number

associated with the log entry. This must be a

randomly generated number that contains exactly eight digits.

For example, 12896123. Duplicate

entries are not allowed.

• A string variable to hold the date of the log entry. The

entered date must be in the form

mm/dd/yyyy. If the user enters an invalid date format, the

program must print an error and reprompt

the user to enter the date in the correct format.

• A string variable to hold the time of day of the log entry

(i.e. the time that the run will start). The

entered date must be in the form hh:mm am or hh:mm pm. Again, if

the user enters an invalid

time format, the program must print an error and re-prompt the

user to enter the time in the

correct format.

• A string variable to hold the users goal.

• A string variable to hold the current weather (e.g. rainy,

cloudy, sunny, hot, cold, etc.).

• A string variable to hold the name of the route.

• A double variable to hold the distance of the run (in

miles)

• A string variable to hold the running time in the format

hh:mm:ss.

Provide the appropriate accessor methods to set and get the data for each of these class variables. For<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

example getRoute() and setRoute(string route). The main program must provide the following

functionality:

1. When the program is first started, it must read a data file called log.dat. If the file exists, the

program will load the data for each log entry into the global linked list data structure. If the

file does not exist, the program will start with an empty linked list.

2. Provide a simple text-based user interface that displays the name of your runner’s log and

allows the user to operate on the global linked list of log entries. Each log entry must be

placed in this global linked list as an object that will hold all of the information associated

with each run. The program interface will allow the user to do the following:

(a) Enter a run – allows the user to enter all of the fields for log entry associated for a

given run, except for the identification field, which will be an automatically

generated eight digit random number. After the data fields are entered, the program

will place the log entry in the global linked list data structure.

(b) Search for a run – allows the user to search for a log entry in the linked list based on

a given date. The program should prompt the user to enter a data in the form

mm/dd/yyyy. Display a message if there are no entries not found in the linked list

for a given date. If there are multiple entries for a given date, the program should

display all of the entries associated with that date.

(c) Modify a run – allows the user to modify any of the fields for a log entry (except for

the log identification number) in the linked list. Use the eight digit identification

number as the key to find the entry to modify. Display a message if the log entry is

not found in the linked list.

(d) Delete a run – allows the user to delete a log entry from the linked list using the eight

digit identification number as the key. Display a message if the item is not found in

the linked list.

(e) Display the log – displays all of the entries in the linked list. The feature will display

all of the fields associated with the each log entry. It should also print the total

number of miles for all of the entries in the linked list.

(f) Exit program – before the program exits, it must save all of the data for each log

entry that is contained within the linked list into the log.dat data file. At this point, if

the file does not exist, the program will create it.


Explanation / Answer

// char and wchar_t types

#include <string>

#include <iostream>

using namespace std;

int main( )

{

const basic_string <char> str1("TEST");

// uses the typedef for string word synonym to basic_string <char>

string str2("TEST");

// simple comparison between two objects of type basic_string

cout<<"String str1: "<<str1<<" String str2: "<<str2<<endl;

cout<<"Operation: (str1 == str2)"<<endl;

if(str1 == str2)

cout<<"Strings str1 & str2 are equal."<<endl;

else

cout<<"Strings str1 & str2 are not equal."<<endl;

// L - literal qualifier, long

const basic_string <wchar_t> str3(L"TESTING");

// uses the typedef for wstring word synonym to basic_string <wchar_t>

wstring str4(L"JUMPING");

// simple comparison between two objects of type basic_string <wchar_t>

cout<<" String str3: TESTING String str4: JUMPING"<<endl;

cout<<"Operation: (str3 == str4)"<<endl;

if(str3 == str4)

cout<<"Strings str3 & str4 are equal."<<endl;

else

cout<<"Strings str3 & str4 are not equal."<<endl;

return 0;

}



// concatenating using ‘+’ operator

#include <string>

#include <iostream>

using namespace std;

int main()

{

// declaring an object of type basic_string<char>

string str1("StringOne");

string str2("StringTwo");

// declaring a C-style string

char *str3 = "StringThree";

// declaring a character constant

char chr = '?';

cout<<"str1 string is = "<<str1<<endl;

cout<<"str2 string is = "<<str2<<endl;

cout<<"str3 C-style string is = "<<str3<<endl;

cout<<"A character constant chr is = "<<chr<<endl;

// concatenates an object of type basic_string with an object of type basic_string

cout<<" Operation: str12 = str1 + str2"<<endl;

string str12 = str1 + str2;

cout<<"str12 = "<<str12<<endl;

// concatenates an object of type basic_string with an object of C-style string type

cout<<" Operation: str13 = str1 + str3"<<endl;

string str13 = str1 + str3;

cout<<"str13 = "<<str13<<endl;

// concatenates an object of type basic_string with a character constant

cout<<" Operation: str13chr = str13 + chr"<<endl;

string str13chr = str13 + chr;

cout<<"str13chr = "<<str13chr<<endl;

return 0;

}

// the >= and <= operators

#include <string>

#include <iostream>

using namespace std;

int main( )

{

// declaring an objects of type basic_string<char>

string str1("testingone");

string str2("testingtwo");

cout<<"str1 string is = "<<str1<<endl;

cout<<"str2 string is = "<<str2<<endl;

// declaring a C-style string

char *str3 = "testingone";

cout<<"str3 C-style string is = "<<str3<<endl;

// comparison between left-side object of type basic_string & right-side object of type basic_string

cout<<" Operation: (str1 <= str2)"<<endl;

if(str1 <= str2)

cout<<"str1 is less than or equal to str2."<<endl;

else

cout<<"str1 is not less than or equal to str2."<<endl;

// a comparison between left-side object of C-style string type & right-side object of type basic_string

cout<<" Operation: (str3 <= str2)"<<endl;

if(str3 <= str2)

cout<<"str3 is less than or equal to str2."<<endl;

else

cout<<"str3 is not less than or equal to str2."<<endl;

// comparison between left-side object of type basic_string & right-side object of C-style string type

cout<<" Operation: (str1 <= str3)"<<endl;

if(str1 <= str3)

cout<<"str1 is less than or equal to str3."<<endl;

else

cout<<"str1 is not less than or equal to str3."<<endl;

// comparison between left-side object of type basic_string & right-side object of type basic_string

cout<<" Operation: (str1 >= str2)"<<endl;

if(str1 >= str2)

cout<<"str1 is greater than or equal to str2."<<endl;

else

cout<<"str1 is not greater than or equal to str2."<<endl;

// comparison between left-hand object of C-style string type & right-hand object of type basic_string

cout<<" Operation: (str3 >= str2)"<<endl;

if(str3 >= str2)

cout<<"str3 is greater than or equal to str2."<<endl;

else

cout<<"str3 is not greater than or equal to str2."<<endl;

// comparison between left-hand object of type basic_string & right-hand object of C-style string type

cout<<" Operation: (str1 >= str3)"<<endl;

if(str1 >= str3)

cout<<"str1 is greater than or equal to str3."<<endl;

else

cout<<"str1 is not greater than or equal to str3."<<endl;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote