上传文件至 ''
This commit is contained in:
parent
0fb9f75436
commit
db5c6f78a7
|
@ -0,0 +1,19 @@
|
|||
实训题目002
|
||||
题目1:读取"births.csv"文件(births美国出生人口统计表),读取到适当数据结构中,并输出。(代码量30-50行)
|
||||
题目2:完成如下表格 (60-100行)
|
||||
gender F M ALL F-M
|
||||
decade
|
||||
1960 12349384 12334455 236.......... -200
|
||||
1970 12334555 13454545
|
||||
1980 ........ .........
|
||||
......
|
||||
ALL 10000000000 100000000000 20000000000 0
|
||||
注:表格内容非真实统计结果,你需要编写相应代码,统计计算相应数据。比如
|
||||
表格右上角12349384意思是1960到1970年这10年出生的女性(F:female)人数为:12349384
|
||||
ALL意思为总人数, F-M 是女性人数减去男性人数,最后一行ALL,统计所有女性、男性、总数、总男女差值。
|
||||
|
||||
题目3:(110-160行)
|
||||
计算平均每月出生人数
|
||||
计算平均每天出生人数
|
||||
求出每年出身人数,并排序,显示出生人数最多的一年,和出生人数最小的一年,求出排序后的中位数对应的年份。
|
||||
求1970年,出生人数最多的一天和最少的一天。
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,24 @@
|
|||
提交代码到课堂派作业区
|
||||
提交作业的重复率不得超过40%,超过40%的代码会自动打回
|
||||
作业要求:
|
||||
严格打击各种学术不端的行为:代谢、抄袭等现象!
|
||||
|
||||
重复率不得超过20%, 每超过一个百分点扣5%的总成绩
|
||||
比如:
|
||||
一名学生得分为80分,重复率为30%, 那么最终分数为( 100 -(30-20)*5)* 100% * 80 = 40分(不及格)
|
||||
一名学生得分为70分,重复率为25%, 那么最终分数为( 100 -(25-20)*5)* 100% * 70 = 53分(>=51及格)
|
||||
以上为系统查重,作业采用面批的形式,会根据你的代码问若干个问题
|
||||
问题包括:新增简单功能,补全代码,局部代码描述等
|
||||
|
||||
人工查重:
|
||||
在面批期间,无法回答老师根据你的代码提出的问题,或者回答完全错误,
|
||||
以至于根据这样的回答无法独立完成代码。若出现以上情况,得分为0分!
|
||||
|
||||
在面批期间若出现代码逻辑及其相似,或者核心代码及其相似,却无法清晰解释相似代码的逻辑意义时。
|
||||
判定抄袭,抄袭与被抄袭者均0分!(目前还在积极争取,这种抄袭是否给与补考机会!)
|
||||
|
||||
判定抄袭者,可以申辩,申辩有效时间为判定抄袭后2周以内(申辩必须在正式成绩公布出来之前完成!!!)
|
||||
申辩内容:给予一个类似的简单题目,当场写代码,通过给予(”抄袭和被抄袭者“)相应分数。申辩测试时间90分钟,地点机房。
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,243 @@
|
|||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
#include<stdlib.h>
|
||||
typedef struct peoples{
|
||||
int year;
|
||||
int month;
|
||||
int day;
|
||||
char gender[10];
|
||||
int births;
|
||||
} Peo;
|
||||
typedef struct people{
|
||||
int year;
|
||||
int F;
|
||||
int M;
|
||||
int ALL;
|
||||
int cha;
|
||||
} Peop;
|
||||
typedef struct years{
|
||||
int year;
|
||||
int births;
|
||||
} Year;
|
||||
void clean(int i,Peo *peo){
|
||||
if(peo[i].year%4!=0&&peo[i].year%100==0||peo[i].year%400!=0){
|
||||
if(peo[i].month==2&&peo[i].day==29){
|
||||
peo[i].births=0;} }
|
||||
if((peo[i].month==2&&peo[i].day==30)||(peo[i].month==2&&peo[i].day==31)){
|
||||
peo[i].births=0;}
|
||||
if(peo[i].month==4&&peo[i].day==31){
|
||||
peo[i].births=0;}
|
||||
if(peo[i].month==6&&peo[i].day==31){
|
||||
peo[i].births=0;}
|
||||
if(peo[i].month==9&&peo[i].day==31){
|
||||
peo[i].births=0;}
|
||||
if(peo[i].month==11&&peo[i].day==31){
|
||||
peo[i].births=0;}
|
||||
}
|
||||
void init(Peo *peo,char *b,int i){
|
||||
char s[5]=",";
|
||||
peo[i].year=atoi(strtok(b,s));
|
||||
peo[i].month=atoi(strtok(NULL, s));
|
||||
peo[i].day=atoi(strtok(NULL, s));
|
||||
strcpy(peo[i].gender,strtok(NULL,s));
|
||||
peo[i].births=atoi(strtok(NULL,s));
|
||||
}
|
||||
Peo *read(char *t){
|
||||
FILE *fp;
|
||||
fp=fopen(t,"r");
|
||||
char buff[500];
|
||||
int q=15547;
|
||||
Peo *peo;
|
||||
peo=(Peo*)malloc(sizeof(Peo)*(q));
|
||||
fgets(buff,500,fp);
|
||||
int i;
|
||||
for(i=0;i<15547;i++){
|
||||
fgets(buff,500,fp);
|
||||
init(peo,buff,i);
|
||||
}
|
||||
fclose(fp);
|
||||
return peo;
|
||||
}
|
||||
void display(Peo *peo){
|
||||
int i;
|
||||
printf("年份\t月份\t天份\t性别\t出生人数\n");
|
||||
for(i=0;i<15547;i++){
|
||||
printf("%d\t%d\t%d\t%s\t%d\n",peo[i].year,peo[i].month,peo[i].day,peo[i].gender,peo[i].births);
|
||||
}
|
||||
}
|
||||
void form(Peo *peo,Peop *peop,int a[]){
|
||||
int i,e,j,k;
|
||||
a[0]=0;
|
||||
printf("year\tF\t\tM\t\tALL\t\tF-M\n");
|
||||
peop=(Peop*)malloc(sizeof(Peop)*(5));
|
||||
peop[0].year=1960;
|
||||
for( i=0;i<15547;i++){
|
||||
if(peo[i].year==1969){
|
||||
a[1]=i+1;
|
||||
peop[1].year=peo[i+1].year;
|
||||
}
|
||||
if(peo[i].year==1979){
|
||||
a[2]=i+1;
|
||||
peop[2].year=peo[i+1].year;
|
||||
}
|
||||
if(peo[i].year==1989){
|
||||
a[3]=i+1;
|
||||
peop[3].year=peo[i+1].year;
|
||||
}
|
||||
if(peo[i].year==1999){
|
||||
a[4]=i+1;
|
||||
peop[4].year=peo[i+1].year;
|
||||
}
|
||||
if(peo[i].year==2008){
|
||||
a[5]=i+1;
|
||||
peop[5].year=peo[i+1].year;
|
||||
}
|
||||
}
|
||||
int sumC=0,sum=0,sumf=0,summ=0;
|
||||
for( i=0;i<5;i++){
|
||||
for( j=a[i];j<a[i+1];j++){
|
||||
clean(j,peo);
|
||||
sum=sum+peo[j].births;
|
||||
peop[i].ALL=sum;
|
||||
if(strcmp(peo[j].gender,"F")==0){
|
||||
sumf=sumf+peo[j].births;
|
||||
peop[i].F=sumf;
|
||||
}
|
||||
if(strcmp(peo[j].gender,"M")==0){
|
||||
summ=summ+peo[j].births;
|
||||
peop[i].M=summ;
|
||||
}
|
||||
sumC=sumf-summ;
|
||||
peop[i].cha=sumC;
|
||||
}
|
||||
}
|
||||
int all=0,all01=0,all02=0,allcha=0;
|
||||
for(int e=0;e<5;e++){
|
||||
all=all+peop[e].ALL;
|
||||
all01=all01+peop[e].F;
|
||||
all02=all02+peop[e].M;
|
||||
allcha=allcha+peop[e].cha;
|
||||
}
|
||||
for(k=0;k<5;k++){
|
||||
printf("%d\t%10d\t%10d\t%10d\t%10d\n",peop[k].year,peop[k].F,peop[k].M,peop[k].ALL,peop[k].cha);
|
||||
}
|
||||
printf("all\t%10d\t%10d\t%10d\t%10d\n",all01,all02,all,allcha);
|
||||
}
|
||||
void month(Peo *peo){
|
||||
double z,sum0;
|
||||
for(int h=0;h<15547;h++){
|
||||
clean(h,peo);
|
||||
sum0=sum0+peo[h].births;
|
||||
}
|
||||
z=sum0/480;
|
||||
printf("平均每月出生%0.2f人\n",z);
|
||||
}
|
||||
void day(Peo *peo,int d[]){
|
||||
int count=0,i,h;
|
||||
double sum0,z;
|
||||
for(i=0;i<40;i++){
|
||||
d[i]=i+1969;
|
||||
if(d[i]%4==0&&d[i]%100!=0||d[i]%400==0){
|
||||
count=count+1;
|
||||
}
|
||||
}
|
||||
for(h=0;h<15547;h++){
|
||||
clean(h,peo);
|
||||
sum0=sum0+peo[h].births;
|
||||
}
|
||||
z=sum0/(((2008-1969)*365)+count);
|
||||
printf("平均每天出生%0.2f人\n",z);
|
||||
}
|
||||
int cmp(const void *a,const void *b){
|
||||
return (*(Year*)a).births>(*(Year*)b).births?1:-1;
|
||||
}
|
||||
void sort(Peo *peo,int d[],Year *year,int c[]){
|
||||
int j,h,q,u,e,w;
|
||||
year=(Year*)malloc(sizeof(Year)*(40));
|
||||
for( j=0;j<40;j++){
|
||||
for( h=0;h<15547;h++){
|
||||
if(peo[h].year==d[j]){
|
||||
c[j]=h;
|
||||
}
|
||||
}
|
||||
}
|
||||
int sum=0,sum1=0;
|
||||
for(j=0;j<c[0];j++){
|
||||
clean(j,peo);
|
||||
sum=sum+peo[j].births;
|
||||
year[0].births=sum;
|
||||
year[0].year=d[0];
|
||||
}
|
||||
for(u=1;u<40;u++){
|
||||
sum1=0;
|
||||
for( e=c[u-1];e<c[u];e++){
|
||||
clean(e,peo);
|
||||
sum1=sum1+peo[e].births;
|
||||
year[u].births=sum1;
|
||||
year[u].year=d[u];
|
||||
}
|
||||
}
|
||||
qsort(year,40,sizeof(Year),cmp);
|
||||
// printf("年份\t出生人数\n");
|
||||
// for( w=0;w<40;w++){
|
||||
// printf("%d\t%10d\n",year[w].year,year[w].births);
|
||||
// }
|
||||
int p;
|
||||
p=((2008-1969+1)/2);
|
||||
printf("排序后出生人数最多的是%d年,人数为%d\n排序后出生人数最少的是%d年,人数为%d\n",year[39].year,year[39].births,year[0].year,year[0].births);
|
||||
printf("排序后的中位数对应年份是%d和%d\n",year[p].year,year[p+1].year);
|
||||
}
|
||||
typedef struct last{
|
||||
int month;
|
||||
int day;
|
||||
int births;
|
||||
} Last;
|
||||
void qilin(Peo *peo,int c[],Last *las){
|
||||
las=(Last*)malloc(sizeof(Last)*(800));
|
||||
int j,w,a,b;
|
||||
int t[800]={0};
|
||||
for(j=c[0]+1;j<c[1]+1;j=j+2){
|
||||
if(peo[j].day==99||peo[j+1].day==99){
|
||||
peo[j].births=0;
|
||||
peo[j+1].births=0;
|
||||
}
|
||||
a=c[0];
|
||||
b=c[0]-1;
|
||||
las[j-a].births=peo[j].births+peo[j+1].births;
|
||||
las[j-a].day=peo[j].day;
|
||||
las[j-a].month=peo[j].month;
|
||||
las[j-b].births=0;
|
||||
las[j-b].day=0;
|
||||
las[j-b].month=0;
|
||||
}
|
||||
int max=0,month01,day01,min=9999999,month02,day02;
|
||||
for(int u=0;u<766;u++){
|
||||
if(las[u].births>max){
|
||||
max=las[u].births;
|
||||
month01=las[u].month;
|
||||
day01=las[u].day;
|
||||
}
|
||||
if(las[u].births!=0&&las[u].births<min){
|
||||
min=las[u].births;
|
||||
month02=las[u].month;
|
||||
day02=las[u].day;
|
||||
}
|
||||
}
|
||||
printf("1970年出生人数最多的是%d月%d日,出生人数为%d\n1970年出生人数最少的是%d月%d日,出生人数为%d\n",month01,day01,max,month02,day02,min);
|
||||
}
|
||||
int main(){
|
||||
int a[10]={0};
|
||||
int d[100]={0};
|
||||
int c[100]={0};
|
||||
Peo *peo=read("births.csv");
|
||||
Peop *peop;
|
||||
Year *year;
|
||||
Last *las;
|
||||
display(peo);
|
||||
form(peo,peop,a);
|
||||
month(peo);
|
||||
day(peo,d);
|
||||
sort(peo,d,year,c);
|
||||
qilin(peo,c,las);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue