#include <iostream>
#include <vector>
#include <string>
using namespace std;
// Define a structure to hold student information
struct Student {
string name;
int age;
string major;
};
// Function to input student information
void inputStudentInfo(Student &student) {
cout << "Enter student name: ";
getline(cin, student.name);
cout << "Enter student age: ";
cin >> student.age;
cin.ignore(); // Clear the newline character from the input buffer
cout << "Enter student major: ";
getline(cin, student.major);
}
// Function to display student information
void displayStudentInfo(const Student &student) {
cout << "Name: " << student.name << endl;
cout << "Age: " << student.age << endl;
cout << "Major: " << student.major << endl;
}
int main() {
int numberOfStudents;
cout << "Enter the number of students: ";
cin >> numberOfStudents;
cin.ignore(); // Clear the newline character from the input buffer
vector<Student> students(numberOfStudents);
// Input information for each student
for (int i = 0; i < numberOfStudents; ++i) {
cout << "Entering information for student " << (i + 1) << ":" << endl;
inputStudentInfo(students[i]);
}
// Display information for each student
cout << "\nStudent Information:\n";
for (const auto &student : students) {
displayStudentInfo(student);
cout << "------------------------" << endl;
}
return 0;
}