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

5月24日打卡

时间:2023-05-24 20:01:36浏览次数:33  
标签:24 count const Point int return 打卡 include

例5-9常引用做形参

 

#include<iostream>
#include<cmath>
using namespace std;
class Point {
public:
    Point(int x=0,int y=0):x(x),y(y){}
    int getX() { return x; }
    int getY() { return y; }
    friend float dist(const Point& p1, const Point& p2);
private:
    int x, y;
};
float dist(const Point& p1, const 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()
{
    const Point myp1(1, 1), myp2(4, 5);
    cout << "The distance is:";
    cout << dist(myp1, myp2) << endl;
    return 0;
}

 例5-10具有静态数据、函数成员的Point类,多组织文件

class Point {
public:
    Point(int x = 0, int y = 0) :x(x), y(y) { count++;}
    Point(const Point& p);
    ~Point() { count--; }
    int getX()const { return x; }
    int getY()const { return y; }
    static void showCount();
private:
    int x, y;
    static int count;
};
#include"Point.h"
#include<iostream>
using namespace std;
int Point::count = 0;
Point::Point(const Point& p) :x(p.x), y(p.y)
{
    count++;

}
void Point::showCount() {
    cout << "Object count=" << count << endl;
}
#include"Point.h"
#include<iostream>
using namespace std;
int main()
{
    Point a(4, 5);
    cout << "Point A:" << a.getX() << "," << a.getX();
    Point::showCount();
    Point b(a);
    cout << "Point B:" << b.getX() << "," << b.getY();
    Point::showCount();

}

 

标签:24,count,const,Point,int,return,打卡,include
From: https://www.cnblogs.com/xuechenhao173/p/17429269.html

相关文章

  • 2023-05-24:为什么要使用Redis做缓存?
    2023-05-24:为什么要使用Redis做缓存?答案2023-05-24:缓存的好处买啤酒和喝啤酒的例子可以帮助我们理解缓存的好处。假设你在超市里买了一箱啤酒,如果你需要每次想喝啤酒就去超市购买,无疑会浪费很多时间和精力。而如果你将一部分啤酒放在家中的冰箱里,每次想喝啤酒时就从冰箱里取出......
  • 5.24
    python电子算盘fromtkinterimport* tk=Tk()tk.title("电子算盘")#窗口名称tank=Canvas(tk,width=1000,height=600,bg='ivory')#创建画板tank.pack()#显示画板tank.create_rectangle(30,30,520,190,width=3)#左上侧方框tank.create_rectangle(30,19......
  • 编程打卡:面向对象程序设计
    importjava.util.*;publicclassStaffManagementSystem{privatestaticList<Staff>staffList=newArrayList<>();publicstaticvoidmain(String[]args){Scannerscanner=newScanner(System.in);while(true){......
  • 5.24
    #include<iostream>#include<cmath>usingnamespacestd;classPoint{private:doublex;doubley;doublez;public:Point(doublea,doubleb,doublec):x(a),y(b),z(c){};frienddoubleoperator-(Point,Point);};template<class......
  • 刘铭诚:5.24今日黄金价格涨跌走势分析,原油EIA数据行情提前布局
    黄金行情走势分析——昨日黄金行情走势V型反转,白盘跌至1954一线,然后连续收阳K线反弹高点触及1980一线,上下波幅达26个点,但是整体走势还是处于4小时上下轨区间内运行,更大的空间需要等待区间破位才会选择方向。技术面上黄金价格昨日又一次试探日线布林带下轨附近也再次反......
  • 5.24打卡
    #include<bits/stdc++.h>usingnamespacestd;classPoint{public:Point(intxx=0,intyy=0){x=xx;y=yy;}Point(Point&p);intgetX(){returnx;......
  • 5.24
    #include<stdio.h>voidmain(){longinta,b,c;printf("Pleaseenteraoptionalfraction(a/b):");scanf("%ld%ld",&a,&b);printf("Itcanbedecomposedto:");while(1){if(b%a)c=b/a+1;else{c=b/a;a=1;}if(a==1){printf("......
  • 5.24打卡
     3.程序流程图 4.代码实现#include<bits/stdc++.h>usingnamespacestd;main(){intx,y,z,num=0;printf("MenWomenChildren\n");for(x=0;x<=10;x++){y=20-2*x;z=30-x-y;if(3*x+2*y+z==50)......
  • 每日打卡1057
    给定一串长度不超过 105 的字符串,本题要求你将其中所有英文字母的序号(字母a-z对应序号1-26,不分大小写)相加,得到整数N,然后再分析一下N的二进制表示中有多少0、多少1。例如给定字符串 PAT(Basic),其字母序号之和为:16+1+20+2+1+19+9+3=71,而71的二进制是1000111,即有3个......
  • 20230524_配置环境
    debhttp://mirrors.aliyun.com/ubuntu/bionicmainrestricteduniversemultiversedeb-srchttp://mirrors.aliyun.com/ubuntu/bionicmainrestricteduniversemultiversedebhttp://mirrors.aliyun.com/ubuntu/bionic-securitymainrestricteduniversemultivers......