Warning: fopen(/www/wwwroot/www.wendadaohang.com/data/md5_content_title/4a/4aafc9b37f95ae5033e7218959fb8686.txt): failed to open stream: No space left on device in /www/wwwroot/www.wendadaohang.com/inc/function.php on line 2468

Warning: flock() expects parameter 1 to be resource, bool given in /www/wwwroot/www.wendadaohang.com/inc/function.php on line 2469

Warning: fclose() expects parameter 1 to be resource, bool given in /www/wwwroot/www.wendadaohang.com/inc/function.php on line 2475
1)定义一个结构体描述学生信息(学号,姓名,性别,年龄,住址); 2)设计一个函数,用于显示单个学生信息,函 - www问答网

1)定义一个结构体描述学生信息(学号,姓名,性别,年龄,住址); 2)设计一个函数,用于显示单个学生信息,函

1)定义一个结构体描述学生信息(学号,姓名,性别,年龄,住址);
2)设计一个函数,用于显示单个学生信息,函数的参数为前面定义的结构体类型;
3)设计一个主函数,在主函数中输入学生的信息,并调用前面定义的函数进行显示(学生人数不少于5人)。

结构体的定义:
struct student
{
int num;
char name[20];
char sex;
int age;
char address[100];
};
struct student1,student2;(定义了两个学生)
下面是显示某个学生的相关信息:(比如显示student1的信息)
显示学号:student1.num
显示姓名:student1.name
显示性别:student1.sex
显示年龄:student1.age
显示住址:student1.address
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-09-03
#include "stdafx.h"
#include <iostream>

struct stu {
int iNum;
char szName[20];
char szSex[1];
int iAge;
char adress[20];
};

void print(stu* lpStu) {
printf("学号: %d\r\n", lpStu->iNum);
printf("姓名: %s\r\n", lpStu->szName);
printf("性别: %s\r\n", lpStu->szSex);
printf("年龄: %d\r\n", lpStu->iAge);
printf("地址: %s\r\n", lpStu->adress);
}
int main(int argc, char* argv[])
{

stu *lpStu = new stu;
if (lpStu == NULL) return 0;

lpStu->iNum = 3;
strcpy(lpStu->adress, "杭州市西湖区");
lpStu->iAge = 25;
strcpy(lpStu->szSex, "男");
strcpy(lpStu->szName, "苏振华");

print(lpStu);
delete lpStu;
lpStu = NULL;

return 0;
}
第2个回答  2010-09-03
struct stu {
int iNum;
char szName[20];
char szSex[1];
int iAge;
char adress[50];
};

void print(stu* lpStu) {
printf("学号: %d\r\n", lpStu->iNum);
printf("姓名: %s\r\n", lpStu->szName);
printf("性别: %s\r\n", lpStu->szSex);
printf("年龄: %d\r\n", lpStu->iAge);
printf("地址: %s\r\n", lpStu->adress);
}本回答被提问者采纳
相似回答