Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- 2.4
- Write an application that:
- * Asks for the name of a student
- * asks for the name of a course and the grade the student got
- * Does this until course name is "stop"
- * Asks for a new student until the name is "stop"
- * Then prints out the grades gathered for each student
- */
- #include <iostream>
- #include <iomanip>
- #include "student.h"
- int main()
- {
- // Map of all students
- Students students;
- // Name given by user input
- std::string studentName;
- // Ask for students until stop is given
- while(getStudent(studentName))
- {
- // Variables to keep name and grade input
- std::string courseName;
- std::string courseGrade;
- // Ask for grades until stop is given
- while(getCourse(courseName, courseGrade))
- students[studentName][courseName] = courseGrade;
- std::cout << std::endl;
- }
- std::cout << std::endl;
- // Print out each student
- for(const auto& student: students)
- {
- // Set '-' as fill character, used when padding.
- // Can also be done inline.
- std::cout << std::setfill('-');
- // Print pretty header for each student
- std::cout << std::setw((int)student.first.size()) << "" << std::endl;
- std::cout << student.first << std::endl;
- std::cout << std::setw((int)student.first.size()) << "" << std::endl << std::endl;
- // Reset fill character to space
- std::cout << std::setfill(' ');
- // Print out each grade
- for(const auto& grade: student.second)
- std::cout << student.first << " - " << grade.first << " - " << grade.second << std::endl;
- std::cout << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement