I\'m trying to Implement a Logger class and add a Logger object to this ATM Clas
ID: 3622631 • Letter: I
Question
I'm trying to Implement a Logger class and add a Logger object to this ATM Class using composition. I'm kind of stuck because I cannot seem to get anything working.
The log should be written to a text file on the hard drive and each entry should be appended to the file. Each Log entry should have a timestamp... The following classes should access the Logger: ATM, Withdrawal, Deposit, BalanceInquiry. Log all significant events such as Object creation & destruction, User Authentication failed/success, Execution of all ATM transaction types, etc...
Leave the user Authentication, I.E., the Account #'s and Pin $'s hard coded... A sample account:
Account #: 12345
Pin #: 54321
// What time is it?
// The Logger::Log() function will need this code
#include
#include
#include
#pragma warning( disable : 4996)
using namespace std;
void main(void)
{
// Test this first, then put it in Logger::Log()
char buf[30];
time_t rawtime;
time(&rawtime);
strcpy(buf, ctime(&rawtime));
buf[strlen(buf) - 1] = 0; // get rid of the LF
cout << buf;
}
Explanation / Answer
//Here is Log class implemented that can be used in other's class. #include #include using namespace std; class Logger { ofstream out; public: Logger(); // open the file in here void Log(char *); // log to the file here with a timestamp prefix ~Logger(); // close the file here }; Logger::Logger() { out.open("log.txt", ios::out | ios::app | ios::binary); } void Logger::Log(char *data) { if (out.is_open()) { char buf[30]; time_t rawtime; time(&rawtime); strcpy(buf, ctime(&rawtime)); buf[strlen(buf) - 1] = 0; // get rid of the LF coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.