1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. class Dog
  7. {
  8. private:
  9. string name;
  10. int age;
  11. char sex;
  12. double weight;
  13. public:
  14. void GetName(){cin>>name;return;}
  15. void GetAge(){cin>>age;return;}
  16. void GetSex(){cin>>sex;return;}
  17. void GetWeight(){cin>>weight;return;}
  18. void ShowMyDog(){
  19. cout<<"It is my dog."<<endl;
  20. cout<<"Its name is "<<name<<'.'<<endl;
  21. cout<<"It is "<<age<<" years old."<<endl;
  22. if(sex=='m') cout<<"It is male."<<endl;
  23. else cout<<"It is female."<<endl;
  24. cout<<"It is "<<weight<<" kg."<<endl;
  25. return;
  26. }
  27. };
  28.  
  29. int main()
  30. {
  31. Dog one;
  32. one.GetName();
  33. one.GetAge();
  34. one.GetSex();
  35. one.GetWeight();
  36. one.ShowMyDog();
  37. return ;
  38. }

设计Dog类 代码参考的更多相关文章

  1. 设计带构造函数的Dog类 代码参考

    #include <iostream> #include <string> using namespace std; class Dog { private: string n ...

  2. 设计Person类 代码参考

    #include <iostream> using namespace std; class Trapezium { private: int x1,y1,x2,y2,x3,y3,x4,y ...

  3. 设计MyTime类 代码参考

    #include <iostream> #include <cstdio> using namespace std; class MyTime { private: int h ...

  4. 设计Weekday类 代码参考

    #include <iostream> using namespace std; class Weekday { private: int num; public: void SetDay ...

  5. 设计一个多功能的MyTime类 代码参考

    #include <iostream> #include <cstdio> using namespace std; class MyTime { private: int h ...

  6. 设计并测试Trapezium类 代码参考

    #include <iostream> using namespace std; class Trapezium { private: int x1,y1,x2,y2,x3,y3,x4,y ...

  7. 从Student类和Teacher类多重派生Graduate类 代码参考

    #include <iostream> #include <cstring> using namespace std; class Person { private: char ...

  8. 从Point类继承的Circle类 代码参考

    #include <iostream> #include <cstring> using namespace std; class Point { private: int x ...

  9. 一个基类Person的多个派生类 代码参考

    #include <iostream> #include <cstring> using namespace std; class Person { protected: ch ...

随机推荐

  1. LeetCode 572. 另一个树的子树 | Python

    572. 另一个树的子树 题目来源:https://leetcode-cn.com/problems/subtree-of-another-tree 题目 给定两个非空二叉树 s 和 t,检验 s 中 ...

  2. P1666前缀单词

    题目传送门点我传送 Ⅰ.字典树+树型DP 非常奇妙的一种解法 第一部分:构建树 先对来的单词读入,插入字典树 然后对于一颗字典树,其实是有很多无用边的,所以我们需要删去一些边 删去非单词节点和非单词节 ...

  3. 【HBase】协处理器是什么?又能干什么?怎么用?

    目录 简单了解 官方帮助文档 协处理器出现的原因 协处理器的分类 Observer Endpoint Phoenix 协处理器的使用 加载方式 静态加载 动态加载 协处理器的卸载 协处理器Observ ...

  4. scala 隐式参数

    def test(implicit name: String = "susu"): Unit ={ println(name);} 三种调用方法如下:test("dudu ...

  5. vue项目-打印页面中指定区域的内容(亲测有效!)

    关于打印整个页面的,没什么好说的.今天我给大家分享一个打印指定区域的方法,你想打印哪里,就打印哪里! 我也是刚刚开始接触打印这一块功能的,然后当然是找度娘深入了解了一番啦,期间试了网上的各种方法,有的 ...

  6. [hdu4300] next数组的应用

    题意:给你一个密文和明文的对应表以及一个密文+明文的字符串,明文可能只出现前面的一部分(也就是说是原明文的前缀),求最短的明文. 思路:首先密文的长度至少占到一半,所以先把那一半解密,问题转化为找一个 ...

  7. Golang遍历删除数组

    Golang 做数字切片 package main import "fmt" /*遍历删除数组示例*/ func main() { //定义一个数组 a1 := []int{1, ...

  8. 关于fromdata的上传文件问题

    <div <label>上传pdf</label> <input id="fileId" type="file" accep ...

  9. HTML简单的伪装与造假

    利用浏览器制止台能简单的修改内容,致使其造成伪装. 打开网页控制台后,不要管那些眼花撩乱的代码,我们直接寻找控制台顶部的 Tab 栏 找到 Console 这个 Tab,点击它,把代码 documen ...

  10. linux-Curl error (37): Couldn't read a file:// file for file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-x86_64 [Couldn't open file /e tc/pki/rpm-gpg/RPM-GPG-KEY-fedora-x86_64]

    在安装Python3-pip 的时候遇到 [root@localhost rpm-gpg]# yum install python3-pipFedora 31 - x86_64 - Updates - ...