C++内容
为什么下面这个程序运行后的结果,余额那里的数字是这样的,是哪里出现问题了吗,求解答
```c++
#include
#include //因为有字符串型数据,所以打开此头文件
using namespace std;
class coordinate
{
public:
coordinate();
void Draw(double num)//存钱
{
balance+=num;
cout<<"【操作】:存钱!"<>num;
cout<<"【数目】:¥"<"元。"<"【结果】:存入人民币:¥"<"元。"<"【您的余额】:¥"<"元。"<void Deposit(double num)//取钱
{
balance-=num;
cout<<"【操作】:取钱!"<>num;
cout<<"【数目】:¥"<"元。"<"【结果】:取出人民币:¥"<"元。"<"【您的余额】:¥"<"元。"<void ShowBalance(double num)
{
cout<<"【操作】:查询余额!"<"【您的余额】:¥"<"元。"<private:
string name; //定义name(姓名) 为string类型,字符串类型可以直接用=赋值
string number; //定义number (姓名)为string类型
double balance;//定义balance(余额)为double类
double password;//密码
double num;//钱
};
coordinate::coordinate()
{
cout<<"请进行账户初始化"<>name;
cin>>number;
cin>>password;
cin>>balance;
cout<<"【用户姓名】:"<"【用户账号】:"<"【账户密码】:"<"【账户余额】:"<Draw(num);
Deposit(num);
ShowBalance(num);
}
int main()
{
coordinate();
return 0;
}
不太明白你什么意思,但是我发现了一些问题,我对你的代码进行了小调整,你复制去运行一下
#include <iostream>
#include <string> //因为有字符串型数据,所以打开此头文件
using namespace std;
class coordinate {
public:
coordinate();
void Draw(double num) { //存钱
cout << "【操作】:存钱!" << endl;
cin >> num;
balance += num;
cout << "【数目】:¥" << num << "元。" << endl;
cout << "【结果】:存入人民币:¥" << num << "元。" << endl;
cout << "【您的余额】:¥" << balance << "元。" << endl;
}
void Deposit(double num) { //取钱
cout << "【操作】:取钱!" << endl;
cin >> num;
balance -= num;
cout << "【数目】:¥" << num << "元。" << endl;
cout << "【结果】:取出人民币:¥" << num << "元。" << endl;
cout << "【您的余额】:¥" << balance << "元。" << endl;
}
void ShowBalance(double num) {
cout << "【操作】:查询余额!" << endl;
cout << "【您的余额】:¥" << balance << "元。" << endl;
}
private:
string name; //定义name(姓名) 为string类型,字符串类型可以直接用=赋值
string number; //定义number (姓名)为string类型
double balance;//定义balance(余额)为double类
double password;//密码
double num;//钱
};
coordinate::coordinate() {
cout << "请进行账户初始化" << endl;
cin >> name;
cin >> number;
cin >> password;
cin >> balance;
cout << "【用户姓名】:" << name << endl;
cout << "【用户账号】:" << number << endl;
cout << "【账户密码】:" << password << endl;
cout << "【账户余额】:" << balance << endl;
Draw(num);
Deposit(num);
ShowBalance(num);
}
int main() {
coordinate();
return 0;
}
这个是运行结果