当前位置: 首页 > news >正文

【C++ Primer Plus习题】10.1

问题:

这里是引用
在这里插入图片描述

解答:
main.cpp

#include <iostream>
#include "BankAccount.h"
using namespace std;int main()
{BankAccount BA1("韩立","韩跑跑",1);BA1.get_info();BankAccount BA;BA.init_account("姚国林", "amdin", 10000);BA.get_info();BA.deposit(1000);BA.get_info();BA.withdraw(2000);BA.get_info();return 0;
}

BankAccount.h

#pragma once
#include <iostream>
using namespace std;
class BankAccount
{
private:string fullname;string accid;double balance;
public:BankAccount();BankAccount(const string name, const string id, double bal);~BankAccount();void init_account(const string name, const string id, double bal);void get_info()const;void deposit(double cash);void withdraw(double cash);
};

BankAccount.cpp

#include "BankAccount.h"BankAccount::BankAccount()
{this->fullname = "";this->accid = "";this->balance = 0.0;
}
BankAccount::BankAccount(const string name, const string id, double bal)
{this->fullname = name;this->accid = id;this->balance = bal;
}
BankAccount::~BankAccount()
{}
void BankAccount::init_account(const string name, const string id, double bal)
{this->fullname = name;this->accid = id;this->balance = bal;
}
void BankAccount::get_info()const
{cout << "姓名为:" << this->fullname << endl;cout << "账号为:" << this->accid << endl;cout << "存款为:" << this->balance << endl;
}
void BankAccount::deposit(double cash)
{this->balance += cash;
}
void BankAccount::withdraw(double cash)
{this->balance -= cash;
}

运行结果:
在这里插入图片描述

考查点:

  • 类和对象
  • 分文件

2024年9月3日19:52:54


http://www.mrgr.cn/news/18985.html

相关文章:

  • chapter12-异常(Exception)——(注解)——day14
  • accelerate一些类和函数说明二
  • 记录一下安装腾讯混元文生图模型的艰辛历程
  • 新版某数字壳脱壳,过frida检测,及重打包
  • 全网都在学,2024最新大模型畅销的三本书!千言万语,尽在书中
  • KAN 学习 Day2 —— utils.py及spline.py 代码解读及测试
  • ES6 URL对象
  • java和js计算文件的SHA-256哈希值
  • 鼎曼高品质老白茶,在时光的声色里芬芳隽永
  • RDP最小化之后仍然保持UI渲染的方法
  • 【计算机网络】socket编程 --- 实现简易TCP网络程序
  • C++进阶面试题
  • 九月最新蜘蛛池|泛码网的SEO工具怎么样?
  • 【C++】---STL之用哈希桶模拟实现:unordered_set和unordered_map
  • EEPROM 扫盲
  • 十分钟让你彻底明白正则表达式
  • AI模型:追求全能还是专精?-- 之3:“智能”符号学诠释的程序逻辑分析
  • C++ ─── List的模拟实现
  • 牛心包瓣类医用生物瓣膜厚度无损检测
  • 暴力破解和撞库攻击有什么区别,怎么防御暴力破解和撞库攻击