Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <set>
- #include <algorithm>
- using namespace std;
- struct Student {
- string faculty_number;
- string name;
- double average_grade;
- };
- void input_students(Student *, size_t);
- void output_students(Student *, size_t);
- void print(const string&);
- void output_sorted(Student*, size_t);
- void output_excellent_grade_students(Student *, size_t);
- int main() {
- // Declare test as pointer of Student structure
- size_t *number_of_students = new size_t;
- cout << "Enter number of students: ";
- cin >> *number_of_students;
- Student *students = new Student[*number_of_students];
- // Call input function
- input_students(students, *number_of_students);
- // Call output function
- output_students(students, *number_of_students);
- // Sort
- output_sorted(students, *number_of_students);
- output_excellent_grade_students(students, *number_of_students);
- // Free memory
- delete[] students, number_of_students;
- system("pause");
- return 0;
- }
- void input_students(Student *student, size_t number_of_students) {
- for(size_t i = 0; i < number_of_students; i++) {
- // Clear input stream and sync it
- cin.sync();
- cin.clear();
- cout << "Enter Student #" << i << " name: ";
- getline(cin, student[i].name);
- cout << "Enter Student #" << i << " faculty number: ";
- getline(cin, student[i].faculty_number);
- cout << "Enter Student #" << i << " average grade: ";
- cin >> student[i].average_grade;
- }
- }
- void output_students(Student *student, size_t number_of_students) {
- for(size_t i = 0; i < number_of_students; i++)
- cout << "\nStudent with faculty number " << student[i].faculty_number << " whose name is " << student[i].name << " has grade of " << student[i].average_grade << endl << endl;
- }
- void output_sorted(Student* student, size_t number_of_students) {
- set<string> sorted_string;
- for(size_t i = 0; i < number_of_students; i++) {
- sorted_string.insert(student[i].name);
- }
- for_each(sorted_string.begin(), sorted_string.end(), &print);
- }
- void print(const std::string& item)
- {
- cout << item << endl;
- }
- void output_excellent_grade_students(Student *student, size_t number_of_students) {
- for(size_t i = 0; i < number_of_students; i++)
- if(student[i].average_grade >= 5.50)
- cout << "\nStudent with faculty number " << student[i].faculty_number << " whose name is " << student[i].name << " has grade of " << student[i].average_grade << endl << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement