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

  • Comp Sci
  • Thread starter Isma
  • Start date
  • Tags
    C++
In summary, the conversation is about a C++ program for an online banking system. The code includes classes for User, Customer, and Administrator, as well as functions for creating and deleting accounts, changing passwords, and managing account information. The main issue being discussed is a problem with assigning account numbers and enabling/disabling accounts.
  • #1
Isma
27
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()
{
cout<<"\t\t\tWELCOME TO ONLINE BANKING SYSTEM"<<endl;
cout<<endl;
};

int getacctno();
int checkaccno(int );

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

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

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

}

void logout()
{
strcpy(login," ");
pw=0;
cout<<"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()
{
cout<<"\n\t\tWELCOME to CUSTOMER MENU\n\n";
cout<<"\t\t\t1. Display information"<<endl;
cout<<"\t\t\t2. Cash Transfer"<<endl;
cout<<"\t\t\t3. Withdraw Cash"<<endl;
cout<<"\t\t\t4. Display Balance"<<endl;
cout<<"\t\t\t5. Change password"<<endl;
cout<<"\t\t\t6. Log out"<<endl;
cout<<"\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()
{
cout<<"\tCustomer Information:"<<endl;
cout<<"\t\tName: "<<Name<<endl;
cout<<"\t\tAccount No.: "<<AcctNo<<endl;
cout<<"\t\tAddress: "<<Address<<endl;
cout<<"\t\tTelephone no.: "<<Tel<<endl;
cout<<"\t\tCurrent balance:Rs. "<<CurrentBalance<<endl;
}

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

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

cout<<"\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 defintion./*/

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

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

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

void changepw()
{
int newpw;
cout<<"Please enter ur new password : ";
cin>>newpw;
pw=newpw;
cout<<"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()
{
cout<<"\n\n\t\tWELCOME to ADMINISTRATOR MENU\n\n";
cout<<"\t\t\t1. Create New Account"<<endl;
cout<<"\t\t\t2. Delete Existing Account"<<endl;
cout<<"\t\t\t3. Update login data"<<endl;
cout<<"\t\t\t4. Search for Account"<<endl;
cout<<"\t\t\t5. Add balance"<<endl;
cout<<"\t\t\t6. Deduct balance"<<endl;
cout<<"\t\t\t7. View All Accounts"<<endl;
cout<<"\t\t\t8. Logout"<<endl;
cout<<"\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()
{
cout<<"Enter account number to be searched :";
int acct;
cin>>acct;
int n=checkaccno(acct);
if (n==0)
{
list[acct].display();
adminmenu();
}
else
{ cout<<"The account number "<<acct<<" doesn't exist\n";
search();
}
}
void addbalance()
{
cout<<"\tEnter account number to which balance is to be added : ";
int acct,amt;
cin>>acct;
cout<<"\tEnter the balance: ";
cin>>amt;
int n=checkaccno(acct);
if (n==0)
{
list[acct].CurrentBalance=list[acct].CurrentBalance+amt;
cout<<"Account updated successfully: \n\tThe current balance is:"<<list[acct].CurrentBalance;
}
else
{ cout<<"The account number "<<acct<<" doesn't exist\n";}
}

void dedbalance()
{
cout<<"\tEnter account number from which balance is to be deducted : ";
int acct,amt;
cin>>acct;
cout<<"\tEnter the balance: ";
cin>>amt;
int n=checkaccno(acct);
if (n==0)
{
list[acct].CurrentBalance=list[acct].CurrentBalance-amt;
cout<<"Account updated successfully: \n\tThe current balance is:"<<list[acct].CurrentBalance;
}
else
{ cout<<"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;
cout<<"Enter login for new account : ";
cin>>login;
check(login);
cout<<"Enter password for new account : ";
cin>>pw;
int n=getacctno();
strcpy(list[n].login,login);
list[n].pw=pw;
list[n].AcctNo=n;
cout<<"\nEnter personal details of customer : ";
cout<<"\n\t\tName: ";
cin>>Name;
strcpy(list[n].Name,Name);
cout<<"\n\t\tAddress: ";
cin>>Address;
strcpy(list[n].Address,Address);
cout<<"\n\t\tTelephone no.: ";
cin>>Tel;
list[n].Tel=Tel;
cout<<"\n\t\tCurrent balance:Rs. ";
cin>>CurrentBalance;
list[n].CurrentBalance=CurrentBalance;
cout<<"You have created a new account successfully."<<endl;
cout<<"The account no. of new account is "<<n;

}

void Administrator::delacct()
{
int accno;
cout<<"Enter account number you want to delete : ";
cin>>accno;
int n=checkaccno(accno);
if (n==0)
{ cout<<"The account "<<accno<<" is deleted.\n";}
else
{ cout<<"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)
{
cout<<"Login unavailable.Please enter another.\n";
createacct();
}
}

}
void Administrator::update()
{
cout<<"\tEnter right choice:\n";
cout<<"\t\t1. Change password\n\t\t2. Enable disable account:";
int choice;
cin>>choice;
if (choice==1)
{
cout<<"Enter the account number whose password is to be changed: ";
int acctno;
cin>>acctno;
int n=checkaccno(acctno);
if (n==0)
{ cout<<"Enter new password for account : ";
int newpw;
cin>>newpw;
list[acctno].pw=newpw;
cout<<"\tAccount updated.\n";
}
else
{ cout<<"The account number "<<acctno<<" doesn't exist\n";
update();
}
adminmenu();
}
if (choice==2)
{
cout<<"Enter the account number you want to Enable or Disable: ";
int acct;
cin>>acct;
int n=checkaccno(acct);
if (n==0)
{ cout<<"Enter 1 to enable and 2 to disable account "<<acct;;
int letter;
cin>>letter;
if (letter==1)
{
cout<<"\tAccount enabled.\n";
}
else if (letter==2)
{
cout<<"\tAccount disabled.\n";
}
else
{
cout<<"Enter valid choice.\n";
update();
}
}
else
{ cout<<"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)
{
cout<<"You have signed in successfully as Administrator."<<endl;
Ad.adminmenu();
}
else if (strcmp(A.login,Ad.login)==0 && A.pw!=Ad.pw)
{
cout<<"Wrong password for Administrator account."<<endl;
A.start();
}
else if (strcmp(A.login,Ad.login)!=0 && strcmp(A.login,Cust.login)!=0)
{
cout<<"Enter valid user name."<<endl;
A.start();
}

else if(strcmp(A.login,Cust.login)==0 && A.pw==Cust.pw)
{
cout<<"You have signed in successfully as Customer."<<endl;
Cust.custmenu();
}
else if(strcmp(A.login,Cust.login)==0 && A.pw!=Cust.pw)
{
cout<<"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
{cout<<"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
  • #2
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 throught the function. You should see the problem...
 
  • #3
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?
 

1. How do I create a new account on the online banking system using a C++ program?

To create a new account on the online banking system using a C++ program, you will need to first initialize the program with the necessary libraries and functions for user input and data storage. Then, you will prompt the user to enter their personal information, such as name, address, and contact information. Next, you will generate a unique account number and set a password for the account. Finally, you will store the account information in a database or text file for future use.

2. Can I create multiple accounts using the same C++ program?

Yes, you can create multiple accounts using the same C++ program. As long as you have a system in place to generate unique account numbers and store the account information separately, you can create as many accounts as needed.

3. Is it safe to create an account on the online banking system using a C++ program?

Creating an account on the online banking system using a C++ program can be safe as long as proper security measures are taken. This includes encrypting sensitive information, regularly updating the program to fix any vulnerabilities, and implementing secure login protocols.

4. Can I access my online banking account using the same C++ program?

Yes, you can access your online banking account using the same C++ program. You will need to prompt the user to enter their login credentials and then validate them using the stored account information. Once the login is successful, you can provide options for the user to view account information, make transactions, and perform other banking tasks.

5. How do I delete an account on the online banking system using a C++ program?

To delete an account on the online banking system using a C++ program, you will need to first prompt the user to enter their account number and password for verification. Once the account is verified, you can delete the account information from the database or text file. It is important to also inform the user that the account has been deleted and provide any necessary steps for closing the account completely.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
9
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
5
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
14
Views
4K
Back
Top