设计带构造函数的Dog类 代码参考
#include <iostream>
#include <string> using namespace std; class Dog
{
private:
string name;
int age;
char sex;
double weight;
public:
Dog(string,int,char,double);
void GetName(){cin>>name;return;}
void GetAge(){cin>>age;return;}
void GetSex(){cin>>sex;return;}
void GetWeigth(){cin>>weight;return;}
void speak(){cout<<"Arf!Arf!"<<endl;return;}
void show()
{
cout<<name<<endl;
cout<<age<<endl;
cout<<sex<<endl;
cout<<weight<<endl;
return;
}
}; Dog::Dog(string name, int age, char sex, double weight)
{
this->name=name;
this->age=age;
this->sex=sex;
this->weight=weight;
} int main()
{
string name;
int age;
char sex;
double weight;
cin>>name>>age>>sex>>weight;
Dog one(name,age,sex,weight);
one.show();
one.speak();
return ;
}
设计带构造函数的Dog类 代码参考的更多相关文章
- 设计Dog类 代码参考
#include <iostream> #include <string> using namespace std; class Dog { private: string n ...
- 设计一个多功能的MyTime类 代码参考
#include <iostream> #include <cstdio> using namespace std; class MyTime { private: int h ...
- 设计Person类 代码参考
#include <iostream> using namespace std; class Trapezium { private: int x1,y1,x2,y2,x3,y3,x4,y ...
- 设计并测试Trapezium类 代码参考
#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 ...
- 从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 ...
随机推荐
- 老师,你确定Java注释不会被执行吗?
之前在博客上分享过一篇文章,涉及到 Java 中的注释,就信誓旦旦地写了一句话:"注释是不会被执行的!"结果,有小伙伴留言说,"老师,你确定吗?" 我这个人一直 ...
- 获取Wi-Fi的SSID
前几天做项目的时候,碰到一个问题,获取wifi的SSID,其实就是获取Wi-Fi的名字 iOS12以前 在iOS13之前获取wifi的SSID很简单,苹果提供了接口CNCopyCurrentNetwo ...
- E - Help Jimmy POJ - 1661 dp
E - Help Jimmy POJ - 1661 这个题目本身不是很难,但是可以更加优化这个写法. 开始是n*n #include <cstdio> #include <cstri ...
- F - Power Network POJ - 1459
题目链接:https://vjudge.net/contest/299467#problem/F 这个是一个很简单的题目,但是读入很有意思,通过这个题目,我学会了一种新的读入方式. 一个旧的是(%d, ...
- [js进阶1]-数据类型
基本数据类型 js 总的有7中数据类型,包括基本类型和引用类型 基本类型 6 种 number boolean string null undefiend symbol 前5种类型统称为原始类型 sy ...
- STM32 使用st-link调试遇到写保护 Flash Timeout 问题的解决思路
本文介绍了如何解决STM32芯片Flash写保护导致无法下载程序,无法在线调试的问题:如果您遇到相同的问题,希望本文可以带来一些帮助: 如果本文帮到了您,请帮忙点个赞
- 日志系列1——slf4j日志框架原理
目录 1.前言 2.日志门面 3.日志库 4.日志适配器 5.日志库的选用 6.logback.xml 配置文件 1.前言 说到日志工具,日常工作或学习中肯定听过这些名词:log4j.logbac ...
- sqli-labs之Page-2
第二十一关:base64编码的cooki注入 YOUR COOKIE : uname = YWRtaW4= and expires: Tue 10 Mar 2020 - 03:42:09 注:YWRt ...
- Oracle用decode函数或CASE-WHEN实现自定义排序
1 问题 对SQL排序,只要在order by后面加字段就可以了,可以通过加desc或asc来选择降序或升序.但排序规则是默认的,数字.时间.字符串等都有自己默认的排序规则.有时候需要按自己的想法来排 ...
- virtualbox复制了以后网卡启动不了。
还是有些坑..必须踩 virtualbox复制了以后网卡启动不了.原因是如果没选重新生成mac ,那么mac地址会和第一台 机器一模一样,出现ip 征用的情况. 第二是系统方面的原因,你要删一个文件, ...