作业要求一 (15分)
完成下列编程题目,每次上完课都会增加2-3道题目,并将编程过程记录在博客里,一次PTA作业任选一道题目给出设计思路、流程图、源代码和错误记录,其他题目可只给出设计思路、源代码和错误记录。另外将每次PTA作业的提交列表贴在博客里,每次5分,共15分。
1)C高级第二次PTA作业(1)
void delnum(char *s)
{
short int j=;
for(short int i=;*(s+i)!='\0';i++)
if(*(s+i)<=''&&*(s+i)>='')
continue;
else
{
*(s+j)=*(s+i);
j++;
}
*(s+j)='\0';
}
#include<stdio.h>
int fun(char *str,char *substr);
int main()
{
char str[]="asdasasdfgasdaszx67asdmklo",substr[]="asd";
int n;
n=fun(str,substr);
printf("n=%d\n",n);
return ;
}
int fun(char *str,char *substr)
{
short int j=,count=;
for(short int i=;*(str+i)!='\0';i++)
{
for(j=;*(substr+j)!='\0';j++)
if(*(str+i)==*(substr+j))
i++;
else
break;
if(*(substr+j)=='\0')
count++;
}
return count;
}
#include <stdio.h>
int fun(char *s,int num);
int main()
{
char s[];
gets(s);
fun(s,);
printf("%s",s);
return ;
}
int fun(char *s,int num)
{
for(short int i=;i<num-;i++)
{
short int k=i,swap;
for(short int j=i+;j<num-;j++)
if(*(s+k)<*(s+j))
k=j;
swap=*(s+k);
*(s+k)=*(s+i);
*(s+i)=swap;
}
}
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
void main()
{
short int N;
scanf("%d\n",&N);
short int *grade=(int *)malloc(N*sizeof(short int));
if(grade!=NULL)
{
float max=-,min=,sum=;
for(short int i=;i<N;i++)
{
scanf("%d",grade+i);
if(max<*(grade+i))
max=*(grade+i);
if(min>*(grade+i))
min=*(grade+i);
sum+=*(grade+i);
}
printf("average = %.2f\nmax = %.2f\nmin = %.2f\n",sum/N,max,min);
free(grade);
}
system("pause");
}
2)C高级第二次PTA作业(2)
#include <stdio.h>
#include <stdlib.h>
struct Staffinformation
{
char name[];float basepay;
float fluctuatingwages;float expenses;
float actualwages;
};
void main()
{
signed short int N;
scanf("%d",&N);
struct Staffinformation s;
for(signed short int i=;i<N;i++)
{
scanf("%s %f %f %f\n",s.name,&s.basepay,&s.fluctuatingwages,&s.expenses);
s.actualwages=s.basepay+s.fluctuatingwages-s.expenses;
printf("%s %.2f\n",s.name,s.actualwages);
}
system("pause");
}
#include <stdio.h>
#include <stdlib.h>
struct student
{
char number[];char name[];
int grade;
};
void main()
{
int N,sum=;
scanf("%d",&N);
struct student infor[N];
for(signed short int i=;i<N;i++)
{
scanf("%s %s %d\n",infor[i].number,infor[i].name,&infor[i].grade);
sum+=infor[i].grade;
}
printf("%.2f\n",sum/N*1.0f);
for(signed short int i=;i<N;i++)
if(sum/N*1.0f>infor[i].grade)
printf("%s %s\n",infor[i].name,infor[i].number);
system("pause");
}
3)C高级第二次PTA作业(3)
#include <stdio.h>
#define MAXN 10
struct student
{
int num;char name[];
int score;char grade;
};
int set_grade( struct student *p, int n );
int main()
{
struct student stu[MAXN], *ptr;
int n, i, count;
ptr = stu;
scanf("%d\n", &n);
for(i = ; i < n; i++)
scanf("%d%s%d", &stu[i].num, stu[i].name, &stu[i].score);
count = set_grade(ptr, n);
printf("The count for failed (<60): %d\n", count);
printf("The grades:\n");
for(i = ; i < n; i++)
printf("%d %s %c\n", stu[i].num, stu[i].name, stu[i].grade);
return ;
}
int set_grade(struct student *p,int n)
{
short int count=;
for(signed short int i=;i<n;i++)
if((p+i)->score>=&&(p+i)->score<=)
(p+i)->grade='A';
else if((p+i)->score>=&&(p+i)->score<=)
(p+i)->grade='B';
else if((p+i)->score>=&&(p+i)->score<=)
(p+i)->grade='C';
else
{
(p+i)->grade='D';
count++;
}
return count;
}
#include <stdio.h>
struct student
{
int num;
char name[];
float score[];
float sum;
};
void calc(struct student *p,int n);
void sort(struct student *p,int n);
int main()
{
struct student stu[];
int i,j;
float f;
for(i=;i<;i++)
{
scanf("%d%s",&stu[i].num,stu[i].name);
for(j=;j<;j++)
{
scanf("%f",&f);
stu[i].score[j]=f;
}
}
calc(stu,);
sort(stu,);
for(i=;i<;i++)
{
printf("%5d%15s",stu[i].num,stu[i].name);
printf(" %.1f %.1f %.1f %.1f\n",stu[i].score[],stu[i].score[],stu[i].score[], stu[i].sum);
}
return ;
}
void calc(struct student *p,int n)
{
for(signed short int i=;i<n;i++)
{
(p+i)->sum=;
for(signed int j=;j<;j++)
(p+i)->sum+=(p+i)->score[j];
}
}
void sort(struct student *p,int n)
{
for(signed short int i=;i<n-;i++)
{
short int k=i;
for(signed short int j=i+;j<n;j++)
if((p+k)->sum<(p+j)->sum)
k=j;
struct student swap=p[k];
p[k]=p[i];
p[i]=swap;
}
}
要求三、学习总结和进度(15分)
1、总结两周里所学的知识点有哪些学会了?(可记录每道作业题目所用的知识点)哪些还没有学会?(5分)
2、将PTA作业的源代码使用git提交到托管平台上,要求给出上传成功截图和你的git地址。请注意git地址应是类似“https://git.coding.net/Dawnfox/wf4_2.git”这样的字符串且是可被访问者直接点击进行访问的链接。(3分)
3、点评3个同学的本周作业(在作业中给出被点评同学博客的链接),并邀请3名同学点评你的作业,无点评作业(你的作业未被3人点评)/或者没有回复同学或老师的点评都倒扣该题分数。(4分)
建议采用汉堡包的方式点评其他同学的作业,只有赞扬没有给出实质性建议或者指正的不算点评,不给分。
4、请用表格和折线图呈现你本周(3/26 8:00~4/9 8:00)的代码行数和所用时间、博客字数和所用时间(3分)