我無法按照規范完成作業 . 這是分配方案:
大學迫切需要一個自動測試評分系統 . 使用C,為大學寫一個評分系統,并對至少五名學生的測試進行評分 . 要創建評分系統,請按照以下步驟操作:首先詢問測試中的問題數量然后詢問每個問題的正確答案 . 請注意,多項選擇測試和問題將從A到D得到答案 . 詢問學生人數并通過詢問他們的姓名來處理每個學生,然后循環詢問學生的答案 . 為每個問題打分 . 在最后一個問題計算出學生得分后,顯示“學生'插入學生姓名'得分為20分中的10分或50% . ”重復,直到所有學生都得分 . 在對所有學生進行評分后,以與以前相同的方式插入打印所有學生成績的 class 列表 .
這是我到目前為止:
#include "stdafx.h"
#include
#include
#include
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
//declare variables
char choice;
string studentName;
vector answers;
vector 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 userAnswer;
vector 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;
}
最終得分返回的值不準確,我找不到錯誤發生的位置 .
同樣,為了在最后一步中進行排序,我被要求按升序或字母順序按降序和名稱排序 . 我能夠相互獨立地排序這些,但不知道如何將它們組合起來并按照這種方式對它們進行排序 .