坐等!!!定义学生结构体类型,其成员包括学号、姓名、3门课的成绩 用一个函数input从键盘输入5个学生的 c语言中,定义一个学生结构体类型,包括学号、姓名、性别、年龄...

作者&投稿:泷霄 (若有异议请与网页底部的电邮联系)

代码如下:

#include <stdio.h>

#include  <string.h>

struct student {

long  sno;

char  name[10];

float  score[3];

};

void fun( struct student  *b)

{

b->sno = 10004;

strcpy(b->name, "LiJie");

}

main()

{struct student  t={10002,"ZhangQi", 93, 85, 87};

int  i;

printf("

The original data :
");

printf("
No: %ld  Name: %s
Scores:  ",t.sno, t.name);

for (i=0; i<3; i++)  printf("%6.2f ", t.score[i]);

printf("
");

fun(&t);

printf("
The data after modified :
");

printf("
No: %ld  Name: %s
Scores:  ",t.sno, t.name);

for (i=0; i<3; i++)  printf("%6.2f ", t.score[i]);

printf("
");

}


扩展资料

结构体内标的定义方式:

结构体,透明表区,DATA ELEMENT,DOMAIN

透明表是对一个物理表的逻辑描述,透明表里有许多字段,并且定义某些字段为 PRIMARY KEY,字段里又包含 DATA ELEMENT,用来描述语言属性和技术属性。DATA ELEMENT 中又包含 DOMAIN,它是定义数据类型和字段长度。

结构体一般是用来定义一个结构变量,有临时数据的储存,没有 PRIMARY KEY,结构体里包含 COMPONENT 而不是 FIELD

参考资料来源:

百度百科——结构体类型



#include "stdio.h"#include #define SIZE 5struct student{ char id[20]; char name[20]; int score[3];} stud[SIZE];float ave[SIZE];void input() /* 输入学生的信息 */{ int i; for(i=0;i<SIZE;i++) { printf("第%d个学生的信息:
",i+1); scanf("%s%s%d%d%d",stud[i].id,stud[i].name,&stud[i].score[0],&stud[i].score[1],&stud[i].score[2]); }}void average() /* 求每个学生的总平均分 */{ int i; for(i=0;i<SIZE;i++) { ave[i]=(stud[i].score[0]+stud[i].score[1]+stud[i].score[2])/3.0; }}void max() /* 找出总分最高学生的数据 */{int i,j;float ftemp; struct student temp; for(i=0;i<SIZE;i++) { for(j=0;j<SIZE-i-1;j++) { if(ave[j]<ave[j+1]) { temp=stud[j]; stud[j]=stud[j+1]; stud[j+1]=temp; ftemp=ave[j]; ave[j]=ave[j+1]; ave[j+1]=ftemp; } } } printf("
%s %s %d %d %d %3.1f
",stud[0].id,stud[0].name,stud[0].score[0],stud[0].score[1],stud[0].score[2],ave[0]);}void output() /* 输出学生的信息 */{ int i; printf("
"); for(i=0;i<SIZE;i++) printf("%s %s %d %d %d %3.1f
",stud[i].id,stud[i].name,stud[i].score[0],stud[i].score[1],stud[i].score[2],ave[i]);}void main(){ input(); average(); output(); max();}坐等!!!定义学生结构体类型,其成员包括学号、姓名、3门课的成绩 用一个函数input从键盘输入5个学生的

坐等!!!定义学生结构体类型,其成员包括学号、姓名、3门课的成绩 用一个函数input从键盘输入5个学生的~

代码如下:
#include
#include
struct student {
long sno;
char name[10];
float score[3];
};
void fun( struct student *b)
{
b->sno = 10004;
strcpy(b->name, "LiJie");
}
main()
{struct student t={10002,"ZhangQi", 93, 85, 87};
int i;
printf("

The original data :
");
printf("
No: %ld Name: %s
Scores: ",t.sno, t.name);
for (i=0; i<3; i++) printf("%6.2f ", t.score[i]);
printf("
");
fun(&t);
printf("
The data after modified :
");
printf("
No: %ld Name: %s
Scores: ",t.sno, t.name);
for (i=0; i<3; i++) printf("%6.2f ", t.score[i]);
printf("
");
}

扩展资料
结构体内标的定义方式:
结构体,透明表区,DATA ELEMENT,DOMAIN
透明表是对一个物理表的逻辑描述,透明表里有许多字段,并且定义某些字段为 PRIMARY KEY,字段里又包含 DATA ELEMENT,用来描述语言属性和技术属性。DATA ELEMENT 中又包含 DOMAIN,它是定义数据类型和字段长度。
结构体一般是用来定义一个结构变量,有临时数据的储存,没有 PRIMARY KEY,结构体里包含 COMPONENT 而不是 FIELD
参考资料来源:
百度百科——结构体类型

printf("please input the second student name:
");
scanf("%s", b.name);

printf("please input the second student sex:
");
scanf("%s", b.sex);

printf("please input the second student age:
");
scanf("%d", &b.age);

printf("please input the second student score:
");
scanf("%d", &b.score);

if(a.score >= b.score)
pStudent = &a;
else
pStudent = &b;

printf("the score higher student info:
");
printf("name = %s, sex = %s, age = %d, score = %d
", pStudent->name, pStudent->sex, pStudent->age, pStudent->score);

return 0;
}

定义一个结构体类型Student,成员包括学号,姓名和成绩,定义结构体数组s...
答:运行结果如下

用C++编写:定义一个学生结构体,包括学号,性别,数学英语4种信息,输入5...
答:include <iostream>#include <string>using namespace std;#define COUNT_STUDENTS 5enum Gender { male, female};struct Student { int score_english; int score_maths; enum Gender gender; int student_id;};std::istream& operator>>(std::istream& is, Gender& i){ int...

求C语言答案.定义一个学生结构体就一个学生,包含学生姓名,学号,性别,年...
答:typedef struct student //学生 { char sno[max]; // 学号 char sname[max]; //姓名 char sex[max]; //性别 char age[max]; //年龄 struct student* next;} student;void regist(){ char ch;student *s,*ptr; //s用来建新结点,ptr用来暂存头结点 do { s=(student*)mallo...

用c语言写:定义一个学生结构体(包含姓名,学号,语文,数学,外语,总分...
答:if(high->total < (s+i)->total) high = s+i; } return high;}main(){ struct student *s, student[5]; // 录入学生信息 for(s = student; s < student+5; s++) { printf("输入第%d个学生的信息:\n", s-student+1); printf("姓名:");...

...四个成员属性,然后定义长度为3的一个学生类型的数组,对
答:define NAMELENGTH 1024 typedef struct { int n_StudentId;int n_Sex;(0 男 1女)double d_Score;char p_StudentName[NAMELENGTH];}student;//结构如上 申请数组 student m_student[3];

c语言中关于结构体类型的定义
答:struct在C语言中是一个关键字,用于定义结构数据类型。问题中的两种定义的区别在于第一种是给student数据类型,重新定义了一个类型别名,而第二种则单纯的表示一种叫做student的数据结构类型。两者的主要区别在于后面直接定义变量时。如下代码,则可以直接在结构体后面定义一个zhang_san的结构体变量。struct ...

c语言里复数结构体的定义
答:1、首先我们打开Dev。2、我们给这个结构体取个名字叫student。3、然后我们添加变量。4、给结构体类型指针p申请堆空间。5、使用for循环给结构体赋值。6、在通过for循环打印输出,这样就完成就结构体的基本创建,结尾不要忘了使用free(p);释放我们申请的堆空间。

c语言 定义一个学生结构体,从键盘输入结构体信息,并把这些信息写入磁盘...
答:从文件中读出结构体:[cpp] view plaincopy include <stdio.h> include <stdlib.h> typedef struct { char c;int h;short n;long m;float f;double d1;char *s;double d2;}st;int main(void){ FILE *fp;st sa,sb;char *str="abcdefg";sa.c='K';sa.h=-3;sa.n=20;sa.m=...

定义一个学生结构体,包含学生姓名性别,年龄,身高并且提供输入姓名,然后...
答:这样吧..include "stdio.h"int main(){ struct { char name[10];//姓名 char sex[2];//性别 int age;//年龄 }student[10];//printf("%d",sizeof(wchar_t));int i;for(i=0;i<10;i++){ printf("请输入第%d个学生的信息:名字,学号,性别和年龄:\n",i+1);scanf("%s%d%s%d...

...的结构体类型DATE,它包含年,月,日三个成员,定义学生结构体类...
答:include <iostream>using namespace std;typedef struct __date{int nYear;int nMonth;int nDay;friend ostream& operator << (ostream &o, const __date& d){o << d.nYear << "年" << d.nMonth << "月" << d.nDay << "日";return o;}} DATE;#define MAX_LEN_NAME 20typedef ...