Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include "CreditCard.h"
- #include <iostream>
- #include <fstream>
- #include <ctime>
- #include <sstream>
- using namespace std;
- CreditCard::CreditCard()
- {
- string fName;
- ifstream fin;
- ostringstream n;
- srand((unsigned)time(0));
- Ano = (rand() % 100000) + 1;
- n << Ano << flush;
- fName = "CC" + n.str() + ".txt";
- fin.open(fName.c_str());
- while (fin.is_open())
- {
- fin.close();
- Ano = (rand() % 100000 + 1);
- n << Ano << flush;
- fName = "CC" + n.str() + ".txt";
- fin.open(fName.c_str());
- }
- fin.close();
- vCLimit = 1000;
- vBalDue = 0;
- CCName = fName;
- CCLName = "CCL" + n.str() + ".txt";
- writestatus();
- writelog("Account " + n.str() + "opened. ");
- }
- CreditCard::CreditCard(int a)
- {
- string fName;
- ifstream fin;
- ostringstream n;
- vErr = false;
- n << a << flush;
- fName = "CC" + n.str() + ".txt";
- fin.open(fName.c_str());
- if (fin.is_open())
- {
- Ano = a;
- fin >> vCLimit;
- fin >> vBalDue;
- fin.close();
- CCName = fName;
- CCLName = "CCL" + n.str() + ".txt";
- writelog("Account " + n.str() + " reopened. ");
- }
- else
- {
- Ano = 0;
- vCLimit = 0;
- vBalDue = 0;
- vErr = true;
- vEMsg = "Account " + n.str() + "could not be opened. ";
- }
- }
- void CreditCard::applyCharge(int charge)
- {
- vBalDue = vBalDue + charge;
- vCLimit = vCLimit - charge;
- }
- void CreditCard::applyPayment(int payment)
- {
- vBalDue = vBalDue - payment;
- vCLimit = vCLimit + payment;
- }
- int CreditCard::getAcctNo()
- {
- return Ano;
- }
- double CreditCard::getCreditLimit()
- {
- return vCLimit;
- }
- double CreditCard::getBalanceDue()
- {
- return vBalDue;
- }
- void CreditCard::writestatus()
- {
- vErr = false;
- vEMsg = "";
- ofstream fout;
- fout.open(CCName.c_str());
- if (fout.is_open())
- {
- fout << vCLimit << endl;
- fout << vBalDue << endl;
- fout.close();
- }
- else
- {
- vErr - true;
- vEMsg = "Unable to write status file. ";
- }
- }
- void CreditCard::writelog(string m)
- {
- vErr = false;
- vEMsg = "";
- time_t rawtime;
- time(&rawtime);
- ofstream fout;
- fout.open(CCLName.c_str(), ios_base::app);
- if (fout.is_open())
- {
- fout << m << " on " << ctime(&rawtime) << endl;
- fout.close();
- }
- else
- {
- vErr = true;
- vEMsg = "Unable to write log entry: " + m;
- }
- }
- CreditCard::~CreditCard()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement