【发布时间】:2015-05-24 02:10:59
【问题描述】:
我无法按照规范完成作业。以下是作业场景:
一所大学迫切需要一个自动化的考试评分系统。使用 C++,为大学编写一个评分系统,并为至少五名学生的考试评分。
要创建评分系统,请按照以下步骤操作:
先询问考试题数
然后询问每个问题的正确答案。请注意,多项选择测试和问题的答案从 A 到 D。
询问学生人数并通过询问他们的姓名来处理每个学生,然后遍历要求学生回答的问题。
为每个问题评分。
在最后一道题后计算学生分数并显示“学生‘插入学生姓名’得分为 10 分,满分 20 分或 50%。”
重复直到所有学生都被评分。
在所有学生都得分后,以与以前相同的方式插入打印所有学生成绩的班级列表。
这是我目前所拥有的:
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//declare variables
char choice;
string studentName;
vector<char> answers;
vector<string> names;
int getStudents();
int getQuestions();
//calls function to get number of questions
float questions = getQuestions();
//Get answers
for (int i = 0; i < questions; ++i) {
cout << "What is the answer for question " << i + 1 << endl;
cin >> choice;
answers.push_back(choice);
}
//Get number of students
int students = getStudents();
//Get student names
for (int i = 0; i < students; i++) {
cout << "Student " << i + 1 << ", what is your name?" << endl;
cin >> studentName;
names.push_back(studentName);
}
float score = 0;
char studentAnswer;
vector<char> userAnswer;
vector<float> finalScore;
//gets student answers
for (int i = 0; i < students; i++) {
for (int j = 0; j < questions; j++) {
cout << names[i] << ", what is your answer for question " << j + 1 << "?" << endl;
cin >> studentAnswer;
userAnswer.push_back(studentAnswer);
}
}
//calculates student scores
for (int i = 0; i < students; i++) {
for (int j = 0; j < questions; j++) {
if (userAnswer[j] == answers[j])
score = score + 1;
}
finalScore.push_back(score);
}
//outputs scores
for (int i = 0; i < students; i++) {
cout << names[i] << " scored " << finalScore[i] << " out of " << questions <<
" or " << (finalScore[i] / questions) * 100 << "%" << endl;
}
system("pause");
return 0;
}
//function to get number of questions
int getQuestions()
{
int questions;
cout << "How many questions are there?" << endl;
cin >> questions;
return questions;
}
//function to get number of students
int getStudents()
{
int students;
cout << "How many students are there?" << endl;
cin >> students;
return students;
}
最终分数返回的值不准确,我找不到错误发生的位置。
对于最后一步的排序,我被要求按照降序排列的分数和升序或字母顺序排列的名称进行排序。我能够彼此独立地对它们进行排序,但不知道如何组合它们并以这种方式排序。
【问题讨论】:
-
关于排序,无论如何你都应该展示你到目前为止所得到的,但最好单独提出一个问题。