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

5月23日打卡

时间:2023-05-23 19:12:23浏览次数:37  
标签:const r1 r2 23 int void print 打卡

例5-7常成员函举例

代码部分:

 

#include<iostream>
using namespace std;
class R {
private:
    int r1, r2;
public:
    R(int r1, int r2):r1(r1),r2(r2){}
    void print();
    void print()const;
};
void R::print() {
    cout << r1 << ":" << r2 << endl;

}
void R::print()const {
    cout << r1 << ";" << r2 << endl;
}
int main()
{
    R a(5, 4);
    a.print();
    const R b(20, 52);
    b.print();
    return 0;
}

例5-8

常数据成员举例

代码部分:

#include<iostream>
using namespace std;
class A {
private:
    const int a;
    static const int b;
public:
    A(int i);
    void print();
};
const int A::b = 10;
A::A(int i):a(i){}
void A::print()
{
    cout << a << ";" << b << endl;
}
int main()
{
    A a1(100), a2(0);
    a1.print();
    a2.print();
    return 0;

}

 

标签:const,r1,r2,23,int,void,print,打卡
From: https://www.cnblogs.com/xuechenhao173/p/17425509.html

相关文章

  • 编程打卡:面向对象程序设计
    #include<iostream>#include<iomanip>usingnamespacestd;constfloatPI=3.14159;classShape{public:virtualfloatarea()=0;};classCircle:publicShape{private:floatradius;public:Circle(floatr):radius(r){}......
  • 每日打卡,pta题目
    给定一个长度不超过 104 的、仅由英文字母构成的字符串。请将字符重新调整顺序,按 PATestPATest.... 这样的顺序输出,并忽略其它字符。当然,六种字符的个数不一定是一样多的,若某种字符已经输出完,则余下的字符仍按PATest的顺序打印,直到所有字符都被输出。输入格式:输入在一......
  • 5.23打卡
    #include<bits/stdc++.h>usingnamespacestd;constfloatPI=3.141593;constfloatFENCE_PRICE=35;constfloatCONCRETE_PRICE=20;classCircle{public:Circle(floatr);floatcircumference();floatarea();private:......
  • 2023.5.21学习内容 多态、接口、泛型、反射
    下午1.了解CSS响应式布局和兼容性问题2.浏览IDEA使用手册并修改Maven仓库设置3.复习强化JavaSE的多态、接口、泛型、反射知识importorg.junit.Test;importtest.Hello;importjava.lang.reflect.Field;importjava.util.ArrayList;importjava.util.LinkedList;import......
  • c++打卡第三十五天
    一、最大公约数1、问题描述 2、设计思路本题中可以有三种算法,其中我们提供第三种辗转相除法的代码,第一种是从1开始,由于最大公约数可以是最小的那个数,所以我们循环条件到两个之中的小数,如果这个数满足可以整除两个整数,遍历到最大的那个数时,打印出来。第二种是从小数开始循环,当......
  • poj-2362
    //132K141MSC++withbeginSearchPos#include<cstdio>#include<cstring>#include<cstdlib>usingnamespacestd;intcmp(constvoid*a,constvoid*b)//降序{return*(longlong*)b-*(longlong*)a;}longlongfourEdgeLeng......
  • poj-2371
    //524K63MSC++#include<cstdio>#include<cstring>#include<cstdlib>intcmp(constvoid*a,constvoid*b){return*((int*)a)-*((int*)b);}usingnamespacestd;constintMAX=100001;intarray[MAX];intdataBaseSiz......
  • poj-1023
    //184K0MSC++#include<cstdio>#include<cstring>usingnamespacestd;charNP[65];//-1:n,1:pcharstr[80];chardigitUsed[80];charbinaryExpression[80];intcaseNum;intlength;longlongval;voidsolve(longlongval){l......
  • poj-2231
    //264K 47MS C++#include<cstdio>#include<cstring>#include<cstdlib>constintMAX=10005;longlongcowLocation[10005];intcmp(constvoid*a,constvoid*b){ return*((longlong*)a)-*((longlong*)b);}longlongcowNum;......
  • 2023春季学期个人总结
    回顾我在第一周定下的课程计划,我发现我完成程度不是很好——计划1——实现从eclipse到IDEA的转型完成情况——实现计划2——熟练掌握对数据库的CRUD等基本操作完成情况——实现了简单的增加删除修改和精准查询等基本功能,通过数据库原理这门课程也学习到了如何对表进行关联、多......