Question: /* BEGIN - DO NOT EDIT CODE */ // File: main.cpp #include LoginAccount.h #include RegisteredLoginAccount.h #include GuestLoginAccount.h #include #include #include #include using namespace std; //prototypes

/* BEGIN - DO NOT EDIT CODE */

// File: main.cpp

#include "LoginAccount.h" #include "RegisteredLoginAccount.h" #include "GuestLoginAccount.h" #include #include #include #include

using namespace std;

//prototypes and constants const int ARRAY_SIZE = 20;

using number_of_records_t = int;

//Function Declarations. void readAccountsFromFile(ifstream& fin, RegisteredLoginAccount registeredAccounts[], number_of_records_t& registeredLength, GuestLoginAccount guestAccounts[], number_of_records_t& guestLength); bool openFileForInput(ifstream& ifs, const string& filename); bool openFileForOutput(ofstream& ofs, const string& filename); void writeAccountsToFile(ofstream& ofs, RegisteredLoginAccount registeredAccounts[], const number_of_records_t registeredLength, GuestLoginAccount guestAccounts[], const number_of_records_t guestLength); void writeAccountToFile(ofstream& ofs, const LoginAccount& account);

int main() { RegisteredLoginAccount registeredAccounts[ARRAY_SIZE]; GuestLoginAccount guestAccounts[ARRAY_SIZE]; number_of_records_t registeredLength; number_of_records_t guestLength; ifstream ifs; ofstream ofs;

/* Open the input file for reading. * Give an error message and exit if connection fails. */ if ( !openFileForInput(ifs, "loginAccounts.txt") ) { cerr << "Error reading file." << endl; exit(1); } /* Declare the integer variable, numberOfRecords to hold the actual number * of records read in. * Assign to it the value returned from the loadArrayFromFile() function. */ readAccountsFromFile(ifs, registeredAccounts, registeredLength, guestAccounts, guestLength); /* Open the output file for writing. * Give an error message and exit if connection fails. */ if ( !openFileForOutput(ofs, "accountsOutput.txt") ) { cerr << "Error writing file." << endl; exit(1); } writeAccountsToFile(ofs, registeredAccounts, registeredLength, guestAccounts, guestLength); cout << "File created successfully." << endl;

return 0; }// end main()

/* END - DO NOT EDIT CODE */

bool openFileForInput(ifstream& ifs, const string& filename) { /* * TODO (1): * * Attempt to open the stream and connect it to the filename given. * Return the result of the open attempt. */ ifs.open(filename, ios::in); if( !ifs.is_open() ) { cerr << "Error opening file." << endl; return false; } return true; }// end openFileForInput()

bool openFileForOutput(ofstream& ofs, const string& filename) { /* * TODO (2): * * Attempt to open the stream and connect it to the filename given. * Return the result of the open attempt. */ ofs.open(filename, ios::out); if( !ofs.is_open() ){ cerr << "Error opening file." << endl; return false; } return true; }// end openFileForOutput()

void readAccountsFromFile(ifstream& ifs, RegisteredLoginAccount registeredAccounts[], number_of_records_t& registeredLength, GuestLoginAccount guestAccounts[], number_of_records_t& guestLength) { /* * TODO (3): * * Read in the account records from the given stream. * * Records in the file are formatted as: * ,,,, * ... * is either 'r' or 'g'. * * Use these values to create 'Registered' or 'Guest' objects, which you are to store * in their respective arrays. Remember to use the build in function * int stoi(string s) * to convert a string to an integer. * * Make sure you close the file stream. */ }// end readAccountsFromFile()

void writeAccountsToFile(ofstream& ofs, RegisteredLoginAccount registeredAccounts[], const number_of_records_t registeredLength, GuestLoginAccount guestAccounts[], const number_of_records_t guestLength) {

/* TODO (4): * * Write each type of account record to the provided output stream. First * write all the 'registered' users, then all the 'guest' users. * * Call the function writeAccountToFile() to do so. * * Make sure you close the file stream. */ }// end writeAccountsToFile()

void writeAccountToFile(ofstream& ofs, const LoginAccount& account) { /* Each account received is of a subclass. Since the parameter is a * LoginAccount& type, and the toString() method is virtual, then * the actual object's (RegisteredLoginAccount or GuestLoginAccount) * toString() method is used. */ ofs << account << endl; }// end writeAccountToFile()

This is all of main. TODO #3 is where I am currently struggling. Registered and Guest accounts inherit fields from LoginAccount

string first; string last; string username;

string accountType;

RegisteredAccount gets the field string password and GuestLoginAccount gets the field int expirationInSeconds. Id add the header files but I'm out of space. If this is sufficient information for any help with TODO #3 I'd appreciate it. Thanks.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!