Advertisement
kolioi

54. Students Information C++

Jan 5th, 2019
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.82 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4.  
  5. using namespace std;
  6.  
  7. class Student
  8. {
  9. public:
  10.     Student(string fname, string lname, double gpa) :
  11.         first_name(fname), last_name(lname), GPA(gpa)
  12.     {}
  13.  
  14.     void print() const
  15.     {
  16.         cout << first_name << ' ' << last_name << ' ' << GPA << endl;
  17.     }
  18.  
  19. private:
  20.     string first_name;
  21.     string last_name;
  22.     double GPA;
  23. };
  24.  
  25. vector<Student> read_student_info(size_t n)
  26. {
  27.     vector<Student> students;
  28.     for (size_t i = 0; i < n; ++i)
  29.     {
  30.         string fname, lname;
  31.         double gpa;
  32.  
  33.         cin >> fname >> lname >> gpa;
  34.  
  35.         Student student(fname, lname, gpa);
  36.         students.push_back(student);
  37.     }
  38.  
  39.     return students;
  40. }
  41.  
  42. int main()
  43. {
  44.     size_t n;
  45.     cin >> n;
  46.  
  47.     vector<Student> students = read_student_info(n);
  48.  
  49.     for (auto& student : students)
  50.         student.print();
  51.  
  52.     return 0;
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement