G 结构体应用
时间: 1ms 内存:128M
描述:
程序填空--学生信息结构体
定义一个学生信息结构体,有姓名、英语成绩和数学成绩3个成员。
在主程序中定义学生结构体对象,先输入学生的姓名、英语成绩和数学成绩,
再输出该学生的姓名、英语成绩和数学成绩。请在下面的程序段基础上完成整个设计。
#include <iostream>
#include <string>
using namespace std;struct student //结构体声明
{
string name;
double english;
double math;
};//**********************begin********************int main()
{student s;
cin>> >> >> ; //输入学生信息
cout<<"name:"<< <<endl;cout<<"english:"<< <<endl;cout<<"math:"<< <<endl; //输出学生信息
return 0;
}//***********************end*************************
输入:
学生姓名、英语成绩、数学成绩
输出:
学生姓名、英语成绩、数学成绩
示例输入:
lisi 99 100
示例输出:
name:lisi
english:99
math:100
提示:
参考答案(内存最优[1092]):
#include<stdio.h>
int main()
{
char a[100];
int i,j;
scanf("%s",&a);
scanf("%d",&i);
scanf("%d",&j);
printf("name:%s\n",a);
printf("english:%d\n",i);
printf("math:%d\n",j);
}
参考答案(时间最优[0]):
#include <iostream>
#include <string>
using namespace std;
struct student //结构体声明
{
string name;
double english;
double math;
};
//**********************begin********************
int main()
{
student s;
cin>>s.name>>s.english>>s.math; //输入学生信息
cout<<"name:"<<s.name<<endl;
cout<<"english:"<<s.english<<endl;
cout<<"math:"<<s.math<<endl; //输出学生信息
return 0;
}
题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。