主题:高手们·帮忙··跪谢··在线等
wybwyb67
[专家分:0] 发布于 2010-03-15 08:47:00
[code=c]
编写一个程序,采用结构体存储三个学生的信息:姓名,学号,性别,年龄,
这三个学生的信息分别为:li ming 1001 male 18
zhang xia 1002 female 17
wang gang 1003 male 19
通过scanf函数输入其中任何一个学生的学号,要求最后输出这个学生的相关信息。
例如:输入1002
则在屏幕上显示:
zhang xia 1002 female 17
[/code]
回复列表 (共5个回复)
沙发
sxm227 [专家分:10] 发布于 2010-03-15 09:45:00
深圳市华信群英科技有限公司与知名通信软件公司正式签订定向输送人才的合作协议
针对想进入IT软件行业的有志人士提供专业的企业内训
实训课程采用“2+3”分段教学模式,分为2个月理论强化和3个月项目实训两个阶段
实训前就签订就业安置协议,岗前实训后入职
不仅学费优惠而且是企业定向培训定向招聘,百分百保证就业
有意向请登录www.szctt.com,或加QQ:1179397962做详细咨询
板凳
quhailiang1984 [专家分:1720] 发布于 2010-03-15 13:36:00
[code=c]
#include <stdio.h>
#define N 3
struct student
{
char name[15];
int num;
char sex[10];
int age;
}stu[N];
main()
{
void print(struct student stu[]);
void input(struct student stu[]);
input(stu);
print(stu);
int number,i;
printf("Enter the number:");
scanf("%d",&number);
for(i=0;i<N;i++)
{
if(number==stu[i].num)
{
printf("This student's information is:\n");
printf("%10s%10d%10s%5d",stu[i].name,stu[i].num,stu[i].sex,stu[i].age);
}
}
printf("\n");
}
void input(struct student stu[])
{
int i,j;
for(i=0;i<N;i++)
{
printf("\nInput information of student %d:\n",i+1);
printf("name:");
scanf("%s",stu[i].name);
printf("NO.:");
scanf("%d",&stu[i].num);
printf("sex:");
scanf("%s",stu[i].sex);
printf("age.:");
scanf("%d",&stu[i].age);
printf("\n");
}
}
void print(struct student stu[])
{
int i,j;
printf("\n name NO. sex age\n");
for(i=0;i<N;i++)
{
printf("%10s%10d%10s%5d",stu[i].name,stu[i].num,stu[i].sex,stu[i].age);
printf("\n");
}
}
[/code]
3 楼
liudan319 [专家分:3780] 发布于 2010-03-15 14:03:00
…………………………
授人以鱼不如授人以渔啊
4 楼
qhftom [专家分:0] 发布于 2010-03-29 13:12:00
#include<iostream>
#include<iomanip>
#include<string>
using namespace std;
#define N 3
class Student
{public:
Student(string="unknown",int=0,string="unknown",int=0);
void display();
//private:
string name;
int number;
string sex;
int age;
};
void Student::display()
{
cout<<setiosflags(ios::right)<<setw(12)<<name<<" "<<number<<" "<<setw(8)<<sex<<" "<<age<<endl;
}
Student::Student(string n,int num,string s,int a):name(n),number(num),sex(s),age(a){}
Student search(int n,Student stu[])
{
for(int i=0;i<N;i++)
if(stu[i].number==n) return stu[i];
return ("unknown");
}
int main()
{
Student stu[N]={
Student("li ming",1001,"male",18),
Student("zhang xia",1002,"female",17),
Student("wang gang",1003,"male",19)
};
int n;
cout<<"Students' Imformation:"<<endl;
stu[0].display();stu[1].display();stu[2].display();
cout<<endl<<"Input student's number: ";
scanf("%d",&n);
Student R;
R=search(n,stu);
cout<<endl;
R.display();
cout<<endl;
return 0;
}
5 楼
mur1985 [专家分:0] 发布于 2010-04-18 10:13:00
#include <stdio.h>
#define AMOUNT 3
typedef struct
{
char name[10];
int stu_no;
char sex[10];
short age;
}student_detail;
int main()
{
student_detail student[AMOUNT] =
{ {"li ming", 1001, "male", 18},
{"zhang xia", 1002, "female", 17},
{"wang gang", 1003, "male", 19}
};
printf("Please input the student no:\n");
int stu_no;
scanf("%d", &stu_no);
for (int i = 0; i < 3; ++i)
{
if (student[i].stu_no == stu_no)
{
printf("%s %d %s %d\n", student[i].name, student[i].stu_no,
student[i].sex, student[i].age);
}
}
return 0;
}
我来回复