feat: 统一 cpp 文件编码格式为 utf-8

This commit is contained in:
tracyxiong1
2023-01-02 20:39:00 +08:00
parent ade7173887
commit 368eda305f
63 changed files with 327 additions and 327 deletions

View File

@@ -13,12 +13,12 @@ class A
int main()
{ double d(9.5);
display(d);
A const a(3,4); //a是常对象不能被更新
A const a(3,4); //a是常对象不能被更新
system("pause");
return 0;
}
void display(const double& r)
//常引用做形参,在函数中不能更新 r所引用的对象。
//常引用做形参,在函数中不能更新 r所引用的对象。
{ cout<<r<<endl; }

View File

@@ -3,37 +3,37 @@ using namespace std;
class R
{ public:
R(int r1, int r2){R1=r1;R2=r2;}
//const区分成员重载函数
//const区分成员重载函数
void print();
void print() const;
private:
int R1,R2;
};
/*
常成员函数说明格式:类型说明符 函数名参数表const;
这里const是函数类型的一个组成部分因此在实现部分也要带const关键字。
const关键字可以被用于参与对重载函数的区分
通过常对象只能调用它的常成员函数
常成员函数说明格式:类型说明符 函数名参数表const;
这里const是函数类型的一个组成部分因此在实现部分也要带const关键字。
const关键字可以被用于参与对重载函数的区分
通过常对象只能调用它的常成员函数
*/
void R::print()
{
cout<<"普通调用"<<endl;
cout<<"普通调用"<<endl;
cout<<R1<<":"<<R2<<endl;
}
//实例化也需要带上
//实例化也需要带上
void R::print() const
{
cout<<"常对象调用"<<endl;
cout<<"常对象调用"<<endl;
cout<<R1<<";"<<R2<<endl;
}
int main()
{
R a(5,4);
a.print(); //调用void print()
//通过常对象只能调用它的常成员函数
a.print(); //调用void print()
//通过常对象只能调用它的常成员函数
const R b(20,52);
b.print(); //调用void print() const
b.print(); //调用void print() const
system("pause");
return 0;
}

View File

@@ -1,4 +1,4 @@
//使用友元函数计算两点间距离
//使用友元函数计算两点间距离
#include <iostream>
#include <cmath>
using namespace std;
@@ -13,9 +13,9 @@ class Point{
}
friend float Distance(Point &a,Point &b);
private:
int X,Y;//私有数据成员
int X,Y;//私有数据成员
};
//通过将一个模块声明为另一个模块的友元,一个模块能够引用到另一个模块中本是被隐藏的信息。
//通过将一个模块声明为另一个模块的友元,一个模块能够引用到另一个模块中本是被隐藏的信息。
float Distance(Point &a, Point &b){
double dx = a.X-b.X;
double dy = a.Y-b.Y;
@@ -25,7 +25,7 @@ float Distance(Point &a, Point &b){
int main()
{
Point p1(3.0,5.0),p2(4.0,6.0);
cout<<"两点距离为:"<<Distance(p1,p2)<<endl;
cout<<"两点距离为:"<<Distance(p1,p2)<<endl;
system("pause");
return 0;
}

View File

@@ -1,13 +1,13 @@
#include<iostream>
using namespace std;
/*
若一个类为另一个类的友元,则此类的所有成员都能访问对方类的私有成员。
声明语法将友元类名在另一个类中使用friend修饰说明。
若一个类为另一个类的友元,则此类的所有成员都能访问对方类的私有成员。
声明语法将友元类名在另一个类中使用friend修饰说明。
*/
/*
如果声明B类是A类的友元B类的成员函数就可以访问A类的私有和保护数据
但A类的成员函数却不能访问B类的私有、保护数据。
如果声明B类是A类的友元B类的成员函数就可以访问A类的私有和保护数据
但A类的成员函数却不能访问B类的私有、保护数据。
*/
class A{
friend class B;
@@ -45,5 +45,5 @@ int main(int argc, char const *argv[])
}
/*
如果声明B类是A类的友元B类的成员函数就可以访问A类的私有和保护数据但A类的成员函数却不能访问B类的私有、保护数据
如果声明B类是A类的友元B类的成员函数就可以访问A类的私有和保护数据但A类的成员函数却不能访问B类的私有、保护数据
*/

View File

@@ -15,7 +15,7 @@ Clock::Clock(Clock &c)
}
void Clock::SetTime(int NewH,int NewM,int NewS)
{
//加不加this指针都一样
//加不加this指针都一样
this->Hour=NewH;
this->Minute=NewM;
this->Second=NewS;
@@ -26,7 +26,7 @@ void Clock::ShowTime()
cout<<this->Minute<<endl;
cout<<this->Second<<endl;
}
//析构函数
//析构函数
Clock::~Clock()
{
@@ -37,7 +37,7 @@ int main(int argc, char const *argv[])
c.SetTime(10,20,30);
c.ShowTime();
//拷贝构造函数调用
//拷贝构造函数调用
Clock c1(c);
c1.ShowTime();
c1.SetTime(90,98,99);