day1: homework

This commit is contained in:
flykhan 2023-07-24 21:05:02 +08:00
parent 79430284ab
commit ca6f2f9fe6
3 changed files with 98 additions and 0 deletions

34
day1/homework/h3.cpp Normal file
View File

@ -0,0 +1,34 @@
#include <iostream>
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;
}

40
day1/homework/h4.cpp Normal file
View File

@ -0,0 +1,40 @@
#include <iostream>
#include <cstdlib>
#include <cstring>
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;
}

24
day1/homework/h5.cpp Normal file
View File

@ -0,0 +1,24 @@
#include <iostream>
#include <cmath>
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;
}