完成对一个顺序表的建立,表中的每个元素是同学们的学号、姓名和三门课程的成绩,输入5个同学的信息,然后显示在屏幕上。(要求利用顺序表的基本操作)
输入格式:
首先收入学生人数5,然后依次输入5个学生的学号、姓名和三门课的成绩
输出格式:
输入5个学生的学号、姓名和三门课的成绩
输入样例:
5 01 张三 89 89 89 02 李四 90 90 90 03 王五 89 89 89 04 钱六 97 97 97 05 赵倩 90 90 90
输出样例:
1 张三 89.0 89.0 89.0
2 李四 90.0 90.0 90.0
3 王五 89.0 89.0 89.0
4 钱六 97.0 97.0 97.0
5 赵倩 90.0 90.0 90.0
cin 的用法:cin可以在c++中输入字符串,并且可以一次性输入多个字符串,用>>连接,不能读入不可见的特殊字符,如空格、换行符;
cout用法:cout是c++中输出的方法,可以用<<连接几个不同的字符串,也可以用<<连接字符串和空格。
cin>>a>>b>>c;//输入字符串,可能a b c是三个不同的字符串,用这样的语句就可以一次性输入,并以空格或者换行符作为一个字符串的结束符。
cout<<a<<b<<c;输出字符串,这样输出是把a b c三个字符串放在一起,连接起来输出。
c++中#include<iostream>是头文件,其中定义了标准的输入流和输出流,下边using name std几乎每个程序都会写上,c++标准程序库中所有的标识符都被放在一个名为std的namespace中。所以要写上这句话。
本题答案如下:
#include<iostream>
#define MAXSIZE 100;
using namespace std;
int main(){
typedef struct{
int no;
char name[100];
double score1,score2,score3;
}SqList;
SqList student[5];
int n;
cin>>n;
for(int i=0;i<n;i++){
scanf("%d",&student[i].no);
cin>>student[i].name;
scanf("%lf %lf %lf",&student[i].score1,&student[i].score2,&student[i].score3);
}
for(int i=0;i<n;i++){
printf("%d ",student[i].no);
cout<<student[i].name<<" ";
printf("%.1lf %.1lf %.1lf\n",student[i].score1,student[i].score2,student[i].score3);
}
}