From ca6f2f9fe6c1e1e9f0f6742761e82c9400007e09 Mon Sep 17 00:00:00 2001 From: flykhan Date: Mon, 24 Jul 2023 21:05:02 +0800 Subject: [PATCH] day1: homework --- day1/homework/h3.cpp | 34 ++++++++++++++++++++++++++++++++++ day1/homework/h4.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ day1/homework/h5.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 day1/homework/h3.cpp create mode 100644 day1/homework/h4.cpp create mode 100644 day1/homework/h5.cpp diff --git a/day1/homework/h3.cpp b/day1/homework/h3.cpp new file mode 100644 index 0000000..7be08f1 --- /dev/null +++ b/day1/homework/h3.cpp @@ -0,0 +1,34 @@ +#include + +using namespace std; + +namespace Circle +{ + float r; + float s(); +} + +float Circle::s() +{ + return 3.14 * r * r; +} + +namespace Range +{ + int w, h; + int s(); +} + +int Range::s() +{ + return w * h; +} + +int main() +{ + cout << "输入半径:"; + cin >> Circle::r; + float s1 = Circle::s(); + cout << "面积: " << s1; + return 0; +} \ No newline at end of file diff --git a/day1/homework/h4.cpp b/day1/homework/h4.cpp new file mode 100644 index 0000000..60c584d --- /dev/null +++ b/day1/homework/h4.cpp @@ -0,0 +1,40 @@ +#include +#include +#include + +using namespace std; + +typedef struct file_node_s +{ + char filename[32]; + int filesize; + + file_node_s *next; +} FileNode; + +int main() +{ + FileNode *head = NULL; + FileNode *fn1 = (FileNode *)malloc(sizeof(FileNode)); + strcpy(fn1->filename, "数学"); + fn1->filesize = 1000; + FileNode *fn2 = (FileNode *)malloc(sizeof(FileNode)); + strcpy(fn2->filename, "语文"); + fn2->filesize = 1200; + FileNode *fn3 = (FileNode *)malloc(sizeof(FileNode)); + strcpy(fn3->filename, "英语"); + fn3->filesize = 1150; + head = fn1; + fn1->next = fn3; + fn3->next = fn2; + fn2->next = NULL; + + FileNode *p = head; + while (p != NULL) + { + cout << "文件名: " << p->filename << ", 文件大小: " << p->filesize << endl; + p = p->next; + } + + return 0; +} diff --git a/day1/homework/h5.cpp b/day1/homework/h5.cpp new file mode 100644 index 0000000..bd3bf5e --- /dev/null +++ b/day1/homework/h5.cpp @@ -0,0 +1,24 @@ +#include +#include + +using namespace std; +const float PI = 3.14159; + +double Area(double a, double b) +{ + return PI * pow(a, 2) * b / 360; +} +double Area(double a) +{ + return PI * pow(a, 2); +} + +int main(int argc, char const *argv[]) +{ + double r, x; + cout << "请输入半径和角度: " << endl; + cin >> r >> x; + cout << "半径为 " << r << ", 角度为 " << x << " 的扇形面积为: " << Area(r, x) << endl; + cout << "半径为 " << r << ", 的圆的面积为: " << Area(r) << endl; + return 0; +} \ No newline at end of file