c++ - 有没有办法将 5 个学生的名字添加到一个向量中,每个学生都有 3 个考试分数?
问题描述
我又迷路了,我知道有一种方法可以使用 push_back 添加到向量中,但我不知道如何才能真正让它工作。我想要做的是将 5 个学生添加到一个向量(Egrades)中,并且每个学生收集 3 个单独的考试成绩并将它们附加到该学生的姓名上,以便我以后可以计算平均值。
在下面的代码中,我取出了案例中的行,只放了学生 1 来缩短长度。
我哪里错了?我是不是忘记放东西了?
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int main(void)
{
// Delcarations
int score1;
int score2;
int score3;
int scores[5];
vector <int> Egrades;
string student1;
string student2;
string student3;
string student4;
string student5;
// array with menu options
string menu[15];
menu[0] = " **************";
menu[1] = " *** MAIN MENU ***";
menu[2] = " **************";
menu[3] = " Please Choose From The Following Options:";
menu[6] = " 1. Add Student:";
menu[8] = " 2. Compute Student Test Score Average:";
menu[10] = " 3. Search A Student Average Test Score:";
menu[12] = " 4. Compute The Average Of The Average Exams:";
menu[14] = " 5. Exit";
char selection;
cout << "\t\t\t Enter Your Selection: ", cin >> selection, cout << endl;
switch (selection)
{
case '1':
system("CLS");
do
{
{
cout << "Student Information Section:\n\n";
// Student 1 Info
cout << "Enter Student 1 Name:\n";
cin >> student1; cout << endl;
cout << "Enter Exam 1 Score: ";
cin >> score1; cout << endl;
cout << "Enter Exam 2 Score: ";
cin >> score2; cout << endl;
cout << "Enter Exam 3 Score: ";
cin >> score3; cout << "\n" << endl;
}
system("pause");
return main();
}
while (cin >> score1, score2, score3);
break;
case '2':
break;
case '3':
break;
case '4':
break;
case '5':
exit(-1);
break;
default: cout << "\n Invalid selection\n\n";
}
return 0;
}
解决方案
推荐阅读
- docker - ASP .NET Core 在 Heroku 上给出 System.Net.Sockets.SocketException 错误
- c++ - 我们应该在使用 std::bind 之前检查一个不为空的函数吗?
- php - 通过反射类调用 Eloquent 方法,找不到方法错误
- python - 获取 OSError: [WinError 193] %1 不是带有 anaconda 和 jupyter 的有效 Win32 应用程序
- django - 永远在本地主机上使用 django 应用程序
- c# - 无法在 Linux 下使用 .Net Core 等待 Task.Delay
- python - Py2app 应用程序无法使用 tensorflow
- javascript - 使用 HTMLElement.click() 方法时防止 JavaScript 冒泡 DOM
- javascript - Chrome 扩展通过 chrome.runtime.onMessage 传递当前选项卡 url
- java - Jackson 将 JSON 属性反序列化为不同的 Java 对象