1、n第%d位学生的基本信息如下:nn, i);学号:(%d)t姓名:(%s)t性别:(%c)t年龄:(%d)nn, stu-num, stu-name, stu-sex, stu-age);三科成绩:(%.2f,%.2f,%.2f)nnscore0, stu-score1, stu-score2);总成绩:(%.2f) 平均成绩:(%.2f)n, sum, aeg);n+n);int main() int i, n;The number of students is: scanf(%d, &n); struct Stu *stu = (struct Stu *)calloc(n, sizeof(
2、struct Stu); for (i = 0; inum);姓名:%s, (stu + i)-name);性别: %csex);年龄:%f%f%fscore0, &score1, & putchar(n =n fun(stu + i, i + 1); return 0;题目二:计算每一个结构体的两个变量所表示的长度之和(单位:厘米)要求:(1)分别定义公制METRIC(成员包括:米、厘米)和英制BRITISH(成员包括:英尺、英寸)两个结构体;(2)为每一个结构定义两个变量。 struct METRIC float m; float cm; m1, m2; struct BRITISH fl
3、oat foot; float inches; b1, b2;Enter the info of m1(米,厘米):%f%fm1.m, &m1.cm);Enter the info of m2(米,厘米):m2.m, &m2.cm);nEnter the info of m2(英尺,英寸):b1.foot, &b1.inches);Enter the info of m2(英尺,英寸):b2.foot, &b2.inches);nSum of m1 and m2 is:%.2f(厘米)n, (m1.m + m2.m) * 100 + m1.cm + m2.cm);Sum of b1 and b
4、2 is:%.2f(厘米)nn, (b1.inches + b2.inches)*30.48 + (b1.foot + b2.foot)*2.54);题目三:编写一个函数用于计算某个日期是相应年份的第几天声明一个描述日期(年、月、日)的结构体类型。struct time int year; int month; int day; ;void fun(struct time time) int a,b,sum=0; for(a=1;atime.month;a+) if(a=4|a=6|a=9|a=11) sum+=30; else if(a=2) if(time.year%4=0)&(time.
5、year%100!=0|time.year%400=0) sum+=29; else sum+=28; else sum+=31; sum+=time.day;%d-%d-%d 是该年的第 %d 天!,time.year,time.month,time.day,sum); struct time time;Enter the date(Example:xxxx xx xx)(End with 0000 00 00): while(scanf(%d%d%d,&time.year,&time.month,&time.day)!=EOF) if(time.year=0&time.month=0&ti
6、me.day=0) break; fun(time);题目四:定义两个函数分别用于输入和输出N个STUDENT结构体变量的信息定义两个结构体STUDENT和BIRTHDAY。 其中结构体STUDENT包含成员有:姓名(char name20),学号(int number),出生日期(BIRTHDAY birth);结构体BIRTHDAY包含的成员有:年份(int year),月份(int month)和日期(int day)。struct BIRTHDAY int year; int month; int day;struct STUDENT int number; struct BIRTHD
7、AY birth;void input(struct STUDENT *stu,int n) int i; putchar( i n;第 %d 位学生的信息:n姓名:, stui.name);stui.number);生日:%d-%d-%dstui.birth.year, &stui.birth.month, &stui.birth.day); if (i != n - 1) putchar( else printf(输入完毕!void output(struct STUDENT *stu, int n)n第 %d 位学生的信息如下:(%s)t学号:(%d)t生日:(%d-%d-%d)n, s
8、tui.name, stui.number, stui.birth.year, stui.birth.month, stui.birth.day);输出完毕! int n;请输入待输入资料的学生的数目N: struct STUDENT *stu = (struct STUDENT *)calloc(n, sizeof(struct STUDENT); input(stu, n);=n output(stu, n);题目五:函数sortInfo()是按照总成绩从高到低的顺序进行排序的。如果两位学生的总成绩相等,则按照学号从小到大排序。1声明一个STUDENT结构体,成员有:姓名(char nam
9、e20),学号(int number),总成绩(float totalScore)2在main函数中定义一个长度为N的结构体数组arr,调用函数sortInfo(struct STUDENT *arr, int n)对N位学生的信息进行排序 float totalScore;第 %d 位学生的基本信息:%fstui.totalScore);void sortInfo(struct STUDENT *stu, int n) int i,j; struct STUDENT temp; for (j = 1; j n - i; j+) if (stui.totalScore (stui + j.nu
10、mber) temp = stui; stui = stui + j; stui + j = temp; (%d)t总成绩:, stui.name, stui.number, stui.totalScore);排序之前的初始状态: sortInfo(stu, n);排序之后的最终状态:题目六:编程模拟一个时钟(时间实时更新)1声明一个时间结构体TIME,包含成员:时(int hour),分(int minute),秒(int second)。定义函数updata()用于更新时间。2假设当前时刻为23:59:59,则调用函数updata将得到的下一刻时间为00:00:00假设当前时刻为23:45
11、:56,则调用函数updata将得到的下一刻时间为23:57Windows.hstruct TIME int hour; int minute; int second;updata(struct TIME *t) if (t-second = 59) t-second = 0; if (t-minute = 59) t-minute = 0; if (t-hour = 23) t-hour = 0; else (t-hour)+; else (t-minute)+; else (t-second)+; struct TIME t;请设定此刻时钟的时间(XX:XX:XX):%d:t.hour,&t.minute,&t.second); while (1)%02d:%02dr, t.hour, t.minute, t.second); updata(&t); Sleep(1000);四、讨论
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1