首页 > 其他分享 >2023.4.29

2023.4.29

时间:2023-04-29 19:12:51浏览次数:34  
标签:float 29 class 2023.4 using 习题 include public

 1 //课本习题8-5
 2 #include <iostream>
 3 #include <string>
 4 using namespace std;
 5 class Mammal
 6 {
 7 public:
 8     virtual void speak()
 9     {
10         cout<<"动物正在说话"<<endl;
11     }
12 };
13 class Dog:public Mammal
14 {
15 public:
16     void speak()
17     {
18         cout<<"dog正在说话"<<endl;
19     }
20 };
21 void test()
22 {
23     Dog d;
24     d.speak();
25     Mammal m;
26     m.speak();
27 }
28 int main()
29 {
30     test();
31     return 0;
32 }
 1 //课本习题8-6
 2 #include <iostream>
 3 #include <string>
 4 using namespace std;
 5 class Shape
 6 {
 7 public:
 8     virtual float getArea() = 0;
 9     virtual float getPerim() = 0;
10 };
11 class Rectangle:public Shape
12 {
13 public:
14     Rectangle(float L,float W)
15     {
16         l = L;
17         w = W;
18     }
19     float getArea()
20     {
21         cout<<"rectangle的面积:"<<l*w<<endl;
22         return l*w;
23     }
24     float getPerim()
25     {
26         cout<<"rectangle的周长:"<<(l+w)*2<<endl;
27         return (l+w)*2;
28     }
29 protected:
30     float l;
31     float w;
32 };
33 class Circle:public Shape
34 {
35 public:
36     Circle(float R)
37     {
38         r = R;
39     }
40     float getArea()
41     {
42         cout<<"circle的面积:"<<3.14*r<<endl;
43         return 3.14*r;
44     }
45     float getPerim()
46     {
47         cout<<"circle的周长:"<<2*3.14*r<<endl;
48         return 2*3.14*r;
49     }
50 protected:
51     float r;
52 };
53 void test()
54 {
55     Rectangle r(2,3);
56     Circle c(5);
57     r.getArea();
58     r.getPerim();
59     c.getArea();
60     c.getPerim();
61 }
62 int main()
63 {
64     test();
65     return 0;
66 }
 1 //课本习题8-7
 2 //运行失败
 3 #include <iostream>
 4 using namespace std;
 5 class Point
 6 {
 7     friend ostream& operator<<(ostream &cout,Point p);
 8 public:
 9     Point()
10     {
11         m_Num = 0;
12     }
13     //前置++
14     Point& operator++()
15     {
16         m_Num++;
17         return *this;
18     }
19     //后置++
20     Point operator++(int)
21     {
22         Point temp = *this;
23         m_Num++;
24         return temp;
25     }
26     //前置--
27     Point& operator--()
28     {
29         m_Num--;
30         return *this;
31     }
32     //后置--
33     Point operator--(int)
34     {
35         Point temp = *this;
36         m_Num--;
37         return temp;
38     }
39 private:
40     int m_Num;
41 };
42 ostream& operator<<(ostream& cout,Point p)
43 {
44     cout<<p;
45     return cout;
46 }
47 void test()
48 {
49     Point a;
50     cout<<"a++ = "<<a++<<endl;
51     cout<<"++a = "<<++a<<endl;
52 }
53 int main()
54 {
55     test();
56     return 0;
57 }

 

标签:float,29,class,2023.4,using,习题,include,public
From: https://www.cnblogs.com/muzhaodi/p/17364372.html

相关文章

  • 2023.4.29——软件工程日报
    所花时间(包括上课):0h代码量(行):0行博客量(篇):1篇今天,数学建模比赛中。。。我了解到的知识点:数学建模的相关知识 ......
  • SequoiaDB分布式数据库2023.4月刊
    本月看点速览赋能产业升级,荣获新睿之星聚焦金融,进一步探索非结构化数据价值释放再获肯定,入选2023年中国最佳信创厂商入围名单青杉计划2023已开启,一起攀登更高的“杉” 赋能产业升级,荣获新睿之星4月18日,2023年第九届广州国际投资年会在广州白云国际会议中心成功举办。会中......
  • 【230429-2】用三重循环输出立方体的八个顶点坐标
    【代码】packagetest230429;/***输出立方体的八个顶点坐标*边长为a的立方体一角在(0,0,0),其对角在(a,a,a),求所有顶点的坐标*这是一个可重排列问题,在2阶集合{"0","a"}中进行3次选取。*使用三重循环即可解决此问题。*/publicclassCubeTops{publicstaticvoid......
  • [ABC299F] Square Subsequence
    ProblemStatementYouaregivenastring$S$consistingoflowercaseEnglishletters.Printthenumberofnon-emptystrings$T$thatsatisfythefollowingcondition,modulo$998244353$.Theconcatenation$TT$oftwocopiesof$T$isasubsequenceof$S$(......
  • 2023.4.28——软件工程日报
    所花时间(包括上课):6h代码量(行):0行博客量(篇):1篇今天,上午学习,下午学习并开会。我了解到的知识点:1.了解了一些数据库的知识;2.了解了一些python的知识;3.了解了一些英语知识;5.了解了一些Javaweb的知识;4.了解了一些数学建模的知识;6.了解了一些计算机网络的知识;......
  • 2023.4.27
    1//实验六任务22//定义猫科动物Animal类,由其派生出猫类(Cat)和豹类(Leopard),3//在Animal类中定义虚函数,输出“MynameisAnimal”,在派生类中4//分别重新定义该函数,显示“Mynameis**”,其中**为各自类名5#include<iostream>6#include<string>7usingnamespa......
  • 2023.4.27
     1//实验六任务22#include<iostream>3#include<string>4usingnamespacestd;5classPeople6{7public:8People(){}9~People(){}10voidsetValue(intm,stringstr)11{12age=m;13name=str;......
  • 2023.4.27编程一小时打卡
    一、问题描述:建立一个向量容器的实例s,不断对s调用push_back向其中增加新的元素,观察在此过程中s.capacity()的变化。二、解题思路:首先,编写一个向量容器vector<int>s,利用循环对其进行不断调用push_back,再输出它的capacity()函数观察它向量容器的容量的变化。三、代码实现:1#in......
  • 2023.4.27
    //Parent.vue<template>   <childv-model="value"></child></template><script>exportdefault{   data(){       return{           value:1       }   }}//Child.vue<template>   <input:value="value&......
  • 2023.4.26《人月神话》读后感
    1.编程系统产品开发的工作量是供个人使用的、独立开发的构件程序的九倍。2. 编程行业的一些内在固有苦恼:● 将做事方式调整到追求完美,是学习编程的最困难部分。● 由其他人来设定目标,并且必须依靠自己无法控制的事物。● 真正的权威来自于每次任务的完成。● 任何创造性......