请教达人--c++中读取字符串并赋值给数组。怎么办?
发布网友
发布时间:2023-04-14 02:14
我来回答
共1个回答
热心网友
时间:2023-10-10 21:31
"我把你的代码给改了,建议你用struct活着class
#include
<string>
#include
<iostream>
#include
<string>
using
namespace
std;
int
main()
{
string
stuname[5];
int
Chinese[5];
int
English[5];
int
Math[5];
string
a;
int
sumC=0,
sumE=0,sumM=0;
cout
<<
"成绩管理系统(System)1.0\n";
cout
<<
"###############\n";
for
(int
n=0;
n<5;
n++)
{
cout<<
"请输入第"<<n+1<<"个学生姓名:"
<<
endl;
cin>>a;
//strcpy
(stuname,a);
stuname[n]=a;
cout
<<
"请输入语文成绩:"
<<
endl;
cin
>>
Chinese[n];
cout
<<
"请输入英语成绩:"
<<
endl;
cin
>>
English[n];
cout
<<
"请输入数学成绩:"
<<
endl;
cin
>>
Math[n];
sumC
=
sumC+Chinese[n];
sumE
=
sumE+English[n];
sumM
=
sumM+Math[n];
}
for
(int
i=0;i<5;i++)
cout<<stuname[i]<<
"\n语文:"<<
Chinese[i]<<"\n英语:"<<
English[i]
<<"\n数学:"<<Math[i]<<
endl;
cout
<<
"\n语文平均成绩是:"
<<
sumC/5;
cout
<<
"\n英语平均成绩是:"
<<
sumE/5;
cout
<<
"\n数学平均成绩是:"
<<
sumM/5
<<
endl;
return
0;
}"