is my class defination right?? plz rep fast anyone....

#include <iostream>
#include <string.h>
class Bank_account
{
private:
int account_number;
string ac_holder_name;
double balance;

public:
void get_ac_number()
{
return account_number;
}
void get_ac_holder_name();
{
return ac_holder_name;
}
void withdraw(float money);
{
balance+=money;
}
void deposit(float money);
{
balance-=money;
}
double check_bal();
{
return balance;
}
};
No. You must understand that void is a return type which returns nothing. You are trying to return ints , strings, and doubles on void. Just change them to the proper return types and it should be fine. Also you might want to have a public constructor otherwise how are you going to initialize the account number, name , and balance.
closed account (Dy7SLyTq)
a) code tags!!!!
b) cstring
d) well it certainly looks like it would compile, but past that, we dont know what you mean by right
#include <iostream>
#include <string.h>
class Bank_account
{
private:
int account_number;
string ac_holder_name;
double balance;

public:
int get_ac_number()
{
return account_number;
}
string get_ac_holder_name();
{
return ac_holder_name;
}
double withdraw(float money);
{
balance+=money;
}
double deposit(float money);
{
balance-=money;
}
double check_bal();
{
return balance;
}
};

now what should i have to do.... actually i m confused what data should i protect and show.. can u edit or modify in my program?
i just have to define class i dont have to create main function...
please reply me buddies.................
closed account (Dy7SLyTq)
a) code tags!!!!
b) cstring
d) reposting the code doesnt help
e)well it certainly looks like it would compile, but past that, we dont know what you mean by right
sir actually my question is this:
1. Define a class to represent a “Bank Account.” Each bank account should, at least, have:

a. an account number

b. account holder’s name, and

c. balance.

Protect the state of each bank account and information regarding implementation by providing relevant public to get and set the state variable of the class. Provide definitions of at least the following:

d. Get/Set Account Number

e. Get/Set Account Title

f. Withdraw

g. Deposit
sir can u explain how should i do this step by step?
Only thing to add would probably be:
1
2
3
4
5
6
void set_ac_holder_name(string& new_name){
    ac_holder_name=new_name;
}
void set_ac_number(int new_ac_number){
   account_number=new_ac_number;
}

This is the "set" part of "get and set the state variable[s] of the class."
also withdraw should subtract from the balance
1
2
3
4
double withdraw(float money){
    balance-=money; 
    return balance
};

and deposit should add to it
1
2
3
4
double deposit(float money){
    balance+=money;
    return balance;
}

With the last methods, the added return value allows you to use the updated balance as a value when the function finishes. e.g.
1
2
double new_balance=current_account.withdraw(withdraw_amount);
cout<<"You have withdrawn $"<<withdraw_amount<<". Your remaining balance is $"<<new_balance<<"\n";
Which is why you would declare
double deposit()
instead of
void deposit() //no return value. return statement omitted
Last edited on
Topic archived. No new replies allowed.