그래서 사용자가 5 가지 유형의 정보가있는 특정 양의 구조체를 만든 다음 해당 유형 중 하나를 기준으로 정렬 할 수 있도록해야합니다. 예를 들어, 모든 데이터를 입력 한 후 등급 또는 이름순으로 정렬합니다. 다른 구조체에 걸쳐 다른 이름이나 등급의 배열을 만드는 방법은 어떻게됩니까?여러 구조체를 만든 다음 요소별로 정렬
#include <iostream>
#include <string>
struct student
{
std::string studentName;
std::string studentIDNumber;
int currentExamGrade;
int priorExamGrade;
double GPA;
};
void createStudent()
{
int numStudents;
std::cout << "Enter number of students\n";
std::cin >> numStudents;
while (numStudents > 0)
{
student name;
std::cout << "Enter the student's name\n";
std::cin >> name.studentName;
std::cout << "Enter the student's ID number\n";
std::cin >> name.studentIDNumber;
std::cout << "Enter the student's current exam grade\n";
std::cin >> name.currentExamGrade;
std::cout << "Enter the student's prior exam grade\n";
std::cin >> name.priorExamGrade;
std::cout << "Enter the student's GPA\n";
std::cin >> name.GPA;
numStudents -= 1;
}
}
int main()
{
createStudent();
int choice;
std::cout << "How do you want to sort the list?\n (Enter 1 for name, 2 for ID number, 3 for current exam grade, 4 for prior exam grade, 5 for GPA\n";
std::cin >> choice;
return 0;
}
그래서, Captn, 배열을 정렬하는 것 :
토크 싼 쇼 나 코드입니다? 학생은 괜찮 았지만 읽은 후에는 데이터를 버리고 다른 데이터를 읽습니다. –
그건 내 질문의 일부입니다. – CptJohnMiller74
좋습니다. [std :: vector] (http://www.cplusplus.com/reference/vector/vector/)에 대해 읽을 시간. 예제를 살펴보십시오. –