Create a New Account | Online Banking System | C++ Program

  • Context: Comp Sci 
  • Thread starter Thread starter Isma
  • Start date Start date
  • Tags Tags
    C++
Click For Summary
SUMMARY

The forum discussion revolves around a C++ program for an online banking system, specifically focusing on the account creation functionality within the Administrator class. The user reports an issue with the getacctno() function, which consistently returns the same account number, preventing new accounts from being assigned unique identifiers. Additionally, the user seeks guidance on implementing account enable/disable functionality. The discussion emphasizes the importance of code commenting and debugging techniques, such as using breakpoints to identify issues.

PREREQUISITES
  • Understanding of C++ programming language
  • Familiarity with object-oriented programming concepts
  • Knowledge of debugging techniques in C++
  • Experience with basic data structures in C++
NEXT STEPS
  • Implement code commenting practices to enhance code readability
  • Learn how to use breakpoints and debugging tools in C++ IDEs
  • Research the use of switch statements to simplify conditional logic
  • Explore C++ data structures for managing user accounts more effectively
USEFUL FOR

C++ developers, software engineers working on banking applications, and anyone interested in improving their debugging skills and code organization in object-oriented programming.

Isma
Messages
27
Reaction score
0
C++ program..Help!

Well i am working on an online banking system.Here is my code(not so ood but its a start)

#include <iostream>
#include <string>
using namespace std;

void header()
{
count<<"\t\t\tWELCOME TO ONLINE BANKING SYSTEM"<<endl;
count<<endl;
};

int getacctno();
int checkaccno(int );

class User
{
public:
char login[10];
int pw;

User()
{
strcpy(login,"");
pw=0;
}

void start()
{
count<<"\tPlease Enter your login and password"<<endl;
count<<"\t\tLogin:\t";
cin>>login;
count<<" "<<endl;
count<<"\t\tPassword:\t";
cin>>pw;
count<<" "<<endl;

}

void logout()
{
strcpy(login," ");
pw=0;
count<<"You have logged out successfully.\n\n";
start();
} //end of logout function

}; //end of class User

void logout(User );



class Customer:public User
{
public:
char Name[50];
int AcctNo;
char Address[150];
int Tel;
int CurrentBalance;

Customer():User()
{
strcpy(login,"");
pw=0;
strcpy(Name,"");
AcctNo=1;
strcpy(Address,"");
Tel=0;
CurrentBalance=0;
}
Customer(User A):User()
{
strcpy(login,"cust");
pw=1234;
strcpy(Name,"abd def");
AcctNo=0;
strcpy(Address,"H.no 101, abc street 31, Rawalpindi");
Tel=12345678;
CurrentBalance=5000;
}

void custmenu()
{
count<<"\n\t\tWELCOME to CUSTOMER MENU\n\n";
count<<"\t\t\t1. Display information"<<endl;
count<<"\t\t\t2. Cash Transfer"<<endl;
count<<"\t\t\t3. Withdraw Cash"<<endl;
count<<"\t\t\t4. Display Balance"<<endl;
count<<"\t\t\t5. Change password"<<endl;
count<<"\t\t\t6. Log out"<<endl;
count<<"\t\tEnter choice(1-6):";
int choice;
cin>>choice;

if (choice==1)
{
display();
custmenu();
}

else if (choice==2)
{
transfer();
}

else if (choice==3)
{
withdraw();
}

else if (choice==4)
{
displayBalance();
}

else if (choice==5)
{
changepw();
}

else if (choice==6)
{
logout();
}

}

void display()
{
count<<"\tCustomer Information:"<<endl;
count<<"\t\tName: "<<Name<<endl;
count<<"\t\tAccount No.: "<<AcctNo<<endl;
count<<"\t\tAddress: "<<Address<<endl;
count<<"\t\tTelephone no.: "<<Tel<<endl;
count<<"\t\tCurrent balance:Rs. "<<CurrentBalance<<endl;
}

void transfer()
{
int am;
long accno;
count<<"\tCash Transfer :"<<endl;
count<<"Amount to tranfer :Rs.";
cin>>am;

if (am<CurrentBalance && CurrentBalance<100)
{
count<<"No. of Account where money is to be tranfered :";
cin>>accno;
}
else if (am>CurrentBalance)
{
count<<"Amount of transfer is greater than Current Balance of your account."<<endl;
transfer();
}

count<<"\tTransfer of Rs."<<am<<" to acoount no. "<<accno<<" was successful."<<endl;

CurrentBalance=CurrentBalance-am;

/*/list[accno].CurrentBalance=list[accno].CurrentBalance+am;
This isn't working as list of customer must be defined after class definition
and function cannot be placed out of class as funtion prototype containing the
argument of type Customer will have to be placed before class count./*/

count<<"\tNow, the Balance of your account is Rs."<<CurrentBalance<<endl;
custmenu();
}

void withdraw()
{
int wd;
count<<"Please enter the amount to withdraw :Rs. ";
cin>>wd;
if (wd<CurrentBalance && CurrentBalance-wd>100)
{
CurrentBalance=CurrentBalance-wd;
count<<"Withdrawn amount: "<<wd;
}
else if (wd>CurrentBalance || CurrentBalance-wd<100)
{
count<<"Cannot Withdraw!Please check your Current Balance."<<endl;
}
custmenu();
}

void displayBalance()
{
count<<"Your account balance is Rs."<<CurrentBalance<<endl;
custmenu();
}

void changepw()
{
int newpw;
count<<"Please enter ur new password : ";
cin>>newpw;
pw=newpw;
count<<"Password changed successfully.\n";
custmenu();
}


}; //end of class Customer
Customer list[10];

class Administrator:public User
{
public:
Administrator():User()
{
strcpy(login,"admin");
pw= 123456;
} //end of default constructor

void adminmenu()
{
count<<"\n\n\t\tWELCOME to ADMINISTRATOR MENU\n\n";
count<<"\t\t\t1. Create New Account"<<endl;
count<<"\t\t\t2. Delete Existing Account"<<endl;
count<<"\t\t\t3. Update login data"<<endl;
count<<"\t\t\t4. Search for Account"<<endl;
count<<"\t\t\t5. Add balance"<<endl;
count<<"\t\t\t6. Deduct balance"<<endl;
count<<"\t\t\t7. View All Accounts"<<endl;
count<<"\t\t\t8. Logout"<<endl;
count<<"\t\tEnter choice(1-8):";
int choice;
cin>>choice;

if (choice==1)
{createacct();
adminmenu();}

if (choice==2)
{delacct();}

if (choice==3)
{update();}

if (choice==4)
{search();}

if (choice==5)
{addbalance();
adminmenu();}

if (choice==6)
{dedbalance();
adminmenu();}

if (choice==7)
{viewall();
adminmenu();}

if (choice==8)
{logout();}
}

void createacct();
void delacct();
void check(char[10] );
void update();
void search()
{
count<<"Enter account number to be searched :";
int acct;
cin>>acct;
int n=checkaccno(acct);
if (n==0)
{
list[acct].display();
adminmenu();
}
else
{ count<<"The account number "<<acct<<" doesn't exist\n";
search();
}
}
void addbalance()
{
count<<"\tEnter account number to which balance is to be added : ";
int acct,amt;
cin>>acct;
count<<"\tEnter the balance: ";
cin>>amt;
int n=checkaccno(acct);
if (n==0)
{
list[acct].CurrentBalance=list[acct].CurrentBalance+amt;
count<<"Account updated successfully: \n\tThe current balance is:"<<list[acct].CurrentBalance;
}
else
{ count<<"The account number "<<acct<<" doesn't exist\n";}
}

void dedbalance()
{
count<<"\tEnter account number from which balance is to be deducted : ";
int acct,amt;
cin>>acct;
count<<"\tEnter the balance: ";
cin>>amt;
int n=checkaccno(acct);
if (n==0)
{
list[acct].CurrentBalance=list[acct].CurrentBalance-amt;
count<<"Account updated successfully: \n\tThe current balance is:"<<list[acct].CurrentBalance;
}
else
{ count<<"The account number "<<acct<<" doesn't exist\n";}
}

void viewall()
{
for(int i=0;i<11;i++)
{
list.display();
}
}



}; //end of class Administrator

void Administrator::createacct()
{
char Name[50];
char Address[150];
int Tel;
int CurrentBalance;
count<<"Enter login for new account : ";
cin>>login;
check(login);
count<<"Enter password for new account : ";
cin>>pw;
int n=getacctno();
strcpy(list[n].login,login);
list[n].pw=pw;
list[n].AcctNo=n;
count<<"\nEnter personal details of customer : ";
count<<"\n\t\tName: ";
cin>>Name;
strcpy(list[n].Name,Name);
count<<"\n\t\tAddress: ";
cin>>Address;
strcpy(list[n].Address,Address);
count<<"\n\t\tTelephone no.: ";
cin>>Tel;
list[n].Tel=Tel;
count<<"\n\t\tCurrent balance:Rs. ";
cin>>CurrentBalance;
list[n].CurrentBalance=CurrentBalance;
count<<"You have created a new account successfully."<<endl;
count<<"The account no. of new account is "<<n;

}

void Administrator::delacct()
{
int accno;
count<<"Enter account number you want to delete : ";
cin>>accno;
int n=checkaccno(accno);
if (n==0)
{ count<<"The account "<<accno<<" is deleted.\n";}
else
{ count<<"The account number "<<accno<<" doesn't exist\n";
delacct();
}
adminmenu();
}

void Administrator::check(char login[10])
{
for(int i=0;i<11;i++)
{
if (strcmp(list.login,login)==0)
{
count<<"Login unavailable.Please enter another.\n";
createacct();
}
}

}
void Administrator::update()
{
count<<"\tEnter right choice:\n";
count<<"\t\t1. Change password\n\t\t2. Enable disable account:";
int choice;
cin>>choice;
if (choice==1)
{
count<<"Enter the account number whose password is to be changed: ";
int acctno;
cin>>acctno;
int n=checkaccno(acctno);
if (n==0)
{ count<<"Enter new password for account : ";
int newpw;
cin>>newpw;
list[acctno].pw=newpw;
count<<"\tAccount updated.\n";
}
else
{ count<<"The account number "<<acctno<<" doesn't exist\n";
update();
}
adminmenu();
}
if (choice==2)
{
count<<"Enter the account number you want to Enable or Disable: ";
int acct;
cin>>acct;
int n=checkaccno(acct);
if (n==0)
{ count<<"Enter 1 to enable and 2 to disable account "<<acct;;
int letter;
cin>>letter;
if (letter==1)
{
count<<"\tAccount enabled.\n";
}
else if (letter==2)
{
count<<"\tAccount disabled.\n";
}
else
{
count<<"Enter valid choice.\n";
update();
}
}
else
{ count<<"The account number "<<acct<<" doesn't exist\n";
update();
}
}
}


int main()
{
header();
User A;
Administrator Ad;
Customer Cust1;
Customer Cust(A);
A.start();

if (strcmp(A.login,Ad.login)==0 && A.pw==Ad.pw)
{
count<<"You have signed in successfully as Administrator."<<endl;
Ad.adminmenu();
}
else if (strcmp(A.login,Ad.login)==0 && A.pw!=Ad.pw)
{
count<<"Wrong password for Administrator account."<<endl;
A.start();
}
else if (strcmp(A.login,Ad.login)!=0 && strcmp(A.login,Cust.login)!=0)
{
count<<"Enter valid user name."<<endl;
A.start();
}

else if(strcmp(A.login,Cust.login)==0 && A.pw==Cust.pw)
{
count<<"You have signed in successfully as Customer."<<endl;
Cust.custmenu();
}
else if(strcmp(A.login,Cust.login)==0 && A.pw!=Cust.pw)
{
count<<"Wrong password for Customer account."<<endl;
A.start();
}


return 0;
} //end of main

int getacctno()
{
for (int i=0;i<11;i++)
{
if (strcmp(list.Name,"")==0)
{return i+1;}
else
{count<<"No account available\n";}
}
}

int checkaccno(int accno)
{
if (accno>-1 && accno<11)
{ return 0;}

}


Well the question is
Look at the create account function of class Administrator which calls getacctno() function. I am having problem assigning the account number to new account using this function, it returns same value always.
Also how can i enable nd disable an account.
 
Physics news on Phys.org
Ahhh, please make simplier

No one is going to debug many lines of uncommented code for you.

I would suggest commenting the code first. Say what it is doing and why. There is a good chance you will see the problem while doing that exercise. You should have done that anyway while writing the code.

If you have it well commented and still don't see the problem, put a break point in the method of interest and check the value of each variable carefully as you step through the function. You should see the problem...
 
I agree with learner, that's a lot of uncommented code. ALso why don't you just use a switch statement for all those if's?
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
1K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 24 ·
Replies
24
Views
2K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
8
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K