第十一周项目1-点-圆-圆柱类族的设计(2)
2016-06-05 16:43
323 查看
/*
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:zwj.cpp
*作 者:李落才
*完成日期:2016年6月5日
*版 本 号:v1.0
*
*问题描述:按照提示,从基类开始逐渐完成点——圆——圆柱类族的设计。
*输入描述:
*程序输出:
*/
#include<iostream>
using namespace std;
class Point
{
public:
Point(double a=0,double b=0);
void show_point();
double getx(){return x;}
double gety(){return y;}
protected:
double x;
double y;
};
class Circle:public Point
{
protected:
double r;
public:
Circle(double a,double b,double c):Point(a,b),r(c){}
double area();
void show_circle();
};
Point::Point(double a,double b)
{
x=a;
y=b;
}
void Point::show_point()
{
cout<<"点的坐标为:"<<x<<","<<y<<endl;
}
double Circle::area()
{
return r*r*3.1415926 ;
}
void Circle::show_circle()
{
cout<<"圆的面积为:"<<area()<<endl;
}
int main()
{
Point p1(1,2);
Circle r1(1,2,2.0);
p1.show_point();
r1.show_circle();
return 0;
}
/*
*Copyright (c) 2016,烟台大学计算机学院
*All rights reserved.
*文件名称:zwj.cpp
*作 者:李落才
*完成日期:2016年6月5日
*版 本 号:v1.0
*
*问题描述:按照提示,从基类开始逐渐完成点——圆——圆柱类族的设计。
*输入描述:
*程序输出:
*/
#include<iostream>
using namespace std;
class Point
{
public:
Point(double a=0,double b=0);
void show_point();
double getx(){return x;}
double gety(){return y;}
protected:
double x;
double y;
};
class Circle:public Point
{
protected:
double r;
public:
Circle(double a,double b,double c):Point(a,b),r(c){}
double area();
void show_circle();
};
Point::Point(double a,double b)
{
x=a;
y=b;
}
void Point::show_point()
{
cout<<"点的坐标为:"<<x<<","<<y<<endl;
}
double Circle::area()
{
return r*r*3.1415926 ;
}
void Circle::show_circle()
{
cout<<"圆的面积为:"<<area()<<endl;
}
int main()
{
Point p1(1,2);
Circle r1(1,2,2.0);
p1.show_point();
r1.show_circle();
return 0;
}
/* *Copyright (c) 2016,烟台大学计算机学院 *All rights reserved. *文件名称:zwj.cpp *作 者:张伟晶 *完成日期:2016年5月4日 *版 本 号:v1.0 * *问题描述:按照提示,从基类开始逐渐完成点——圆——圆柱类族的设计。 *输入描述: *程序输出: */ #include<iostream> using namespace std; class Point { public: Point(double a=0,double b=0); void show_point(); double getx(){return x;} double gety(){return y;} protected: double x; double y; }; class Circle:public Point { protected: double r; public: Circle(double a,double b,double c):Point(a,b),r(c){} double area(); void show_circle(); }; Point::Point(double a,double b) { x=a; y=b; } void Point::show_point() { cout<<"点的坐标为:"<<x<<","<<y<<endl; } double Circle::area() { return r*r*3.1415926 ; } void Circle::show_circle() { cout<<"圆的面积为:"<<area()<<endl; } int main() { Point p1(1,2); Circle r1(1,2,2.0); p1.show_point(); r1.show_circle(); return 0; }
相关文章推荐
- Spark 基础 —— Array(数组)
- android中防止多次点击
- ACM天梯赛练习L1-012. 计算指数
- 一天一个shell命令 linux文本内容操作系列-grep命令详解
- mui.ajax与服务器(SpringMVC)传输json数据
- Java 环境下使用 AES 加密的特殊问题处理
- 指针相关
- mysql 5.7+版本时,若发现因根目录下,缺少data文件夹的情况
- 20150417指针衍生
- javaWeb4 jsp 内置对象
- 装饰模式
- 面试(一)
- 设计模式笔记-Visitor访问者模式
- 郑轻OJ 1103: 平均学分绩点(函数专题)留着以后自己算
- 第十一周项目1-点-圆-圆柱类族的设计(1)
- 求出现频率最多的那个字母和出现的次数
- c++第七次作业
- AngulaJs点击
- 渐行渐远的分答
- MySql-InnoDB-缓存管理