support bazel complie this project and format code.

This commit is contained in:
zhangxing
2023-03-30 00:15:11 +08:00
committed by light-city
parent 1f86192576
commit 7529ae3a55
636 changed files with 10025 additions and 9387 deletions

View File

@@ -0,0 +1,23 @@
# please run `bazel run //practical_exercises/10_day_practice/day1:union`
# please run `bazel run //practical_exercises/10_day_practice/day1:print`
# please run `bazel run //practical_exercises/10_day_practice/day1:annotate`
# please run `bazel run //practical_exercises/10_day_practice/day1:runnian`
load("@rules_cc//cc:defs.bzl", "cc_binary")
cc_binary(
name = "union",
srcs = ["union.cpp"],
)
cc_binary(
name = "print",
srcs = ["print.cpp"],
)
cc_binary(
name = "annotate",
srcs = ["annotate.cpp"],
)
cc_binary(
name = "runnian",
srcs = ["runnian.cpp"],
)

View File

@@ -1,8 +1,5 @@
#include<iostream>
/* 注释.cpp */
#include <iostream>
//另一种注释方法
#if 0
@@ -12,5 +9,4 @@ asd
//打开注释
//条件编译指令
#if 1
asData
#endif

View File

@@ -0,0 +1,24 @@
/* 打印练习.cpp */
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
int i, j, k, f;
for (i = 1; i <= 4; i++) {
for (j = 1; j <= 30; j++)
cout << " ";
for (k = 1; k <= 8 - 2 * i; k++)
cout << " ";
for (f = 1; f <= 2 * i; f++)
cout << '*';
cout << endl;
}
for (i = 1; i <= 3; i++) {
for (j = 1; j <= 30; j++)
cout << " ";
for (f = 1; f <= 7 - 2 * i; f++)
cout << '*';
cout << endl;
}
return 0;
}

View File

@@ -0,0 +1,17 @@
/* 是否闰年.cpp */
#include <iostream>
using namespace std;
int main(int argc, char const *argv[]) {
int year;
bool isLeapYear;
cout << "Enter the year: ";
cin >> year;
isLeapYear = (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
if (isLeapYear) {
cout << year << " is a leap year" << endl;
} else {
cout << year << " is not a leap year" << endl;
}
return 0;
}

View File

@@ -0,0 +1,21 @@
/* 联合体学习.cpp */
#include <iostream>
using namespace std;
//相同的内存地址
union myun {
struct {
int x;
int y;
int z;
} u;
int k;
} a;
int main() {
a.u.x = 4;
a.u.y = 5;
a.u.z = 6;
a.k = 0; //覆盖掉第一个int空间值
printf("%d %d %d %d\n", a.u.x, a.u.y, a.u.z, a.k);
return 0;
}

View File

@@ -1,24 +0,0 @@
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int i,j,k,f;
for (i=1;i<=4;i++){
for (j=1;j<=30;j++)
cout<<" ";
for (k=1;k<=8-2*i;k++)
cout<<" ";
for (f=1;f<=2*i;f++)
cout<<'*';
cout<<endl;
}
for(i=1;i<=3;i++){
for (j=1;j<=30;j++)
cout<<" ";
for (f=1;f<=7-2*i;f++)
cout<<'*';
cout<<endl;
}
system("pause");
return 0;
}

View File

@@ -1,20 +0,0 @@
#include<iostream>
using namespace std;
int main(int argc, char const *argv[])
{
int year;
bool isLeapYear;
cout<<"Enter the year: ";
cin>>year;
isLeapYear = (((year%4==0)&&(year%100!=0))||(year%400==0));
if(isLeapYear)
{
cout<<year<<" is a leap year"<<endl;
}
else
{
cout<<year<<" is not a leap year"<<endl;
}
system("pause");
return 0;
}

View File

@@ -1,18 +0,0 @@
#include<iostream>
using namespace std;
//相同的内存地址
union myun
{
struct { int x; int y; int z; }u;
int k;
}a;
int main()
{
a.u.x =4;
a.u.y =5;
a.u.z =6;
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;
}