ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

【C++】引用作为函数形参的练习

2022-07-15 15:31:34  阅读:241  来源: 互联网

标签:ft 形参 void 练习 free attempts accumlate C++ throws


 1 #include <iostream>
 2 
 3 using namespace std;
 4 
 5 struct free_throws
 6 {
 7     string name;
 8     int made;
 9     int attempts;
10     float percent;
11 };
12 
13 void set_pc(free_throws &ft);
14 void display(const free_throws &ft);
15 free_throws & accumlate(free_throws &target,const free_throws &source);
16 int main()
17 {
18     free_throws one = {"Rick",13,14};
19     free_throws two = {"jack",10,16};
20     free_throws three = {"Rose",11,13};
21     free_throws four = {"Mike",12,17};
22     free_throws team = {"Class 6",0,0};
23     set_pc(one);
24     display(one);
25     accumlate(accumlate(accumlate(accumlate(team,one),two),three),four);
26     display(team);
27     return 0;
28 }
29 
30 void set_pc(free_throws &ft)
31 {
32     if(ft.attempts != 0)
33         ft.percent = 100.0 * float(ft.made) / float(ft.attempts);
34     else
35         ft.attempts = 0;
36 }
37 
38 void display(const free_throws &ft)
39 {
40     cout << "Name: " << ft.name << endl;
41     cout << "Made: " << ft.made << "\t";
42     cout << "Attempt: " << ft.attempts << "\t";
43     cout << "Percent: " << ft.percent << endl;
44 }
45 
46 free_throws & accumlate(free_throws &target,const free_throws &source)
47 {
48     target.attempts += source.attempts;
49     target.made += source.made;
50     set_pc(target);
51     return target;
52 }

 

 

标签:ft,形参,void,练习,free,attempts,accumlate,C++,throws
来源: https://www.cnblogs.com/powercool/p/16481559.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有