Skip to content

Commit

Permalink
Merge pull request Light-City#254 from tracyxiong1/master
Browse files Browse the repository at this point in the history
feat: 统一 cpp 文件编码格式为 utf-8
  • Loading branch information
Light-City authored Jan 3, 2023
2 parents ade7173 + 368eda3 commit a9716bd
Show file tree
Hide file tree
Showing 63 changed files with 327 additions and 327 deletions.
8 changes: 4 additions & 4 deletions practical_exercises/10_day_practice/day1/注释.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#include<iostream>


一种条件编译指令注释
一种条件编译指令注释


//另一种注释方法
//另一种注释方法
#if 0
asd
#endif

//打开注释
//条件编译指令
//打开注释
//条件编译指令
#if 1
asData
#endif
4 changes: 2 additions & 2 deletions practical_exercises/10_day_practice/day1/联合体学习.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include<iostream>
using namespace std;
//相同的内存地址
//相同的内存地址
union myun
{
struct { int x; int y; int z; }u;
Expand All @@ -11,7 +11,7 @@ int main()
a.u.x =4;
a.u.y =5;
a.u.z =6;
a.k = 0; //覆盖掉第一个int空间值
a.k = 0; //覆盖掉第一个int空间值
printf("%d %d %d %d\n",a.u.x,a.u.y,a.u.z,a.k);
system("pause");
return 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//用cin输入字符串数据时,如果字符串中含有空白就不能完整输入。因为遇到空白字符时,cin就认为字符串结束了。
//用cin输入字符串数据时,如果字符串中含有空白就不能完整输入。因为遇到空白字符时,cin就认为字符串结束了。
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
Expand All @@ -11,8 +11,8 @@ int main(int argc, char const *argv[])
return 0;
}
/*
若a的内容是:
若a的内容是:
this is a string!
就难以输入啦!
这样的数据应用输入流类的成员函数输入
就难以输入啦!
这样的数据应用输入流类的成员函数输入
*/
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include<iostream>
using namespace std;
//º¯ÊýÔ­ÐÍ
//函数原型
//put(char c)
//write(const char*c, int n)
int main(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ int main(){
double d=-1234.8976;
cout<<setw(30)<<left<<setfill('*')<<c<<"----L1"<<endl;
cout<<setw(30)<<right<<setfill('*')<<c<<"----L2"<<endl;
//showbase显示数值的基数前缀
//showbase显示数值的基数前缀
cout<<dec<<showbase<<showpoint<<setw(30)<<d<<"----L3"<<"\n";
//showpoint显示小数点
//showpoint显示小数点
cout<<setw(30)<<showpoint<<setprecision(10)<<d<<"----L4"<<"\n";
//setbase(8)设置八进制
//setbase(8)设置八进制
cout<<setw(30)<<setbase(16)<<100<<"----L5"<<"\n";
system("pause");
}
12 changes: 6 additions & 6 deletions practical_exercises/10_day_practice/day10/文件例题/12-6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ int main(int argc, char const *argv[])
{
fstream ioFile;
ioFile.open("./a.dat",ios::out);
ioFile<<"张三"<<" "<<76<<" "<<98<<" "<<67<<endl; //L3
ioFile<<"李四"<<" "<<89<<" "<<70<<" "<<60<<endl;
ioFile<<"王十"<<" "<<91<<" "<<88<<" "<<77<<endl;
ioFile<<"黄二"<<" "<<62<<" "<<81<<" "<<75<<endl;
ioFile<<"刘六"<<" "<<90<<" "<<78<<" "<<67<<endl;
ioFile<<"张三"<<" "<<76<<" "<<98<<" "<<67<<endl; //L3
ioFile<<"李四"<<" "<<89<<" "<<70<<" "<<60<<endl;
ioFile<<"王十"<<" "<<91<<" "<<88<<" "<<77<<endl;
ioFile<<"黄二"<<" "<<62<<" "<<81<<" "<<75<<endl;
ioFile<<"刘六"<<" "<<90<<" "<<78<<" "<<67<<endl;
ioFile.close();
ioFile.open("./a.dat",ios::in|ios::binary);
char name[10];
int chinese,math,computer;
cout<<"姓名\t"<<"英语\t"<<"数学\t"<<"计算机\t"<<"总分"<<endl;
cout<<"姓名\t"<<"英语\t"<<"数学\t"<<"计算机\t"<<"总分"<<endl;
ioFile>>name;
while(!ioFile.eof()) {
ioFile>>chinese>>math>>computer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//【例12-2】 用函数get和getline读取数据。
//【例12-2】 用函数get和getline读取数据。
#include <iostream>
using namespace std;
int main()
Expand All @@ -14,8 +14,8 @@ int main()
}

/*
用法:a = cin.get() ?或者 ?cin.get(a)
结束条件:输入字符足够后回车
说明:这个是单字符的输入,用途是输入一个字符,把它的ASCALL码存入到a中
处理方法:与cin不同,cin.get()在缓冲区遇到[enter],[space],[tab]不会作为舍弃,而是继续留在缓冲区中
用法:a = cin.get() ?或者 ?cin.get(a)
结束条件:输入字符足够后回车
说明:这个是单字符的输入,用途是输入一个字符,把它的ASCALL码存入到a中
处理方法:与cin不同,cin.get()在缓冲区遇到[enter],[space],[tab]不会作为舍弃,而是继续留在缓冲区中
*/
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#include<iostream>
using namespace std;
/*
(1)cin.getline(arrayname,size)与cin.get(arrayname,size)的区别
cin.get(arrayname,size)当遇到[enter]时会结束目前输入,他不会删除缓冲区中的[enter]
cin.getline(arrayname,size)当遇到[enter]时会结束当前输入,但是会删除缓冲区中的[enter]
(1)cin.getline(arrayname,size)与cin.get(arrayname,size)的区别
cin.get(arrayname,size)当遇到[enter]时会结束目前输入,他不会删除缓冲区中的[enter]
cin.getline(arrayname,size)当遇到[enter]时会结束当前输入,但是会删除缓冲区中的[enter]
*/
int main()
{
Expand All @@ -12,27 +12,27 @@ int main()
char b;
cin.get(a,10);
cin.get(b);
cout<<a<<endl<<int(b);//输入:12345[enter] 输出:12345 【换行】 10*/
cout<<a<<endl<<int(b);//输入:12345[enter] 输出:12345 【换行】 10*/
/*char c[10];
char d;
cin.getline(c,10);
cin.get(d);
cout<<c<<endl<<int(d);//输入:12345[enter]a[enter] 输出:12345【换行】97*/
//cin.getline(arrayname,size,s)与cin.gei(arrayname,size,s)的区别
cout<<c<<endl<<int(d);//输入:12345[enter]a[enter] 输出:12345【换行】97*/
//cin.getline(arrayname,size,s)与cin.gei(arrayname,size,s)的区别
/*
cin.getline(arrayname,size,s)当遇到s时会结束输入,并把s从缓冲区中删除
cin.get(arrayname,size,s)当遇到s时会结束输入,但不会删除缓冲区中的s
cin.getline(arrayname,size,s)当遇到s时会结束输入,并把s从缓冲区中删除
cin.get(arrayname,size,s)当遇到s时会结束输入,但不会删除缓冲区中的s
*/
/*
char e[10];
char f;
cin.get(e,10,',');
cin.get(f);
cout<<e<<endl<<f;//输入:12345,[enter] 输出:12345【换行】,说明:cin,get不会删除缓冲区的,*/
cout<<e<<endl<<f;//输入:12345,[enter] 输出:12345【换行】,说明:cin,get不会删除缓冲区的,*/
char e1[10];
char f1;
cin.getline(e1,10,',');
cin.get(f1);
cout<<e1<<endl<<f1;//输入:asd,wqe 输出:asd【换行】w
cout<<e1<<endl<<f1;//输入:asd,wqe 输出:asd【换行】w
system("pause");
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include<iostream>
#include<fstream>
//向量是一个能够存放任意类型的动态数组
//向量是一个能够存放任意类型的动态数组
#include<vector>
#include<cstring>
using namespace std;
Expand All @@ -25,20 +25,20 @@ class Person{
int main(int argc, char const *argv[])
{
vector<Person> v;
vector<Person>::iterator pos;//声明一个迭代器,来访问vector容器,作用:遍历或者指向vector容器的元素
vector<Person>::iterator pos;//声明一个迭代器,来访问vector容器,作用:遍历或者指向vector容器的元素
char ch;
ofstream out("d:/person.dat",ios::out|ios::app|ios::binary);
char Name[20],ID[18],Addr[20];
int Age;
cout<<"------输入个人档案------"<<endl<<endl;
cout<<"------输入个人档案------"<<endl<<endl;
do{
cout<<"姓名: ";
cout<<"姓名: ";
cin>>Name;
cout<<"身份证号: ";
cout<<"身份证号: ";
cin>>ID;
cout<<"年龄: ";
cout<<"年龄: ";
cin>>Age;
cout<<"地址: ";
cout<<"地址: ";
cin>>Addr;
Person per(Name,ID,Age,Addr);
out.write((char*)&per,sizeof(per));
Expand All @@ -53,7 +53,7 @@ int main(int argc, char const *argv[])
v.push_back(s);
in.read((char*)&s,sizeof(s));
}
cout<<"\n---------从文件中读出的数据--------"<<endl<<endl;//L15
cout<<"\n---------从文件中读出的数据--------"<<endl<<endl;//L15
pos=v.begin();
for(pos=v.begin();pos!=v.end();pos++)
(*pos).display();
Expand Down
2 changes: 1 addition & 1 deletion practical_exercises/10_day_practice/day2/掷骰子.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ int main(int argc, char const *argv[])
{
int flag;
unsigned seed;
cout<<"ÇëÊäÈëÎÞ·ûºÅÕûÊý£º"<<endl;
cout<<"请输入无符号整数:"<<endl;
cin>>seed;
srand(seed);
int sum = rolldice();
Expand Down
2 changes: 1 addition & 1 deletion practical_exercises/10_day_practice/day2/枚举类型.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(int argc, char const *argv[])
{
cout<<i<<endl;
cout<<wek+s<<endl;
cout<<"-------¹þ¹þ-------"<<endl;
cout<<"-------哈哈-------"<<endl;
}
system("pause");
return 0;
Expand Down
2 changes: 1 addition & 1 deletion practical_exercises/10_day_practice/day2/汉诺塔.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ void move(char A, char B);
void hanoi(int n,char A, char B, char C);
int main(int argc, char const *argv[])
{
cout<<"ÇëÊäÈëÅÌ×ÓÊýÁ¿£º";
cout<<"请输入盘子数量:";
int disks;
cin>>disks;
hanoi(disks,'A','B','C');
Expand Down
2 changes: 1 addition & 1 deletion practical_exercises/10_day_practice/day2/递归2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ using namespace std;
int f(int n, int k);
int main(int argc, char const *argv[])
{
cout<<"ÇëÊäÈënÓëk"<<endl;
cout<<"请输入n与k"<<endl;
int n,k;
cin>>n;
cin>>k;
Expand Down
14 changes: 7 additions & 7 deletions practical_exercises/10_day_practice/day2/静态变量.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include<iostream>
using namespace std;
int i=1; // i 为全局变量,具有静态生存期。
int i=1; // i 为全局变量,具有静态生存期。
int main(void)
{
static int a; // 静态局部变量,有全局寿命,局部可见。
int b=-10; // b, c为局部变量,具有动态生存期。
static int a; // 静态局部变量,有全局寿命,局部可见。
int b=-10; // b, c为局部变量,具有动态生存期。
int c=0;
void other(void);
cout<<"---MAIN---\n";
Expand All @@ -21,10 +21,10 @@ void other(void)
{
static int a=2;
static int b;
// a,b为静态局部变量,具有全局寿命,局部可见。
//只第一次进入函数时被初始化。
int c=10; // C为局部变量,具有动态生存期
//每次进入函数时都初始化。
// a,b为静态局部变量,具有全局寿命,局部可见。
//只第一次进入函数时被初始化。
int c=10; // C为局部变量,具有动态生存期
//每次进入函数时都初始化。
a=a+2; i=i+32; c=c+5;
cout<<"---OTHER---\n";
cout<<" i: "<<i<<" a: "<<a<<" b: "<<b<<" c: "<<c<<endl;
Expand Down
4 changes: 2 additions & 2 deletions practical_exercises/10_day_practice/day3/内联函数.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include<iostream>
using namespace std;
//şŻĘýÉůĂ÷
//函数声明
inline double CalArea(double radius);
int main(int argc, char const *argv[])
{
Expand All @@ -11,7 +11,7 @@ int main(int argc, char const *argv[])
system("pause");
return 0;
}
//źÓšŘźü×Öinline
//加关键字inline
inline double CalArea(double radius)
{
return 3.14*radius*radius;
Expand Down
24 changes: 12 additions & 12 deletions practical_exercises/10_day_practice/day3/函数综合练习题.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
一圆型游泳池如图所示,现在需在其周围建一圆型过道,并在其四周围上栅栏。栅栏价格为35元/米,过道造价为20元/平方米。
过道宽度为3米,游泳池半径由键盘输入。要求编程计算并输出过道和栅栏的造价。
一圆型游泳池如图所示,现在需在其周围建一圆型过道,并在其四周围上栅栏。栅栏价格为35元/米,过道造价为20元/平方米。
过道宽度为3米,游泳池半径由键盘输入。要求编程计算并输出过道和栅栏的造价。
图形描述:大圆嵌套小圆:
小圆在大圆中间,小圆为游泳池,大圆与小圆间隔为过道。
图形描述:大圆嵌套小圆:
小圆在大圆中间,小圆为游泳池,大圆与小圆间隔为过道。
*/
#include<iostream>
using namespace std;
Expand All @@ -25,13 +25,13 @@ Circle::Circle(float r)
radius=r;
}

// 计算圆的周长
// 计算圆的周长
float Circle::Circumference() const
{
return 2 * PI * radius;
}

// 计算圆的面积
// 计算圆的面积
float Circle::Area() const
{
return PI * radius * radius;
Expand All @@ -42,20 +42,20 @@ int main(int argc, char const *argv[])
float radius;
float FenceCost, ConcreteCost;

// 提示用户输入半径
// 提示用户输入半径
cout<<"Enter the radius of the pool: ";
cin>>radius;

// 声明 Circle 对象
// 声明 Circle 对象
Circle Pool(radius);
Circle PoolRim(radius + 3);
// 计算栅栏造价并输出
// 计算栅栏造价并输出
FenceCost = PoolRim.Circumference() * FencePrice;
cout << "Fencing Cost is ¥" << FenceCost << endl;
cout << "Fencing Cost is ¥" << FenceCost << endl;

// 计算过道造价并输出
// 计算过道造价并输出
ConcreteCost = (PoolRim.Area() - Pool.Area())*ConcretePrice;
cout << "Concrete Cost is ¥" << ConcreteCost << endl;
cout << "Concrete Cost is ¥" << ConcreteCost << endl;
system("pause");
return 0;
}
Loading

0 comments on commit a9716bd

Please sign in to comment.