作业要求一 (15分)

完成下列编程题目,每次上完课都会增加2-3道题目,并将编程过程记录在博客里,一次PTA作业任选一道题目给出设计思路、流程图、源代码和错误记录,其他题目可只给出设计思路、源代码和错误记录。另外将每次PTA作业的提交列表贴在博客里,每次5分,共15分。

1)C高级第二次PTA作业(1)

void delnum(char *s)
{
  short int j=0;
  for(short int i=0;*(s+i)!='\0';i++)
  if(*(s+i)<='9'&&*(s+i)>='0')
  continue;
  else
  {
    *(s+j)=*(s+i);
    j++;
  }
  *(s+j)='\0';
}
#include<stdio.h>
int fun(char *str,char *substr);
int main()
{ 
  char str[81]="asdasasdfgasdaszx67asdmklo",substr[4]="asd";
  int n;
  n=fun(str,substr);
  printf("n=%d\n",n);
  return 0;
}
int fun(char *str,char *substr)
{
  short int j=0,count=0;
  for(short int i=0;*(str+i)!='\0';i++)
  {
    for(j=0;*(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[10];
  gets(s);
  fun(s,7);
  printf("%s",s);
  return 0;
}
int fun(char *s,int num)
{
  for(short int i=1;i<num-2;i++)
  {
    short int k=i,swap;
    for(short int j=i+1;j<num-1;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=-1,min=101,sum=0;
    for(short int i=0;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[10];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=0;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[6];char name[10];
  int grade;
};
void main()
{
  int N,sum=0;
  scanf("%d",&N);
  struct student infor[N];
  for(signed short int i=0;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=0;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[20];
    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 = 0; 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 = 0; i < n; i++)
  printf("%d %s %c\n", stu[i].num, stu[i].name, stu[i].grade);
  return 0;
}
int set_grade(struct student *p,int n)
{
  short int count=0;
  for(signed short int i=0;i<n;i++)
  if((p+i)->score>=85&&(p+i)->score<=100)
  (p+i)->grade='A';
  else if((p+i)->score>=70&&(p+i)->score<=84)
  (p+i)->grade='B';
  else if((p+i)->score>=60&&(p+i)->score<=69)
  (p+i)->grade='C';
  else
  {
    (p+i)->grade='D';
    count++;
  }
  return count;
}
#include <stdio.h>
struct student                  
{
  int num;
  char name[15];
  float score[3];
  float sum;
};
void calc(struct student *p,int n);  
void sort(struct student *p,int n);
int main()
{
  struct student stu[5];
  int i,j;
  float f;
  for(i=0;i<5;i++)
  {
      scanf("%d%s",&stu[i].num,stu[i].name);
      for(j=0;j<3;j++)
      { 
        scanf("%f",&f);
          stu[i].score[j]=f;
      }
  }
  calc(stu,5);
  sort(stu,5);
  for(i=0;i<5;i++)
  {
      printf("%5d%15s",stu[i].num,stu[i].name);
      printf("  %.1f  %.1f  %.1f  %.1f\n",stu[i].score[0],stu[i].score[1],stu[i].score[2], stu[i].sum);
  }
  return 0;
}
void calc(struct student *p,int n)
{
  for(signed short int i=0;i<n;i++)
  {
    (p+i)->sum=0;
    for(signed int j=0;j<3;j++)
    (p+i)->sum+=(p+i)->score[j];
  }
}
void sort(struct student *p,int n)
{
  for(signed short int i=0;i<n-1;i++)
  {
    short int k=i;
    for(signed short int j=i+1;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分)

posted on 2018-04-08 20:57  RLee  阅读(211)  评论(1编辑  收藏  举报