[r]
g
name
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
#include <iostream> #include <string> #include <iomanip> #include <locale> #include <vector> #include <algorithm> #include <limits> constexpr auto SIZE = 10; std::string& toUpperWord(std::string& s); struct Student { std::string m_name; double m_GPA; Student(std::string& name, const double& GPA) : m_GPA(GPA) { m_name = toUpperWord(name); } }; std::ostream& operator << (std::ostream& os, const Student& s) { os << std::left << std::setw(45) << s.m_name; os << std::setw(10) << std::fixed << std::setprecision(2) << s.m_GPA << '\n'; return os; } int main() { std::vector<Student> students; int i{}; while (i < SIZE) { std::cout << "Enter student name \n"; std::string name; getline(std::cin, name); std::cout << "Enter student GPA \n"; double GPA; std::cin >> GPA; std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n'); Student tmp(name, GPA); students.push_back(std::move(tmp)); tmp.m_name = " "; tmp.m_GPA = 0.0; i++; } for (auto& elem : students) { std::cout << elem ; } } std::string& toUpperWord(std::string& s) { std::locale loc; size_t count = s.size(); if (count > 0) { s[0] = toupper(s[0], loc); } for(size_t i = 1; i < count; i++) { if (isspace(s[i - 1], loc)) s[i] = toupper(s[i], loc); else s[i] = tolower(s[i]); } return s; }