Jun 13, 2016 at 12:00pm UTC
Hi,
here is ny code for sample assignment. I am getting bank account details first and depending on those details I am going to perform the rest operation on the account. Please go through the code and let me know how to return string from function in one class so that I can use that in main.
I also want declare float balance=0 and rate as 8.0in the variable declaration time but compiler is showing error can anyone suggest better alternative.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
#include <iostream>
#include <cmath>
using namespace std;
class Account
{
public :
char name[100];
int acc_num;
char acc_type[4];
char getdata()
{
cout<<"\nEnter the name of account holder: " ;
cin>>name;
cout<<"\nEnter the 4 digit account number: " ;
cin>>acc_num;
cout<<"\nEnter account type:(enter 'save' for saving and 'curn' for current account holder): " ;
cin>>acc_type;
return acc_type;
}
};
class Sav_acct:public Account
{
protected :
float balance;
float withdraw_amt;
float rate;
float amount;
public :
void withdraw()
{
if (balance>500)
{
cout<<"\nEnter the amount to withdraw: " ;
cin>>withdraw_amt;
balance=balance-withdraw_amt;
}
else
{
cout<<"\nSorry sufficient balance not availbale in your account:" ;
}
}
void deposit()
{
cout<<"\nEnter the amount you want to diposit: " ;
cin>>amount;
balance=balance+amount;
}
void interest()
{
int dd,mm,yr;
float interest;
cout<<"\nEnter todays date:" ;
cin>>dd>>mm>>yr;
// day_interest=mm*30+dd;
balance=balance*(pow(1+rate,mm));
}
void balance_disp()
{
cout<<"\nAvailable balance in your account is :" <<balance<<endl;
}
};
class Cur_acct:public Account
{
protected :
float balance,withdraw_amt;
float rate;
public :
int CheckBook()
{
int choice;
cout<<"Enter 1 for check book request:" <<endl;
cout<<"Enter 2 if you already have a valid checkbook" <<endl;
cin>>choice;
return choice;
}
void withdraw()
{
int amount;
cout<<"Enter the amount you want to withdraw from your account: " ;
cin>>amount;
balance=balance-amount;
}
void deposit()
{
if (balance>500)
{
cout<<"\nEnter the amount to withdraw: " ;
cin>>withdraw_amt;
balance=balance-withdraw_amt;
}
else
{
cout<<"Sorry sufficient balance not availbale in your account:" <<endl;
cout<<"Your Rs.50 is getting deducted as service charges" <<endl;
balance=balance-50;
}
}
void interest()
{
int dd,mm,yr;
float interest;
cout<<"Enter todays date:" ;
cin>>dd>>mm>>yr;
balance=balance*mm*rate/100;
}
void balance_disp()
{
cout<<"Available balance in your account is :" <<balance<<endl;
}
};
int main()
{
int a;
cout << "\nWelcome to HDFC Bank" << endl;
Account act;
Sav_acct sa;
Cur_acct ca;
act.getdata();
if (acc_type='save' )
{
cout<<"Which operation would you like to perform" <<endl;
cout<<"Enter the option 1.Withdraw 2.Deposit" ;
cin>>a;
if (a=1)
{
sa.withdraw();
sa.balance_disp();
}
else if (a=2)
{
sa.deposit();
sa.balance_disp();
}
else
{
}
}
else if (acc_type='curn' )
{
cout<<"Which operation would you like to perform" <<endl;
cout<<"Enter the option 1.Withdraw 2.Deposit" ;
cin>>a;
if (a=1)
{
ca.withdraw();
ca.balance_disp();
}
else if (a=2)
{
ca.deposit();
ca.balance_disp();
}
else
{
}
}
return 0;
}
Last edited on Jun 13, 2016 at 12:05pm UTC
Jun 13, 2016 at 4:45pm UTC
Line 19: You're trying to return a pointer to a local variable. Function is expecting a char
to be returned.
Line 128,148: act_type is undefined. Did you mean to refer to the member variable of an Account instance?
Line 128,133,138,148,153,158: You're using the assignment operator (=), not the comparison operator (==).
Line 128, 148: You can't compare C-strings that way. You should use C++ std::string.
Lines 80-101: You appear to have the deposit() and withdraw() functions reversed.
Jun 14, 2016 at 4:41am UTC
thank a lot kemort
and AbstractionAnon
for your kind help.