Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include #include #define MAX 500 using namespace std; /********************************************************************** * Add text here to describe what the function main does. Also don't forget *

#include

#include

#include

#define MAX 500

using namespace std;

/**********************************************************************

* Add text here to describe what the function "main" does. Also don't forget

* to fill this out with meaningful text or YOU WILL LOSE POINTS.

***********************************************************************/

typedef struct AccessType

{

string username;

string filename;

long unsigned int time;

}

AccessRecord;

/*********************************************************************

* This function will read the file.

*********************************************************************/

void readFromFile(AccessRecord records[MAX],unsigned int &n)

{

string file;

ifstream ifs;

cout

cin >> file;

ifs.open(file.c_str());

if (ifs.is_open())

{

n = 0;

while (!ifs.eof())

{

ifs >> records[n].filename;

if (ifs.eof())

{

break;

}

ifs >> records[n].username >> records[n].time;

n++;

}

ifs.close();

}

else

{

cerr

}

}

/*********************************************************************

* This function will display the records

*********************************************************************/

void display(AccessRecord record)

{

cout

cout

cout

cout

cout

cout

}

/*********************************************************************

* This function will display the records that match.

*********************************************************************/

void displayAll(AccessRecord records[MAX],unsigned int n,long unsigned int s,long unsigned int e)

{

cout

cout

cout

cout

cout

cout

cout

cout

for (int i = 0; i

{

if (records[i].time >= s && records[i].time

{

cout

display(records[i]);

}

}

}

/*********************************************************************

* MAIN

*********************************************************************/

int main()

{

AccessRecord records[MAX];

unsigned int size = 0;

long unsigned int start;

long unsigned int end;

readFromFile(records,size);

cout

cin >> start;

cout

cin >> end;

cout

displayAll(records,size,start,end);

cout

cout

return 0;

}

image text in transcribedimage text in transcribed

Instructions Write a C++ program according to the following: 1. Build on your program from last week. . Use a struct (e.g, AccessRecord) that contains a username, filename, and a timestamp .Prompt the user for the name of a file . Read in a list of Access Records from the file and store it in an array of structs - Prompt the user for a start time and an end time for consideration. Display a list of all files that were accessed during that period along with the users that accessed them 2. When parsing the file, look for the following kinds of problems Timestamps that begin with characters Timestamps that are less than 1,000,000,000 Timestamps that are greater than 10,000,000,000 Lines that are missing filenames, usernames, or timestamps (i.e., only have 2 items instead of 3) 3. Create a function, parseLine that accepts a line (a string) and populates a struct for the AccessRecord 4. Create a function, parseFile, that parses the file one line at a time and passes that line to your parseLine function 5. If an error occurs, in the parseLine function, throw an exception that is a string with the text: "Error parsing line: xxxx xxxx xxxx" (where xxxx xxxx xxxx is replaced by the actual text of the line that had the error) 6. In the parseFile function, catch any errors, display the message, and move on to the next line A few hints Don't forget to change your assignment number in your file header to 03 A complete line can be read into a string via: getline(fin, myStr) If you include the string stream library "sstream", you can take a string, and treat it like a stream (think "cin" or "fin"). For example string line getline (fin, line); // The current line is now stored in the variable "line" stringstream ss; ss.str(line // load the line into "sS" // We can now use "ss" just like cin, and fin // For example, we can read variables from it: long timeStamp; ss >> timeStamp; // We can also check for failures: if (ss.fail()) Get started early, there are a few tricky aspects to this assignment

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Using Entity Relationship Diagrams

Authors: Sikha Saha Bagui, Richard Walsh Earp

3rd Edition

103201718X, 978-1032017181

Students also viewed these Databases questions

Question

When is it appropriate to use a root cause analysis

Answered: 1 week ago

Question

What is DDL?

Answered: 1 week ago