So I have to allow the user to create a certain amount of structs with 5 different types of information, and then sort based on one of those types. For example, they would input all the data and then sort by grade or name. How would I go about creating an array of just the different names or grades across the different structs?
#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;
}