SHARE
TWEET

main.cpp

a guest Nov 12th, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  
  3. 2.4
  4.  
  5. Write an application that:
  6.  
  7. * Asks for the name of a student
  8. * asks for the name of a course and the grade the student got
  9. * Does this until course name is "stop"
  10. * Asks for a new student until the name is "stop"
  11. * Then prints out the grades gathered for each student
  12.  
  13. */
  14.  
  15. #include <iostream>
  16. #include <iomanip>
  17.  
  18. #include "student.h"
  19.  
  20. int main()
  21. {
  22.     // Map of all students
  23.     Students students;
  24.  
  25.     // Name given by user input
  26.     std::string studentName;
  27.  
  28.     // Ask for students until stop is given
  29.     while(getStudent(studentName))
  30.     {
  31.         // Variables to keep name and grade input
  32.         std::string courseName;
  33.         std::string courseGrade;
  34.  
  35.         // Ask for grades until stop is given
  36.         while(getCourse(courseName, courseGrade))
  37.             students[studentName][courseName] = courseGrade;
  38.  
  39.         std::cout << std::endl;
  40.     }
  41.  
  42.     std::cout << std::endl;
  43.  
  44.     // Print out each student
  45.     for(const auto& student: students)
  46.     {
  47.         // Set '-' as fill character, used when padding.
  48.         // Can also be done inline.
  49.         std::cout << std::setfill('-');
  50.  
  51.         // Print pretty header for each student
  52.         std::cout << std::setw((int)student.first.size()) << "" << std::endl;
  53.         std::cout << student.first << std::endl;
  54.         std::cout << std::setw((int)student.first.size()) << "" << std::endl << std::endl;
  55.  
  56.         // Reset fill character to space
  57.         std::cout << std::setfill(' ');
  58.  
  59.         // Print out each grade
  60.         for(const auto& grade: student.second)
  61.             std::cout << student.first << " - " << grade.first << " - " << grade.second << std::endl;
  62.  
  63.         std::cout << std::endl;
  64.     }
  65.  
  66.     return 0;
  67. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top