‘壹’ c语言程序设计
#include<stdio.h>
struct student /*定义一个学生类型结构体*/
{
long num;
char name[20];
float score1;
float score2;
float score3;
float total;
float aver;
};
main()
{
void input(struct student t[3]);/*定义input函数,输入学生信息*/
void average(struct student v[3]);/*定义average函数,求每个学生总成绩、平均成绩和所有学生的总平均成绩*/
void maximum(struct student r[3]);/*定义maximum函数,找出最高分的学生的数据*/
struct student s[3];
int i;
input(s);
printf("the information of student is:\n");
printf("num name score1 score2 score3 total aver\n");
for(i=0;i<3;i++)
printf("%ld %s %f %f %f %f %f\n",s[i].num,s[i].name,s[i].score1,s[i].score2,s[i].score3,s[i].total,s[i].aver);
average(s);
maximum(s);
printf("the information of student with the highest total score is:\n");
printf("%s %f\n",s[0].name,s[0].total);
}
void input(struct student t[3])
{
int i;
printf("please input student's information:\n");
for(i=0;i<3;i++)
{t[i].total=0;
t[i].aver=0;
scanf("%ld%s%f%f%f",&t[i].num,&t[i].name,&t[i].score1,&t[i].score2,&t[i].score3);
t[i].total=t[i].score1+t[i].score2+t[i].score3;
t[i].aver=t[i].total/3;
}
}
void average(struct student v[3])
{
int i;
float sum=0,average=0;
for(i=0;i<3;i++)
{v[i].total=v[i].score1+v[i].score2+v[i].score3;
v[i].aver=v[i].total/3;
sum+=v[i].aver;}
average=sum/3;
printf("the average score of all the students is :average=%f\n",average);
}
void maximum(struct student r[3])
{
int i;
float t;
for(i=0;i<3;i++)
if(r[i].total>r[0].total)
{t=r[0].total;
r[0].total=r[i].total;
r[i].total=t;
strcpy(r[0].name,r[i].name);
r[0].num=r[i].num;r[0].score1=r[i].score1;r[0].score2=r[i].score2;r[0].score3=r[i].score3;
r[0].aver=r[i].aver;
}/*将所有学生信息进行排序,总分高的放在第一组,输出时只需输出第一组学生信息*/
}
程序中限定了学生个数为3,要改成10,则需将3替换为10。运行结果如下:
please input student's information:
1061 lili 80 78 98
1062 liujun 85 80 92
1063 guowei 82 83 93
the information of student is:
num name score1 score2 score3 total aver
1061 lili 80.000000 78.000000 98.000000 256.000000 85.333336
1062 liujun 85.000000 80.000000 92.000000 257.000000 85.666664
1063 guowei 82.000000 83.000000 93.000000 258.000000 86.000000
the average score of all the students is :average=85.666664
the information of student with the highest total score is:
guowei 258.000000
第二题不会。
‘贰’ c语言如何入门
既然已经学过C语言,就算入门了。再学习应该算是再入门了,哈哈。
找一门谭浩强的书快速看一遍,然后,根据你的实际情况,用C语言写几个小一点的程序,然后写写几个稍微大一点的程序就可以了。
如果想要精通C语言,那就要看好多C语言的书,譬如C语言高级程序设计等等。
还有一个最直接的方法,看一遍书,做完题,然后再网络知道上,搜索所有与C有关的提问,然后自己总结,最后形成一个比较大的文档,到时你就是一个C语言专家了!!
网络编程方面的书就多了,你是做安全,还是做页面展示,做不同的东东,需要不同的学习书籍,如果做展示,可以按下述步骤学习:
1、html
2、css
3、javascript(类C语言)
4、php(jsp,asp,java,.net)
5、数据库(access,mysql,sqlserver,oracle)
6、一些常用工具(photoshop,flash,word)
等等。
‘叁’ C语言的类怎么定义
C++才有类,用class关键字定义。