惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
V
Visual Studio Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Threatpost
TaoSecurity Blog
TaoSecurity Blog
Engineering at Meta
Engineering at Meta
T
Troy Hunt's Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
H
Heimdal Security Blog
Webroot Blog
Webroot Blog
A
About on SuperTechFans
S
Securelist
Recorded Future
Recorded Future
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
阮一峰的网络日志
阮一峰的网络日志
S
SegmentFault 最新的问题
P
Palo Alto Networks Blog
F
Fortinet All Blogs
Hacker News: Ask HN
Hacker News: Ask HN
WordPress大学
WordPress大学
W
WeLiveSecurity
N
Netflix TechBlog - Medium
博客园 - 叶小钗
宝玉的分享
宝玉的分享
大猫的无限游戏
大猫的无限游戏
G
GRAHAM CLULEY
Schneier on Security
Schneier on Security
博客园 - 聂微东
www.infosecurity-magazine.com
www.infosecurity-magazine.com
小众软件
小众软件
博客园 - 【当耐特】
有赞技术团队
有赞技术团队
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
A
Arctic Wolf
C
CXSECURITY Database RSS Feed - CXSecurity.com
Google DeepMind News
Google DeepMind News
Security Latest
Security Latest
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
Threat Research - Cisco Blogs
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Spread Privacy
Spread Privacy
罗磊的独立博客
The Hacker News
The Hacker News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
IT之家
IT之家
B
Blog
GbyAI
GbyAI
Hugging Face - Blog
Hugging Face - Blog
Google Online Security Blog
Google Online Security Blog
MongoDB | Blog
MongoDB | Blog

博客园 - 秋天的菠菜

大学计算机基础实验 2013年信1204-1-2班小学期<程序设计技能训练>作品 C++程序设计(第2版)课后习题答案--第14章 C++程序设计(第2版)课后习题答案--第12章 C++程序设计(第2版)课后习题答案--第13章 C++程序设计(第2版)课后习题答案--第8章 C++程序设计(第2版)课后习题答案--第4章 关于指针的经典例题 Java多线程读文件比单线程提高效率的实例 第一门编程语言选谁?(转) C语言程序设计实验指导书 寂寞让生命如此美丽 循环结构经典程序 C语言初学者最容易犯的错误 正则表达式 用脚本类IDS抵御针对WEB的攻击 java实验一 方法和构造方法 java实验二 类和对象 java实验四 面向对象的综合应用 java实验三 类的继承与多态
C++程序设计(第2版)课后习题答案--第11章
秋天的菠菜 · 2013-03-18 · via 博客园 - 秋天的菠菜

11.9  定义分数类Rational......

View Code

 1 #include<iostream.h>
 2 #include<stdlib.h>
 3 class Rational{
 4 private:
 5     int fm,fz;
 6     int getZdgys(int a,int b);
 7 public:
 8     Rational(){
 9         fm=1;fz=0;
10     }
11     Rational(int a,int b);
12     friend Rational Add(Rational r1,Rational r2);
13     friend Rational Sub(Rational r1,Rational r2);
14     void Print1();
15     void Print2();
16 };
17 
18 Rational::Rational(int fm1,int fz1)
19 {
20     int t=getZdgys(fm1,fz1);
21     fm=fm1/t;
22     fz=fz1/t;
23 }
24 
25 void Rational::Print1()
26 {
27     cout<<fz<<"/"<<fm<<endl;
28 }
29 
30 void Rational::Print2()
31 {
32     cout<<(double(fz)/fm)<<endl;
33 }
34 
35 int Rational::getZdgys(int a,int b)
36 {
37     int t;
38     while(t=a%b)
39     {
40         a=b;
41         b=t;
42     }
43     return b;
44 }
45 
46 Rational Add(Rational r1,Rational r2)
47 {
48     int m= r1.fm*r2.fm;
49     int n= r1.fz*r2.fm+r1.fm*r2.fz;
50     Rational result(m,n);
51     return result;
52 }
53 Rational Sub(Rational r1,Rational r2)
54 {
55     int m= r1.fm*r2.fm;
56     int n= r1.fz*r2.fm-r1.fm*r2.fz;
57     Rational result(m,n);
58     return result;
59 }
60 void main()
61 {
62     Rational a(24,12);
63     Rational b(6,1);
64     Rational result;
65     result=Add(a,b);
66     result.Print1();
67     
68     result=Sub(a,b);
69     result.Print1();
70 }