Sir I am Trying to solve an Assignment so ca you please tell me what is the problem with my code,My Code is as following below the Prolem details,

My Assignment is as Follow;
Create a class in C++ name Account with the following Data members
•   AcNumber
•   AcHolderName
•   AcBalance
•   Actype
•   AcMinBalance
And the following member Functions

Identifier    Return type    Parameters
CreateNewAccount   Boolean   Integer AcNumber,
String AcType,
Long Deposit
ShowAcInfo   void   void (No parameters )
ShowAcInfo   void   String InfoType

In the CreateNewAccount member function the Deposit parameter must be assigned to the AcBalance field and others to their respective fields. Depending on the AcType value,the AcMinBalance field must be set. The following table provides us the required information

AcType Value   MinBalance
Savings   10000
Current    25000

If the deposit is less than MinBalance then the method must exit returning bolean value False or True.
Note that there are two ShowAcInfo() methods .The first one accepts no parameters,while the second takes in a string parameter (overloaded).
ShowAcInfo() that’s takes in no parameters print all the field values except the AcMinBalance field ,to the user’s console(screen).
The second ShowAcInfo() method takes in one string parameter (InfoType).This parameter must have one of the following values.
InfoType   Should Display
ShortInfo   AcNumber,AcBalance
LongInfo   All data members of the object

Additionally the class must also have
•   Default constructor, which must set AcType  to “Savings”  and AcMinBalance to 10000.
•   Parameterized constructor which takes in all the fields as parameters and assigns them to their respective fields
•   Set and Get functions for all data members of class
•   Destructor with no implementation (leave body of destructor empty)

In main function create object of Account class and create a new account by calling CreateNewAccount function for that object.
If new account not created successfully then display a message on screen “Your account cannot be opened”.
If new account created successfully then sample outputs are given below:
Sample Output 1:
Your Account has been opened successfully.
Enter ‘L’ for Long information of your Account.
Enter ‘S’ for Short information of your Account.
Account Number : 1
Account Holder Name: Ahmer Waqas
Account Balance : 15000
Account Type :  Saving
Sample Output 2:
Your Account has been opened successfully
Enter ‘L’ for Long information of your Account.
Enter ‘S’ for Short information of your Account.
Account Number : 1
Account Balance : 15000

#include <iostream>
#include <string>
using namespace std;
class Account
       bool CreateNewAccount(int ,string ,string ,long );
       void ShowAcInfo();
       void ShowAcInfo(string InfoType);
       void setAcNumber(int i);
       void setMinBalance(int i);
       void setAcBalance(int i);
       void setAcHolderName(string i);
       void setActype(string i);
       int getAcNumber();
       int getMinBalance();
       int getAcBalance();
       string getAcHolderName();
       string getActype();
       Account();// Constructor of a Class
  int AcNumber,AcMinBalance,AcBalance;
  string AcHolderName;
  string Actype;
   // Defining the Constructor setting default values of Actype and AcMinBalance
   Account::Account(string Actype,int AcMinBalance)
       Actype =="Savings";
       AcMinBalance = 10000;
   bool Account::CreateNewAccount(int AcNumber,string AcHolderName,string Actype,long Deposit)
       cout <<"Please Enter Account number: "<<endl;
       cin >>AcNumber;
       cout <<"Please Enter Account Holder Name: "<<endl;
       cin >>AcHolderName;
       cout <<"Please Enter Type of Your Account(savings or current): "<<endl;
       cout <<"Enter Your Amount to Deposit: "<<endl;
       cin >>Deposit;
       if(Actype == "Savings" && Deposit < 10000)
         cout <<"For Savings Type of Account You should Deposit a minimum of 10000"<<endl;
       }else if(Actype == "Current" && Deposit < 25000)
         cout <<"For Current Type of Account You should Deposit a minimum of 25000"<<endl;
         return false;
   void Account::ShowAcInfo(void)
       cout <<"Your Account Has been Opened Successfully"<<endl;    
       cout<<"Account no: "<<AcNumber<<endl;
       cout<<"Account Holder: "<<AcHolderName<<endl;
       cout<<"Account Type: "<<Actype<<endl;
void Account::ShowAcInfo(string InfoType)
   cout <<"Your Account Has been Opened Successfully"<<endl;
   cout <<"Enter 'L' for Long Information of Your Account\n";
   cout <<"Enter'S' for Short Information of Your Account"<<endl;
   cin >>InfoType;
   if(InfoType == "L" || InfoType == "l")
       cout << "Account no: "<<AcNumber<<endl;
       cout<<"Account Holder: "<<AcHolderName<<endl;
       cout <<"Account Balance: "<<AcBalance<<endl;
       cout<<"Account Type: "<<Actype<<endl;
   }else if(InfoType == "S" || InfoType == "s")
       cout<<"Account no: "<< AcNumber<<endl;
       cout <<"Account Balance: "<<AcBalance<<endl;
void Account::setAcNumber(int AcNumber)
void Account::setAcHolderName(string AcHolderName)
void Account::setAcBalance(int AcBalance)
void Account::setMinBalance(int MinBalance)
void Account::setActype(string Actype)
int Account::getAcNumber()
   return AcNumber;
string Account::getAcHolderName()
   return AcHolderName;
int Account::getAcBalance()
   return AcBalance;

string Account::getActype()
   return Actype;
   Account NewAccount;

Hello ird, thank you for the question.

I'm not entirely sure what your problem is since you didn't specify, but I've spotted a couple of issues with your code. Your mutator methods do not assign the new value.

void Account::setAcBalance(int AcBalance)

Should assign the private data member the new value:

void Account::setAcBalance(int Balance)
  AcBalance = Balance;

That way the class member value is physically updated when you call the method.

In your main function, you are passing data types into a method, which is not allowed. You should pass actual variables into this method:

NewAccount.CreateNewAccount(10, "someValue", "someValue", 400);

Instead of passing undefined variables and empty strings.

If your problem still persists, feel free to ask another question, and make sure you explain exactly what your problem is so I can assist as much as possible.

I hope this information was helpful.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by ExpertRating.com. I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2016 About.com. All rights reserved.