首页 > 其他分享 >5月22日打卡

5月22日打卡

时间:2023-05-22 18:34:12浏览次数:37  
标签:count return 22 Point int static 打卡 include

例具有静态数据、成员函数的Point类

代码部分:

 

#include<iostream>
using namespace std;
class Point {
private:
    int x, y;
    static int count;
public:
    Point(int x=0,int y=0):x(x),y(y)
    {
        count++;
    }
    Point(Point& p)
    {
        x = p.x;
        y = p.y;
        count++;
    }
    ~Point() { count--; }
    int getX() { return x; }
    int getY() { return y; }
    static void showCount() {
        cout << "Object count=" << count << endl;
    }
};
int Point::count = 0;
int main()
{
    Point a(4, 5);
    cout << "Point a:" << a.getX() << "," << a.getY();
    Point::showCount();
    Point b(a);
    cout << "Point B:" << b.getX() << "," << b.getY();
    Point::showCount();
    return 0;
}

例5-6

题目描述:

使用友元函数计算两点间的距离。

代码部分:

#include<iostream>
#include<cmath>
using namespace std;
class Point {
private:
    int x, y;
public:
    Point(int x = 0, int y = 0) :x(x), y(y) {};
    int getX() { return x; }
    int getY() { return y; }
    friend float dist(Point& p1, Point& p2)
    {
        double x = p1.x - p2.x;
        double y = p1.y - p2.y;
        return static_cast<float>(sqrt(x * x + y * y);
    }
};
int main()
{
    Point myp1(1, 1), myp2(4, 5);
    cout << "The distance is:";
    cout << dist(myp1, myp2) << endl;
    return 0;
}

 

标签:count,return,22,Point,int,static,打卡,include
From: https://www.cnblogs.com/xuechenhao173/p/17420711.html

相关文章

  • 打卡第三十一天
    定义基类Point和派生类Circle,求圆的周长一、1.Point类定义两个私有的数据成员floatx,y2.Circle类新增一个私有的数据成员半径floatr和一个公有的求周长的函数getCircumference()二、三、#include<iostream>#include<iomanip>#definePI3.14usingnamespacestd;classPoi......
  • 建民打卡日记5.22
    一、问题描述我们看到,把数字0-9翻倒,有的数字就认不出来了,比如2、3、4、5、7;有的数字看上去没什么大的变化,比如0、1、8;还有的数字变成了另一个数,比如6变成9,9变成6。给定一堆数字,请你判别每个数有没有可能是另一个数字翻倒形成的。二、流程设计对每个给定的数字,如果它......
  • day76(2023.5.22)
    1.Filter过滤器 运行结果: 2.在Filter中设置请求编码 运行结果: 3.FilterConfig对象的使用 运行结果: 4.FilterChain(过滤器链) 5.Filter执行顺序 6.基于注解式开发Filter 7.Filter的生命周期 8.Listener监听器 9.ServletCo......
  • 5.22总结
    packagecom.mf.jdbc.exmaple;importcom.alibaba.druid.pool.DruidDataSourceFactory;importcom.mf.jdbc.Brand;importorg.junit.Test;importjavax.sql.DataSource;importjava.io.FileInputStream;importjava.sql.Connection;importjava.sql.PreparedStatement;......
  • 在Windows Server 2022中使用Microsoft Deployment Toolkit(MDT)时,Bootstrap.ini文件是
    在WindowsServer2022中使用MicrosoftDeploymentToolkit(MDT)时,Bootstrap.ini文件是用于启动和定制Windows预安装环境(WinPE)的关键文件。以下是常见的Bootstrap.ini参数及其描述:[Settings]:指定设置组。Priority:指定Bootstrap.ini的优先级,以确定哪个Bootstrap.ini文件将被使用(如......
  • Windows server 2022 个人使用 优化批处理batch
    Windowsserver2022个人使用一些优化@echooffregadd"HKLM\SOFTWARE\Microsoft\ActiveSetup\InstalledComponents\{A509B1A7-37EF-4b3f-8CFC-4F3A74704073}"/v"IsInstalled"/tREG_DWORD/d00000000/fregadd"HKLM\SOFTWARE\Microsof......
  • 在Windows Server 2022中使用Microsoft Deployment Toolkit(MDT)时,可使用Rules(规则)文件
    在WindowsServer2022中使用MicrosoftDeploymentToolkit(MDT)时,可使用Rules(规则)文件来配置和自定义部署过程。以下是常见的Rules参数及其描述:UserDomain:指定要加入的域的名称。UserID和UserPassword:指定加入域所需的管理员帐户凭据。TimeZoneName:指定安装期间使用的时区。Jo......
  • Jquery操作打卡
    01jquery动态操作节点1.动态操作节点原js:-创建节点createElement('div')createTextNode('内容')-添加节点父节点.appendChild(子节点)父节点.insertBefore(......
  • 【DSP视频教程】DSP视频教程第12期:TI开源分享IQmath DSP源码,适用于所有Cortex-M内核,本
    视频教程汇总帖:https://www.armbbs.cn/forum.php?mod=viewthread&tid=110519 今年TI推出MSPM0系列产品配套的SDK软件包里面将此库开源了,之前的时候也移植过IQmatb,不过只有库版本,这次竟然开源了,确实是不可多得的好资源。这个是定点库,非常适合用于M0,  M0+,  M3和不带硬件F......
  • irq中断相关(2023.5.22)
    //irq29:nobodycared(trybootingwiththe"irqpoll"option) //aer_irqthreaded   aer_isrDIsablingIRQ#105 https://blog.csdn.net/Guet_Kite/article/details/106689126note_interrupt(){if(unlikely(desc->irqs_unhandled>99900)){ ......