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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 秋天的菠菜

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

14.5

View Code

  1 /*
  2 author:shajin
  3 date:2013-4-6
  4 */
  5 #include <iostream>
  6 #include<math.h>
  7 using namespace std;
  8 class Shape
  9 {
 10 public:
 11     double area();
 12     double girth();
 13     void show();
 14 };
 15 double Shape::area()
 16 {
 17     return 0;
 18 }
 19 
 20 double Shape::girth()
 21 {
 22     return 0.0;
 23 }
 24 
 25 void Shape::show()
 26 {
 27     cout<<"Shape Object:"<<endl;
 28 }
 29 
 30 class Circle:public Shape
 31 {
 32 private:
 33     double radius;
 34 public:
 35     Circle(double radius=5.0);
 36     double area();
 37     double girth();
 38     void show();
 39 };
 40 
 41 
 42 Circle::Circle(double r)
 43 {
 44     radius=r;
 45 }
 46 
 47 double Circle::area()
 48 {
 49     return 3.14*radius*radius;
 50 }
 51 
 52 void Circle::show()
 53 {
 54     cout<<"Circle:"<<radius<<endl;
 55     cout<<"面积"<<area()<<endl;
 56     cout<<"周长"<<girth()<<endl;
 57 }
 58 
 59 double Circle::girth()
 60 {
 61     return 2*3.14*radius;
 62 }
 63 
 64 class Triangle:public Shape
 65 {
 66 private:
 67     double a,b,c;//三角形三边
 68 public:
 69     Triangle(double a=3.0,double b=4.0,double c=5.0);
 70     //需要判断是否能构成三角形
 71     double area();
 72     double girth();
 73     void show();
 74 };
 75 Triangle::Triangle(double a,double b,double c)
 76 {
 77     this->a=a;
 78     this->b=b;
 79     this->c=c;
 80 }
 81 double Triangle::area()
 82 {
 83     double s=(a+b+c)/2;
 84     return sqrt(s*(s-a)*(s-b)*(s-c));
 85 }
 86 double Triangle::girth()
 87 {
 88     return a+b+c;
 89 }
 90 void Triangle::show()
 91 {
 92     cout<<"Triangle:"<<a<<b<<c<<endl;
 93     cout<<"面积"<<area()<<endl;
 94     cout<<"周长"<<girth()<<endl;
 95 }
 96 
 97 
 98 class Rectangle:public Shape
 99 {
100 private:
101     double width,height;
102 public:
103     Rectangle(double w=1.0,double h=1.0);
104     double area();
105     double girth();
106     void show();
107 };
108 Rectangle::Rectangle(double w,double h)
109 {
110     width=w;
111     height=h;
112 }
113 double Rectangle::area()
114 {
115     return width*height;
116 }
117 double Rectangle::girth()
118 {
119     return 2*(width+height);
120 }
121 void Rectangle::show()
122 {
123     cout<<"Rectangle:"<<width<<height<<endl;
124     cout<<"面积"<<area()<<endl;
125     cout<<"周长"<<girth()<<endl;
126 }
127 void main()
128 {
129     Circle c(1);
130     c.show();
131 
132     Triangle t;
133     t.show();
134 
135     Rectangle r(3,4);
136     r.show();
137 }

14.6

View Code

 1 // 文件point.h: 类Point的定义
 2 #if !defined __POINT__H__
 3 #define __POINT__H__
 4 
 5 #include <iostream.h>
 6 
 7 class Point
 8 {
 9     friend ostream &operator << (ostream &, const Point &);
10 public:
11     // 重载的构造函数
12     Point(double = 0, double = 0);
13     Point(const Point &p); // 复制构造函数
14 
15     // 析构函数
16     ~Point();
17 
18     // 重载的定值函数
19     void setPoint(double a, double b);
20     void setPoint(Point &p);
21 
22     // 取值函数
23     double getX()const
24     {
25         return x;
26     } double getY()const
27     {
28         return y;
29     }
30 
31 private:
32     double x, y;
33 };
34 
35 #endif

View Code

 1 // 文件point.cpp: 类Point的实现
 2 #include "point.h"
 3 
 4 Point::Point(double a, double b)
 5 {
 6     x = a;
 7     y = b;
 8 }
 9 
10 Point::Point(const Point &p)
11 {
12     x = p.getX();
13     y = p.getY();
14 }
15 
16 Point::~Point(){}
17 
18 void Point::setPoint(double a, double b)
19 {
20     x = a;
21     y = b;
22 }
23 
24 void Point::setPoint(Point &p)
25 {
26     x = p.getX();
27     y = p.getY();
28 }
29 
30 ostream &operator << (ostream &os, const Point &point)
31 {
32     os << "(" << point.x << ", " << point.y << ")";
33     return os;
34 }

View Code

 1 // 文件line.h: 类Line的定义
 2 #if !defined __LINE__H__
 3 #define __LINE__H__
 4 
 5 #include <iostream.h>
 6 #include "point.h"
 7 
 8 class Line {
 9     friend ostream & operator<< (ostream &, const Line &);
10 public:
11     // 重载的构造函数
12     Line(double startX = 0, double startY = 0, double endX = 0, double endY = 0);
13     Line(Point start, Point end);
14     Line(Line &line);    //复制构造函数
15 
16     // 析构函数
17     ~Line();
18 
19     // 重载的定值函数
20     void setLine(double startX = 0, double startY = 0, double endX = 0, double endY = 0);
21     void setLine(Point , Point );
22 
23     double getLength() const; // 计算线段的长度
24 
25     // 取值函数
26     Point getStartPoint()  {return startPoint;}
27     Point getEndPoint()  {return endPoint;}
28 
29 private:
30     Point startPoint, endPoint;
31 };
32 
33 #endif

posted @ 2013-04-11 10:23  秋天的菠菜  阅读(319)  评论()    收藏  举报