设计Dog类 代码参考
#include <iostream>
#include <string> using namespace std; class Dog
{
private:
string name;
int age;
char sex;
double weight;
public:
void GetName(){cin>>name;return;}
void GetAge(){cin>>age;return;}
void GetSex(){cin>>sex;return;}
void GetWeight(){cin>>weight;return;}
void ShowMyDog(){
cout<<"It is my dog."<<endl;
cout<<"Its name is "<<name<<'.'<<endl;
cout<<"It is "<<age<<" years old."<<endl;
if(sex=='m') cout<<"It is male."<<endl;
else cout<<"It is female."<<endl;
cout<<"It is "<<weight<<" kg."<<endl;
return;
}
}; int main()
{
Dog one;
one.GetName();
one.GetAge();
one.GetSex();
one.GetWeight();
one.ShowMyDog();
return ;
}
设计Dog类 代码参考的更多相关文章
- 设计带构造函数的Dog类 代码参考
#include <iostream> #include <string> using namespace std; class Dog { private: string n ...
- 设计Person类 代码参考
#include <iostream> using namespace std; class Trapezium { private: int x1,y1,x2,y2,x3,y3,x4,y ...
- 设计MyTime类 代码参考
#include <iostream> #include <cstdio> using namespace std; class MyTime { private: int h ...
- 设计Weekday类 代码参考
#include <iostream> using namespace std; class Weekday { private: int num; public: void SetDay ...
- 设计一个多功能的MyTime类 代码参考
#include <iostream> #include <cstdio> using namespace std; class MyTime { private: int h ...
- 设计并测试Trapezium类 代码参考
#include <iostream> using namespace std; class Trapezium { private: int x1,y1,x2,y2,x3,y3,x4,y ...
- 从Student类和Teacher类多重派生Graduate类 代码参考
#include <iostream> #include <cstring> using namespace std; class Person { private: char ...
- 从Point类继承的Circle类 代码参考
#include <iostream> #include <cstring> using namespace std; class Point { private: int x ...
- 一个基类Person的多个派生类 代码参考
#include <iostream> #include <cstring> using namespace std; class Person { protected: ch ...
随机推荐
- 一个简单的wed服务器SHTTPD(6)———— SHTTPD错误处理的实现
//start from the very beginning,and to create greatness //@author: Chuangwei Lin //@E-mail:979951191 ...
- JavaScript toFixed() 实现四舍五入保留两位小数
const num = 18.186; let result; result = num.toFixed(2) console.log(result) // 18.19 注意,返回值为String类型
- js 箭头函数不适用的场景
箭头函数虽然方便但也不是每个地方都适用, 箭头函数在开发中可以十分方便的干预 this的指向,在一些情况下,是不需要对this的指向进行干预的,也就不适用箭头函数 1.构造函数的原型方法上 例如:Pe ...
- java基础篇 之 接口
组合接口时的名字冲突: 看下面这段代码: interface I1 { int f(); } interface I2 { void f(); } interface I3 { int f(int a ...
- spring学习笔记(四)我对spring中bean生命周期的理解
我相信大部分同学对spring中bean的生命周期都不陌生,但是如果要详细的说出每一个步骤,可能能说出来的也不多,我之前也是这样,前几天调了一下spring的源码,看了一点书,突然一下明朗了,理解了s ...
- 这么多Linux版本,你究竟该怎么选择?
Linux有非常多的版本,比如世面上常见的有 Ubuntu.RedHat.Fedora.Centos等等,这么多的版本我们究竟该选哪一个呢?今天我带大家对各个版本进行一下分析和比较,帮助大家来做出更好 ...
- 视频文件自动转rtsp流
最近碰到一个项目需要用到 rtsp 视频流做测试, 由于真实环境的 摄像头 并不能满足需求,故尝试了一下用本地视频文件转换成rtsp视频流做测试,记录一下~ 采用方案: Docker + EasyDa ...
- ubuntu上lib-ace库安装编译
描述下本人电脑情况: 虚拟机版本:VMware-workstation-full-v7.1.4: ACE版本:ACE6.0.0 虚拟机[Linux](http://lib.csdn.net/base/ ...
- 解决anaconda与pycharm冲突导致import无法使用
解决annacode与python冲突: 一.File->Setting-> 点击Add-> 然后就完美解决 二.记得重启,检查创建的项目是右键python package-> ...
- libevent到底是同步还是异步,是阻塞还是非阻塞
应该从不同角度看libevent的同步/异步.阻塞/非阻塞: IO数量的角度:select出来之前,会阻塞在一个io上,处理完成后再阻塞在下一个io上:之后就是把所有的io fd拿过来,都不阻塞,一个 ...