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

【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.kler.cn/news/289846.html

相关文章:

  • php邮箱服务器怎么搭建?如何构建服务器?
  • 【重学MySQL】四、关系型数据库设计规则
  • 在react中要将页面跳转有动画
  • 139. 单词拆分
  • 在线音乐播放器项目
  • Kafka【五】Buffer Cache (缓冲区缓存)、Page Cache (页缓存)和零拷贝技术
  • 五、Selenium操作指南(二)
  • 第二证券:涨停潮!传手机将使用钛金属外壳?
  • JVM(Java虚拟机)
  • 深入探索JNI:基础、最佳实践、性能优化与安全策略
  • Mental-LLM——通过在线文本数据利用大型语言模型进行心理健康预测
  • 【高级编程】实用类详解(中)String类及其常用方法 含判断邮箱格式案例
  • springboot使用缓存
  • Java实现加密(六)国密SM2算法
  • 【Qt】QChart折线图
  • ROS 编程入门
  • 集成电路学习:什么是IP知识产权
  • 本地搭建 Whisper 语音识别模型实现实时语音识别研究
  • 单线程Redis:Redis为什么这么快
  • 【html】编辑器、基础、属性、标题、段落、格式化、 连接、头部、CSS、图像
  • 微服务日常总结
  • 【主机入侵检测】Wazuh解码器之JSON解码器
  • 24并发设计模式——线程池模式
  • 台球助教系统小程序源码开发与技术解析
  • LLM大模型学习:LoRA 大模型微调的利器
  • 第三届人工智能与智能信息处理国际学术会议(AIIIP 2024)
  • 在SpringMVC中用fmt标签实现国际化/多语言
  • 装饰器模式(Decorator Pattern)
  • MACOS安装配置前端开发环境
  • 北芯生命持续亏损:产能利用率不理想仍扩产能,销售费用越来越高