首页 > 其他分享 >打卡第一日

打卡第一日

时间:2023-04-12 21:25:17浏览次数:46  
标签:const 第一 float class base1 return 打卡 public

例7-1:

#include<iostream>

#include<cmath>

using namespace std;

class point {

public:

    void initpoint(float x = 0, float y = 0) { this->x = x; this->y = y; }

    void move(float offx, float offy) { x += offx; y += offy; }

    float getx()const { return x; }

    float gety()const { return y; }

private:

    float x, y;

};

class rectangle:public point {

public:

    void initrectangle(float x, float y, float w, float h) {

        initpoint(x, y);

        this->w = w;

        this->h = h;

    }

    float geth()const { return h; }

    float getw()const { return w; }

private:

    float w, h;

};

int main()

{

    rectangle rect;

    rect.initrectangle(2, 3, 20, 10);

    rect.move(3, 2);

    cout << "the data of rect(x,y,w,h):" << endl;

    cout << rect.getx() << ","

        << rect.gety() << ","

        << rect.getw() << ","

        << rect.geth() << endl;

    return 0;

 

}

例7-2:

#include<iostream>

#include<cmath>

using namespace std;

class point {

public:

    void initpoint(float x = 0, float y = 0) { this->x = x; this->y = y; }

    void move(float offx, float offy) { x += offx; y += offy; }

    float getx()const { return x; }

    float gety()const { return y; }

private:

    float x, y;

};

class rectangle :private point {  //私有继承不可访问父类函数;

public:

    void initrectangle(float x, float y, float w, float h) {

        initpoint(x, y);

        this->w = w;

        this->h = h;

    }

    float geth()const { return h; }

    float getw()const { return w; }

private:

    float w, h;

};

int main()

{

    rectangle rect;

    rect.initrectangle(2, 3, 20, 10);

    rect.move(3, 2);

    cout << "the data of rect(x,y,w,h):" << endl;

    cout << rect.getx() << ","

        << rect.gety() << ","

        << rect.getw() << ","

        << rect.geth() << endl;

    return 0;

}

例7-3:

#include<iostream>

using namespace std;

class base1{

public:

    void display()const { cout << "base1::display()" << endl; }

 

};

class base2:public base1 {

public:

    void display()const { cout << "base2::display()" << endl; }

};

class derived :public base2 {

public:

    void display()const { cout << "derived::display()" << endl; }

};

void fun(base1*ptr) {

    ptr->display();

}

int main()

{

    base1 base1;

    base2 base2;

    derived derive;

    fun(&base1);

    fun(&base2);

    fun(&derive);

    return 0;

}

 例7-4:

#include<iostream>

using namespace std;

class base1 {

public:

    base1(int i) { cout << "constructing base1" << i << endl; }

};

class base2 {

public:

    base2(int j) { cout << "construcrting base2" << j << endl; }

};

class base3 {

public:

    base3() { cout << "construing base3 *" << endl; }

};

class derived :public base2, public base1, public base3 {

public:

    derived(int a, int b, int c, int d) :base1(a), member2(d), member1(c), base2(b){

    }

private:

    base1 member1;

    base2 member2;

    base3 member3;

};

int main() {

    derived obj(1, 2, 3, 4);

    return 0;

}

 

标签:const,第一,float,class,base1,return,打卡,public
From: https://www.cnblogs.com/hlhl/p/17311301.html

相关文章

  • 每日打卡一小时
    //#include<iostream>//#include<cmath>//usingnamespacestd;//classfenshu//{//private:// intx,y;//public:// fenshu(intx=1,inty=1)// {// this->x=x,this->y=y;// if(x==0&&y!=0)// {// cout<<"0&quo......
  • 汇编_第一个可执行程序
    第一个可执行程序代码assumecs:codesg ;假设某一段寄存器和某一个程序段相联系codesgsegment ;定义一个段 movax,0123H movbx,0456H addax,bx addax,ax movax,4c00H int21H ;程序返回codesgendsend ;标识程序结束搭建汇编编译、链接和运行环境......
  • 第一天scrum站立会议博客(RTM队)
    今日团队任务:图片转excel(5天)前端开发(需团队风格统一)调用接口(后端),json数据->excel前后端连接           任烁玚(进行中)            图片转html(8天)前端开发(需团队风格统一)图片转为pdf(存储)pdf转html(调用接口)[html存储到数据库]前后台数据同......
  • 打卡第一天
    百钱百鸡问题:#include<iostream>usingnamespacestd;intmain(){ intx,y,z; for(intx=0;x<21;x++){ for(inty=0;y<34;y++){ for(intz=0;z<101;z++){ if(x*5+y*3+z/3.0==100&&x+y+z==100) printf("%d%d%d\n",x,y,z); } } } ......
  • 第一章概述
    1.概述1.1因特网概述1.1.1网络、互联网、因特网的联系首先,什么是网络呢?由上面的图我们就可以知道,网络就是由若干节点和链路连接构成的,而互联网就是若干网络和路由器连接构成,其中因特网就是最大的互联网注意:对于我们平常所说的互联网其实就是因特网,只是我们没有将其明确区......
  • Docker快速入门 第一篇
    目录Docker容器一、前言1、什么时虚拟化2、cocker是什么3、容器与虚拟化的区别4、Docker的概念二、安装dockerDocker容器一、前言1、什么时虚拟化在计算机中,虚拟化(英语:Virtualization)是一种资源管理技术,是将计算机的各种实体资源,如服务器、网络、内存及存储等,予以抽象、转......
  • 第一次团队项目召开会议
    我们初步的计划是我(队长)负责前端的书写,然后我的两个队员,一个负责后端的深度学习实现,另一个负责对数据进行训练和权重调整。我们的视频链接还在生成审核中,以下是我们的团队任务看板  以下是我们的第一阶段冲刺的纸上原型     其次是会议纪要首先讨论了第一阶段......
  • c++基础 打卡1
    一、面向对象的编程语言有的特点。    ①面向对象的编程语言最大的特点是结构化程序,二结构化程序的设计思路是自顶向下、逐步求精;其程序化结构是按功能划分为若干个基本模块,这些模块形成一个树状结构;各模块之间的关系尽可能简单,在功能上相对独立;每个模块内部均是由顺序、......
  • c++ 打卡第三天
    2023-04-12百钱百鸡问题一、问题描述。    一只公鸡值五钱,一只母鸡值三钱,三只小鸡值一钱,我可以通过三种鸡各买多少实现100钱买一百只鸡。二、设计思路。    ①通过以上题我们可以确定两个方程式      公鸡数量+母鸡数量+小鸡数量=100。   ......
  • 第一天打卡第三个问题
    问题描述:第一个人用10%的单利投资了100美元。第二个人用5%复利投资了100美元。请编写一个程序,计算多少年后第二个人的投资价值会超过第一个人的投资价值,并显示此时两个人的投资价值。解决思路:1.先建立两个变量用于存储第一个人和第二个人的投资价值2.建立一个循环体,在循环体......