标签:工资 employee print fun 上传 max uri 线图 ima
作业要求一:
作业截图:
C高级第二次作业(1)
6-7:
6-8:
6-9:
7-1:
C高级第二次作业(2):
7-1:
7-2:
C高级第二次作业(3):
6-1:
6-2:
作业要求二:
6-7 删除字符串中数字字符
1.实验代码:
#include <stdio.h>
void delnum(char *s);
int main ()
{ char item[80];
gets(item);
delnum(item);
printf("%s\n",item);
return 0;
}
void delnum(char *s)
{
int i=0,j=0;
while(s[i]!=‘\0‘){
if(s[i]>‘9‘||s[i]<‘0‘)
{
s[j]=s[i];
j++;
}
i++;
}
s[j]=‘\0‘;
}
2.设计思路:
3遇到问题:
6-8统计子串在母串出现的次数
1.实验代码:
#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)
{
int i=0,num=0;
do
{
if(*(str+i)==‘a‘&&*(str+i+1)==‘s‘&&*(str+i+2)==‘d‘)
{
num++;
}
i++;
}while(*(str+i)!=‘\0‘);
return num;
}
2.设计思路:
3遇到问题:
6-9字符串中除首尾字符外的其余字符按降序排列
1.实验代码:
#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)
{
int i,j;
char temp;
for(i=0;i<num;i++)
{
for(j=1;j<num-2;j++)
{
if(s[j]<s[j+1])
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}
}
}
2.设计思路:
3遇到问题:
7-1输出学生成绩
1.实验代码:
#include<stdio.h>
int main()
{
int n,i;
float max,min=100,sum=0,x,average;
scanf("%d",&n);
for(i=1;i<=n;i++)
{
scanf("%f ",&x);
if(x>max)
{
max=x;
}
if(x<min)
{
min=x;
}
sum=sum+x;
average=sum/n;
}
printf("average = %.2f\n",average);
printf("max = %.2f\n",max);
printf("min = %.2f",min);
return 0;
}
2.设计思路:
3遇到问题:
7-1计算职工工资
1.实验代码:
#include<stdio.h>
struct employees
{
char name[10];
float a,b,c;
};
int main()
{
int n,i=0;
scanf("%d",&n);
struct employees e[n];
for(i=0;i<n;i++)
{
scanf("%s %f %f %f",e[i].name,&e[i].a,&e[i].b,&e[i].c);
}
for(i=0;i<n;i++)
{
printf("%s %.2f\n",e[i].name,e[i].a+e[i].b-e[i].c);
}
}
2.设计思路:
3遇到问题:
7-2计算平均成绩
1.实验代码:
#include<stdio.h>
#include<stdlib.h>
struct student
{
char name[10];
char num[5];
int score;
};
int main()
{
int n,i=0;
float average,sum=0;
scanf("%d",&n);
struct student s[n];
for(i=0;i<n;i++){
scanf("%s %s %d",s[i].num,s[i].name,&s[i].score);
sum=sum+s[i].score;
}
average=(float)(sum/n*1.0);
printf("%.2f\n",average);
for(i=0;i<n;i++)
{
if((float)(s[i].score)<average)
{
printf("%s %s\n",s[i].name,s[i].num);
}
}
}
2.设计思路:
3遇到问题:
6-1 按等级统计学生成绩
1.实验代码:
#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 )
{
int i, count = 0;
for(i = 0;i < n;i ++,p++){
if((*p).score <=100 && (*p).score >= 85){
(*p).grade = ‘A‘;
}else if((*p).score <85 && (*p).score >= 70){
(*p).grade = ‘B‘;
}else if((*p).score && (*p).score >= 60){
(*p).grade = ‘C‘;
}else{
(*p).grade = ‘D‘;
count ++;
}
}
return count;
}
2.设计思路:
3遇到问题:
6-2结构体数组按总分排序
1.实验代码:
#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)
{
int i=0;
for(i=0;i<n;i++){
p[i].sum=p[i].score[0]+p[i].score[1]+p[i].score[2];
}
}
void sort(struct student *p,int n)
{
int j=0,i=0;
struct student a;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(p[j].sum<p[j+1].sum)
{
a=p[j];
p[j]=p[j+1];
p[j+1]=a;
}
}
}
}
2.设计思路:
3遇到问题:
作业要求三:
上传至git
地址: https://coding.net/u/AssassinCreed/p/Devil-May-Cry/git/tree/master/?public=true
截图:
作业要求四
表格:
折线图:
作业要求五:
评论同学:
标签:工资 employee print fun 上传 max uri 线图 ima
原文地址:https://www.cnblogs.com/nothingistrue/p/8747979.html