Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I\'m using C++ to build a credit card simulator. My code is already completed, h

ID: 3861060 • Letter: I

Question

I'm using C++ to build a credit card simulator. My code is already completed, however I am getting three error messages on my CreditCard.h file. The three error messages are

error C2327: 'CreditCard::lim' : is not a type name, static, or enumerator

error C2065: 'lim' : undeclared identifier

error C2864: 'CreditCard::bala' : only static const integral data members can be initialized within a class

Here is the link to my project file. I am using Microsoft Visual Studio 2012 to write this code, and am absolutely stuck on how to fix the problem. Please fix the errors so that the program compiles and runs correctly. You can simply post the code snippet that you changed if you prefer. Be sure the code compiles without error.

https://1drv.ms/u/s!AjLswKvo9tl3hCzsNBkY1IVPmgjN

Explanation / Answer

You are getting the error because you are trying to initialize the class member variable bala in its declaration. Class member variables need to be initialzied in constructor or any other method as applicable. So I have initialized bala in the constructor. The fixed code is given below . I tried to run the program , but looks like the functionality is not yet in place. None of the menu options were functioning as the name suggests.

I AM GIVING ONLY THE PART OF THE CODE THAT WAS FIXED. Please rate if the answer helped. Thank you.

CreditCard.h

class CreditCard
{
public:
   CreditCard();
   CreditCard(int bc);
   double getCredLimit();
   double getBalDue();
   int getAccNum();
   double credAvailable();
   int incre_Credit();
   void trans1();
   int cdInc();
   bool addingChrg(double chrgAmt, const std::string& desc);
   ~CreditCard();

private:
   int accNo;
   bool err;
   string mssg;
   double dueAmt;
   void wtStats();
   void logFl(string qu);
   string credName, credlastName;
   double lim;
   double bala;
   double payscale;
   double chrg;
};

CreditCard.cpp

CreditCard::CreditCard(void)
{
   string first;
   ifstream ifs;
   ostringstream oss;
   srand((unsigned)time(0));
   accNo = (rand() % 100000) + 1;
   oss << accNo << flush;
   first = "CC" + oss.str() + ".txt";
   ifs.open(first.c_str());

   while (ifs.is_open())
   {
       ifs.close();
       accNo = (rand() % 100000) + 1;
       oss << accNo << flush;
       first = "CC" + oss.str() + ".txt";
       ifs.open(first.c_str());
   }

   ifs.close();
   lim = 1000;
bala = lim;
   dueAmt = 0;
   credName = first;
   credlastName = "CCL" + oss.str() + ".txt";
   wtStats();
   logFl("Account " + oss.str() + " opened. ");
}
CreditCard::CreditCard(int bc)
{
   string first;
   ifstream ifs;
   ostringstream oss;
   err = false;
   oss << bc << flush;
   first = "CC" + oss.str() + ".txt";
   ifs.open(first.c_str());
   if (ifs.is_open())
   {
       accNo = bc;
       ifs >> lim;
       ifs >> dueAmt;
bala = lim - dueAmt;
       ifs.close();
       credName = first;
       credlastName = "CCL" + oss.str() + ".txt";
       logFl("Account " + oss.str() + " reopened.");
   }
   else
   {
       accNo = 0;
       lim = 0;
       dueAmt = 0;
       err = true;
       mssg = "Account " + oss.str() + " could not be opened.";
   }
}