一个新手关于C++编程的问题
我是大一的新生才开始学c++遇到一道题要编一个简单的银行存款取款查询余额的程序我自己写了个但是总是有错误谁能帮我修改一下。。由于是大一的新生尽量保持原创就用我写的里面自带...
我是大一的新生 才开始学c++ 遇到一道题 要编一个简单的银行存款 取款 查询余额的程序 我自己写了个 但是总是有错误 谁能帮我修改一下 。。
由于是大一的新生 尽量保持原创 就用我写的里面自带的语言
麻烦修改过后贴上来
实在是麻烦了 谢谢好心人。!
#include <iostream>
using std::cout;
using std::endl;
#include <string>
using std::string;
class Account
{
public:
Account(string initialBalance)
{ if(initialBalance>=0)
accountBalance=initialBalance;
if(initialBalance<0)
{ accountBalance=0;
cout<<"the initial balance was invalid"<<endl;
}
}
void Credit(string deposit)
{
presentAccountBalance=accountBalance+deposit;
}
void debit(string money)
{
if(money<=accountBalance)
presentAccountBalance=accountBalance-money;
if(money>accountBalance)
{
presentAccountBalance=accountBalance;
cout<<"Debit amount exceeded account balance"<<endl;
}
}
void getBalance()
{
cout<<"the present account balance is:"<<presentAccountBalance<<"!"<<endl;
}
}
int main()
{
int accountBalance;
string presentAccountBalance;
string initialBalance;
string deposit;
string money;
Account account1;
Account account2;
cout<<"please enter the initial balance for the account1:"<<endl;
getline(cin,initialBalance);
cout<<"please enter the initial balance for the account2:"<<endl;
getline(cin,initialBalance);
cout<<"please enter the deposit for the account1:"<<endl;
getline(cin,deposit);
cout<<"please enter the deposit for the account2:"<<endl;
getline(cin,deposit);
cout<<"please enter the money you want to take out from account1:"<<endl;
getline(cin,money);
cout<<"please enter the money you want to take out from account2:"<<endl;
getline(cin,money);
return 0
}
题目是这样的:创建一个Account的类 银行可以使用它表示客户的银行账户 这个类应该包括一个类型为int的数据成员 表示账户余额 这个类必须提供一个构造函数 它接受初始余额并用它初始化数据成员
这个构造函数应当确认初始余额的有效性 保证他大于或等于0 否则余额设定为0 并且显示错误信息
该类还要提供3个成员函数 存款 取款 和返回当前余额(getBalance) 具体的我写在程序里了 修改下 不要使用新的函数 我们还没学过。。 展开
由于是大一的新生 尽量保持原创 就用我写的里面自带的语言
麻烦修改过后贴上来
实在是麻烦了 谢谢好心人。!
#include <iostream>
using std::cout;
using std::endl;
#include <string>
using std::string;
class Account
{
public:
Account(string initialBalance)
{ if(initialBalance>=0)
accountBalance=initialBalance;
if(initialBalance<0)
{ accountBalance=0;
cout<<"the initial balance was invalid"<<endl;
}
}
void Credit(string deposit)
{
presentAccountBalance=accountBalance+deposit;
}
void debit(string money)
{
if(money<=accountBalance)
presentAccountBalance=accountBalance-money;
if(money>accountBalance)
{
presentAccountBalance=accountBalance;
cout<<"Debit amount exceeded account balance"<<endl;
}
}
void getBalance()
{
cout<<"the present account balance is:"<<presentAccountBalance<<"!"<<endl;
}
}
int main()
{
int accountBalance;
string presentAccountBalance;
string initialBalance;
string deposit;
string money;
Account account1;
Account account2;
cout<<"please enter the initial balance for the account1:"<<endl;
getline(cin,initialBalance);
cout<<"please enter the initial balance for the account2:"<<endl;
getline(cin,initialBalance);
cout<<"please enter the deposit for the account1:"<<endl;
getline(cin,deposit);
cout<<"please enter the deposit for the account2:"<<endl;
getline(cin,deposit);
cout<<"please enter the money you want to take out from account1:"<<endl;
getline(cin,money);
cout<<"please enter the money you want to take out from account2:"<<endl;
getline(cin,money);
return 0
}
题目是这样的:创建一个Account的类 银行可以使用它表示客户的银行账户 这个类应该包括一个类型为int的数据成员 表示账户余额 这个类必须提供一个构造函数 它接受初始余额并用它初始化数据成员
这个构造函数应当确认初始余额的有效性 保证他大于或等于0 否则余额设定为0 并且显示错误信息
该类还要提供3个成员函数 存款 取款 和返回当前余额(getBalance) 具体的我写在程序里了 修改下 不要使用新的函数 我们还没学过。。 展开
展开全部
= =这变量名..好长了...哈哈
是这样子的, int accountBalance;
string presentAccountBalance;
string initialBalance;
string deposit;
string money;这些应该都作为类的成员变量,
而且在你的程序里也没看到你用你写的成员函数了啊
类最后的} 后要加;
===========
建议你好好看看书上的例子把,这代码写的不合理
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
class Account
{
double accountBalance;
double presentAccountBalance;
double initialBalance;
double deposit;
double money;
public:
Account()
{ cout<<"please enter the initial balance for the account:"<<endl;
cin>>initialBalance;
if(initialBalance>=0)
accountBalance=initialBalance;
if(initialBalance<0)
{ accountBalance=0;
cout<<"the initial balance was invalid"<<endl;
}
}
void Credit()
{
cout<<"please enter the deposit for the account:"<<endl;
cin>>deposit;
presentAccountBalance=accountBalance+deposit;
}
void debit()
{
cout<<"please enter the money you want to take out from account:"<<endl;
cin>>money;
if(money<=accountBalance)
presentAccountBalance=accountBalance-money;
if(money>accountBalance)
{
presentAccountBalance=accountBalance;
cout<<"Debit amount exceeded account balance"<<endl;
}
}
void getBalance()
{
cout<<"the present account balance is:"<<presentAccountBalance<<"!"<<endl;
}
};
int main()
{
Account account1;
Account account2;
account1.Credit();
account1.debit();
account1.getBalance();
account2.Credit();
account2.debit();
account2.getBalance();
return 0;
}
是这样子的, int accountBalance;
string presentAccountBalance;
string initialBalance;
string deposit;
string money;这些应该都作为类的成员变量,
而且在你的程序里也没看到你用你写的成员函数了啊
类最后的} 后要加;
===========
建议你好好看看书上的例子把,这代码写的不合理
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
#include <string>
using std::string;
class Account
{
double accountBalance;
double presentAccountBalance;
double initialBalance;
double deposit;
double money;
public:
Account()
{ cout<<"please enter the initial balance for the account:"<<endl;
cin>>initialBalance;
if(initialBalance>=0)
accountBalance=initialBalance;
if(initialBalance<0)
{ accountBalance=0;
cout<<"the initial balance was invalid"<<endl;
}
}
void Credit()
{
cout<<"please enter the deposit for the account:"<<endl;
cin>>deposit;
presentAccountBalance=accountBalance+deposit;
}
void debit()
{
cout<<"please enter the money you want to take out from account:"<<endl;
cin>>money;
if(money<=accountBalance)
presentAccountBalance=accountBalance-money;
if(money>accountBalance)
{
presentAccountBalance=accountBalance;
cout<<"Debit amount exceeded account balance"<<endl;
}
}
void getBalance()
{
cout<<"the present account balance is:"<<presentAccountBalance<<"!"<<endl;
}
};
int main()
{
Account account1;
Account account2;
account1.Credit();
account1.debit();
account1.getBalance();
account2.Credit();
account2.debit();
account2.getBalance();
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询