Question
Help with CC Simulator program using C++ in VS! ****My coding is not calculating per the below instructions and error with available credit < <
Help with CC Simulator program using C++ in VS!
****My coding is not calculating per the below instructions and error with available credit<<<
***My coding is below the instructions***
Below is what I would like the calculator to do:
Account operations include opening the account with an established limit, posting charges and payments, requesting a limit increase, and displaying account history. Data is stored in text files by account number so that you may run the program multiple times with the same account.
The CREDIT CARD class should handle the normal activities related to a credit card: a) creating the account, b) making charges and payments, and c) updating the credit balance and credit limits. In addition, the Credit Card class will keep account status and transaction histories in text files.
Develop the Credit Card class according to the following guidelines:
The class should either create a new account or load an old account if a valid account number is given. This would involve 2 constructors: one that takes no account number (and generates a new account) or one that accepts an account number and reads in the current values for the account. In the case of a new account, the Credit Card number should be a randomly generated value while the starting credit limit will be $1000. In the case of an existing account, you must verify that the account actually exists (i.e., there is already a non-empty account status file). The account status (only) data should be stored in a text file named as follows: CC + Account Number + .txt.
Methods for processing transactions must be included. These increase and decrease the credit card balance along with the remaining credit. Make sure that the operator cannot exceed his/her credit limit with any given charge amount. Each transaction should be stored in a credit card log file, with name as follows: CCL + account number + .txt
Allow for a request for a credit increase; increases are granted in $100 increments. Use a random number generator to determine whether a credit increase request is granted or denied.
The display of the transaction log is to be done in the view program (the program with main()) there should not be any screen output done by the Credit Card Class. Each transaction log entry is time-stamped when posted to the file (as seen from the sample run).
*****This is what I have so far by using VS C++*****
CreditCardSim.cpp
// CreditCardSim.cpp : main project file.
#include "stdafx.h"
#include "CreditCard.h"
#include
#include
using namespace std;
using namespace System;
int main()
{
srand((unsigned)time(nullptr));
CreditCard *cc;
char choice;
int acctno;
int answered;
double chrg = 0;
string charge_desc;
double payscale = 0;
int incr;
cout << "Welcome!" << endl;
cout << " New or Existing Account? (N/E): ";
cin >> choice;
choice = toupper(choice);
if (choice == 'N')
{
//new account creation
cc = new CreditCard();
if (cc->getAcctNo() == 0)
{
cout << "Account Not Created!";
return(1);
}
cout << "Credit account " << cc->getAcctNo() << " opened." << endl;
}
else
{
cout << "Enter account number: ";
cin.ignore(1000, ' ');
cin >> acctno;
cc = new CreditCard(acctno);
if (cc->getAcctNo() == 0)
{
cout << "Account doesn't exist!";
return (2);
}
cout << "Credit account " << cc->getAcctNo() << " was re-opened." << endl;
}
do
{
cout << "Limit = " << cc->getCreditLimit() << endl;
cout << "Account: " << cc->getAcctNo() << " Outstanding Balance: " << cc->getBalanceDue() << " Credit Limit: " << cc->getCreditLimit() << " Availble Credit: " << cc->getcredAvail() << endl;
cout << "0.Quit 1. New Charge 2. Payment 3. Credit Increase Request 4. Card History Choice: ";
cin >> answered;
if (cin.fail())
{
cin.clear();
cin.ignore();
}
switch (answered)
{
case 0:
cout << "Thanks!" << endl;
break;
case 1:
cout << "Charge Amount: ";
cin >> chrg;
if ((chrg - cc->getBalanceDue()) < cc->getCreditLimit())
{
cout << "Charge Description: ";
cin.clear();
cin.ignore();
getline(cin, charge_desc);
}
else
{
cout << "Over credit limit!" << endl;
}
break;
case 2:
cout << "Payment Amount: ";
cin >> payscale;
break;
case 3:
cout << "Request Increase (increments of 100): ";
cin >> incr;
break;
case 4:
break;
default:
cout << "You did not enter valid selection ";
break;
}
} while (answered != 0);
system("Pause");
return 0;
}
CreditCard.cpp
#include "stdafx.h"
#include "CreditCard.h"
#include
#include
#include
#include
using namespace std;
CreditCard::CreditCard(void)
{
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;
vcravail = 1000;
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 >> vcravail;
fin.close();
CCName = fName;
CCLName = "CCL" + n.str() + ".txt";
writelog("Account " + n.str() + " reopened.");
}
else
{
Ano = 0;
vCLimit = 0;
vBalDue = 0;
vcravail = 0;
vErr = true;
vEMsg = "Account " + n.str() + " could not be opened.";
}
}
int CreditCard::getAcctNo()
{
return Ano;
}
double CreditCard::getCreditLimit()
{
return vCLimit;
}
double CreditCard::getBalanceDue()
{
return vBalDue;
}
double CreditCard::getcredAvail()
{
return(vCLimit - vBalDue);
}
void CreditCard::trans1()
{
vcravail = vcravail - chrg + payscale;
vBalDue = vBalDue + chrg - payscale;
}
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()
{
}
CreditCard.h
#pragma once
#include
using namespace std;
class CreditCard
{
public:
CreditCard(void);
CreditCard(int a);
double getCreditLimit();
double getBalanceDue();
int getAcctNo();
double getcredAvail();
int incre_Credit();
void trans1();
int cdInc();
bool addingChrg(double chargAmt, const std::string & desc);
~CreditCard(void);
private:
int Ano;
bool vErr;
string vEMsg;
double vCLimit, vBalDue, vcravail;
void writestatus();
void writelog(string m);
string CCName, CCLName;
double bal = vCLimit;
double payscale;
double chrg;
};
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started