C++ Primer:Exercises Section 1.5.1

线性模型:AR、MA、ARMA、ARMAX、ARX、ARARMAX、OE、BJ等 阅读详情

Sales_item.h
#ifndef SALESITEM_H
#define SALESITEM_H
#include <iostream>
#include <string>


class Sales_item
{
public:
 Sales_item(const std::string &book):isbn(book),units_sold(0),revenue(0.0){}
 Sales_item(std::istream &is){ is >> *this;}
 friend std::istream& operator>>(std::istream &,Sales_item &);
 friend std::ostream& operator<<(std::ostream &,const Sales_item &);
public:
 Sales_item & operator+=(const Sales_item&);
public:
 double avg_price() const;
 bool same_isbn(const Sales_item &rhs)const
 {
  return isbn == rhs.isbn;
 }
 Sales_item():units_sold(0),revenue(0.0){}
public:
 std::string isbn;
 unsigned units_sold;
 double revenue;
};

using std::istream;
using std::ostream;
Sales_item operator+(const Sales_item &,const Sales_item &);
inline bool operator==(const Sales_item &lhs,const Sales_item &rhs)
{
 return lhs.units_sold == rhs.units_sold && lhs.revenue == rhs.revenue && lhs.same_isbn(rhs);
}
inline bool operator!=(const Sales_item &lhs,const Sales_item &rhs)
{
 return !(lhs == rhs);
}

inline Sales_item & Sales_item::operator +=(const Sales_item &rhs)
{
 units_sold += rhs.units_sold;
 revenue += rhs.revenue;
 return *this;
}
inline Sales_item operator+(const Sales_item &lhs,const Sales_item &rhs)
{
 Sales_item ret(lhs);
 ret += rhs;
 return ret;
}
inline istream& operator>>(istream &in,Sales_item &s)
{
 double price;
 in >> s.isbn >> s.units_sold >> price;
 if(in)
  s.revenue = s.units_sold * price;
 else
  s = Sales_item();
 return in;
}
inline ostream& operator<<(ostream &out,const Sales_item &s)
{
 out << s.isbn << "\t" <<s.units_sold << "\t" << s.revenue << "\t" << s.avg_price();
 return out;
}
inline double Sales_item::avg_price() const
{
 if(units_sold)
  return revenue/units_sold;
 else
  return 0;
}
#endif



Exercise 1.21:本书配套网站的第一章的代码目录下有 Sales_item.h 源文件。复制该文件到你的工作目录。编写程序,循环遍历一组书的销售交易,读入每笔交易并将交易写至标准输出。

	std::cout << book.units_sold << std::endl;

Exercise 1.22:编写程序,读入两个具有相同 ISBN 的 Sales_item 对象并产生它们的和。

	Sales_item book1,book2;
	// read ISBN, number of copies sold, and sales price
	std::cin >> book1>>book2;
	// write ISBN, number of copies sold, total revenue, and average price
	std::cout << book1 + book2 << std::endl;

Exercise 1.23:编写程序,读入几个具有相同 ISBN 的交易,输出所有读入交易的和。

	Sales_item book1,book2;
	// read ISBN, number of copies sold, and sales price
	std::cin >> book1>>book2;
	// write ISBN, number of copies sold, total revenue, and average price
	std::cout << book1.units_sold + book2.units_sold << std::endl;



Anasys Workbanch实战解析:齿轮接触强度有限元分析全流程 本文详细解析了在Anasys Workbanch中进行齿轮接触强度有限元分析的全流程。从模型简化、材料赋予、接触对设置,到网格划分艺术、非线性接触求解调试,再到结果后处理与工程解读,提供了避开常见陷阱的实战经验,旨在帮助工程师精准评估齿轮强度与疲劳寿命。 阅读详情

相关推荐

角谱迭代与傅里叶变换迭代算法(GS)的原理及其实例演示分析

角谱迭代与傅里叶变换迭代算法(GS)的原理及其实例演示分析 目前,迭代法和强度传输方程(TIE)法是两类典型的非干涉相位检索技术(Phase Retrieval,被称为相位恢复、相位检索、相位反演法、相位复原等)。迭代法中的经典算法是Gerchberg-Saxton(GS),随后,出现了包括错误减少算法(ER)、混合输入输出法(HIO)、梯度搜索算法、角谱迭代算法等改进算法。...

简单光学 2万+

C++ Primer Section 1-5

Section 1-5 Introducing Class Sales_item Class A class in C++ is a data structure, a type. When we look at a class, we should focus on the legal operations of it and not bother to care about the ...

fitzleopard的博客 187

小白 虚拟机 kali_Linux安装 详细教程

安装版本:VMmare workstation pro kali_Linux 安装环境:Window10 首先我们先了解一下什么是kali_linux: Kali Linux是基于Debian的Linux发行版, 设计用于数字取证操作系统。每一季度更新一次。由Offensive Security Ltd维护和资助。最先由Offensive Security的Mati Aharoni和Devon Kearns通过重写BackTrack来完成,BackTrack是他们之前写的用于取证的Linux发行

m0_50917178的博客 9万+

习题1.23 编写程序,读入几个具有相同ISBN 的交易,输出所有读入交易的和。

#include #include"Sales_item.h" int main() {     Sales_item result,item;     while(std::cin>>item)     {         result+=item;                                   }     std::cout     return 0;

yyyooo ☺ cpp集散地 950

别再瞎改注册表了!实测Win10/Win11远程桌面60帧的正确姿势(附ToDesk对比)

本文深入解析Windows远程桌面60帧优化的科学方法,揭示常见误区并提供实测有效的解决方案。从版本差异到硬件加速,再到第三方工具对比(如ToDesk),帮助用户避开无效的注册表修改,实现流畅的远程桌面体验。

weixin_33738555的博客 341

海思Hi3519AV100 sensor移植实战:IMX586驱动调试与硬件验证全流程

本文详细解析了在海思Hi3519AV100平台上移植索尼IMX586传感器的全流程实战。内容涵盖从硬件I2C通信验证、驱动代码移植与修改,到内核配置、时钟设定,以及使用示波器进行硬件信号深度验证和ISP图像调优等关键步骤,为开发者提供了一套清晰、可复现的sensor移植与调试方法。

weixin_29168393的博客 395

C++Primer第五版 1.5.1节练习

练习1.20 在网站(书上提供)上,第一章的代码目录中包含了头文件Sales_item.h。将它拷贝到你自己的工作目录中。用它编写一个程序,读取一组书籍销售记录,将每条记录打印到标准输出上。   练习 1.21 编写程序,读取两个ISBN相同的Sales_item对象,输出它们的和。   练习 1.22 编写程序,读取多个具有相同ISBN的销售记录,输出其所有记录的和   答:1.20

Nick Feng 的小屋 2447

Altium Designer 18 将Gerber文件逆向转换成PCB(详细记录)

自己看了网上的教程,弄了很久,估计还有不足的地方,但是先把思路理一理(初学AD) 同时遇到了许多问题: 不是AD导出的Gerber估计不能自动识别层 要自己设置层顺序 要有钻孔文件数据制作NC工具(我也不懂是怎么说,就是size尺寸的) 这里记录一下,以防忘记。 正常顺序: 1.新建CAM 2.导入Gerber,选择CAM文件夹下的所有文件导入 3.设置层属性和物理顺序 4.设置NC工具 5.提取网络表 ...

lb_monkey的博客 1万+

C++Primer 类

Exercises Section 1.5.1 Exercise 1.21: The Web site (http://www.awprofessional.com/cpp_primer) contains a copy of Sales_item.h in the Chapter 1 code directo...

qq_41245033的博客 499

别再死磕U-Net了!用PyTorch手把手教你搭建ResUnet,搞定医学图像分割(附完整代码)

本文详细介绍了如何利用PyTorch搭建ResUnet模型,通过引入残差连接解决医学图像分割中的梯度消失、特征退化和细节丢失问题。与传统U-Net相比,ResUnet在Dice系数和收敛速度上均有显著提升,特别适合处理脑部MRI等复杂医学图像。文章还提供了完整的代码实现和关键训练技巧,帮助开发者快速掌握这一先进技术。

weixin_42552637的博客 327

【深度学习-番外1】Win10系统搭建VSCode+Anaconda+Pytorch+CUDA深度学习环境和框架全过程

本文将介绍在Windows 10系统下搭建深度学习环境的完整过程,包括安装Anaconda、CUDA、NVIDIA显卡驱动以及Pytorch框架。后续本专栏的Python语言下的深度学习环境都以本篇搭建的为准。

fengzhuqiaoqiu的博客 3998

C++primer习题--第1章

本文地址:http://www.cnblogs.com/archimedes/p/cpp-primer-chapter1-ans.html,转载请注明源地址。 【习题 1.3】 编一个程序,在标准输出上打印“Hello, World”。 #include &lt;iostream&gt; using namespace std; int main() { cout&lt;...

weixin_33982670的博客 236

从Power到HO:一文搞懂主流脑图谱在DPABI里怎么选,让你的rs-fMRI分析更精准

本文深入解析了rs-fMRI分析中主流脑图谱(如Power、HO、AAL等)在DPABI中的科学选择策略,帮助研究者根据不同的神经科学研究目标优化分析流程。从解剖学图谱到功能连接图谱的特性对比,到DPABI实操中的多图谱分析工作流,提供了全面的方法论指导,助力提升静息态功能磁共振成像(rs-fMRI)研究的精准度和可重复性。

weixin_30654583的博客 403

C++ Primer:Exercises Section 1.5.2

Exercise 1.24: 编写程序,读入几笔不同的交易。对于每笔新读入的交易,要确定它的 ISBN 是否和以前的交易的 ISBN 一样,并且记下每一个 ISBN 的交易的总数。通过给定多笔不同的交易来测试程序。这些交易必须代表多个不同的 ISBN,但是每个 ISBN 的记录应分在同一组。 Sales_item book1,book2,book3; Sales_item bookType

卖包子的大夫 735

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

C++ primer practice: 5.4.1 (Exercises section) answer

The is an answer (not the only one) for exercise 5.4.1: Remark it for my own path for program path #include #include using namespace std; int main(){ vector sVect; vector iVec; unsigned i

Achilles's Blog 989

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

C++ Primer:Exercises Section 1.1.1

Exercise 1.1:查看所用的编译器文档,了解它所用的文件命名规范。编译并运行本节的 main 程序。 int main() { return 0; } 由于此main函数没有执行任何操作,执行后无任何返回结果 Exercise 1.2:修改程序使其返回 -1。返回值 -1 通常作为程序运行失败的指示器。然而,系统不同,如何(甚至是否)报告 main

卖包子的大夫 889

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

c++ primer exercises section 4.1

Exercise 4.1 Assuming get_size is a function that taks no arguments and returns an int value, whic o the following definitions are illegal? Explain why? unsigned buf_siz = 1024; (a) int ia[buf_size]

Rachel Wang的little tree 578

C++ Primer:Exercises Section 2.2

Exercise 2.7: 解释下列字面值常量的不同之处。 (a) 'a',L 'a',"a",L"a" (b) 10, 10u, 10L, 10uL, 012, 0xC (c) 3.14, 3.14f, 3.14L (a)‘a’:单个字符a,L'a':宽单个字符a,“a”字符a与空字符,L"a"宽字符a与空字符 (b)10:整数,10U:无符号整数,10L:长整数型,10uL:

卖包子的大夫 797

C++ Primer:Exercises Section 2.3

Exercise 2.11: 编写程序,要求用户输入两个数——底数(base)和指数(exponent),输出底数的指数次方的结果。 int base,expond,result = 1; std::cin>>base>>expond; for (expond;expond > 0;expond--) { result *= base; } std::cout Exerc

卖包子的大夫 977

C++ Primer:Exercises Section 1.2.2

Exercise 1.3:编一个程序,在标准输出上打印“Hello, World”。 #include int main() { std::cout<<"Hello,World"<<std::endl; return 0; } Exercise 1.4:我们的程序利用内置的加法操作符“+”来产生两个数的和。编写程序,使用乘法操作符“*”产生两个数的积。 #include int ma

卖包子的大夫 589

C++Primer Section 2-1

Section 2-1 Primitive Built-in Types Section 2-1-1 Arithmetic Types Differences in Integer Types Differences between char wchar_t char16_t and char32_t Note Differences between short int long and long

fitzleopard的博客 517

C++ Primer:Exercises Section 2.1.2

Exercise 2.1: int、long 和 short 类型之间有什么差别? int 16位,short 16位,long 32位 Exercise 2.2: unsigned 和 signed 类型有什么差别? unsigned无符号型(大于等于0),signed带符号(任意数值) Exercise 2.3: 如果在某机器上 short 类型占 16 位,那么可以赋给 sho

卖包子的大夫 618

C++Primer(5th) Exercises Section 2.1.3

Exercise 2.5: Determine the type of each of the following literals. Explain the differences among the literals in each of the four examples: (a) ‘a’, L’a’, “a”, L”a” (b) 10, 10u, 10L, 10uL, 012...

bensoho的博客 497

C++Primer(第5版) Exercises Section 2.2.1

Exercise 2.9: Explain the following definitions. For those that are illegal, explain what’s wrong and how to correct it. (a) std::cin &gt;&gt; int input_value; (b) int i = { 3.14 }; (c) doub...

bensoho的博客 406

C++ Primer5 第一章练习题答案ps肯定有错误,只为交流,望各位大神指正

EXERCISES SECTION 1.1.1 Exercise 1.1: Review the documentation foryour compiler and determine what file naming convention it uses. Compile andrun the main program from page 2. Source files  .cpp; he

mgl58569的专栏 542

C++ Primer:Exercises Section 1.4.4

Exercise 1.18:编写程序,提示用户输入两个数并将这两个数范围内的每个数写到标准输出。 int v1, v2; std::cin >> v1 >> v2; // read input if (v1 > v2) { for (v2;v1>=v2;v2++) { std::cout<<v2<<std::endl; } } else if(v2 > v1)

卖包子的大夫 723
上一篇: C++ Primer:Exercises Section 1.4.4
下一篇: C++ Primer:Exercises Section 1.5.2
AwL_1124
博客等级 码龄19年 94粉丝 135原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值