NickAndNick

Класс student

Dec 17th, 2012
83
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <string>
  4.  
  5. using namespace std;
  6.  
  7. class student {
  8. public:
  9.     student()
  10.         : surname(L""), name(L""), patronymic(L""), group(L""), point(0)
  11.     { };
  12.     student(wstring _surname, wstring _name, wstring _patronymic, wstring _group, double _point)
  13.         : surname(_surname), name(_name), patronymic(_patronymic), group(_group), point(_point)
  14.     { };
  15.     student(const student &);
  16.     ~student();
  17.     void input();
  18.     void output();
  19.     student operator =(student &);
  20. private:
  21.     wstring surname;
  22.     wstring name;  
  23.     wstring patronymic;
  24.     wstring group;
  25.     double point;
  26. };
  27.  
  28. void ru();
  29.  
  30. int main() {
  31.     ru();
  32.     const size_t size = 2;
  33.     student students[size];
  34.     for (size_t n = 0; n < size; n++) students[n].input();
  35.     for (size_t n = 0; n < size; n++) students[n].output();
  36.     student ivanov = student(L"Иванов", L"Игорь", L"Филиппович", L"115а", 4.12);
  37.     ivanov.output();
  38.     cin.get(); cin.get();
  39.     return 0;
  40. }
  41.  
  42. student::~student() {
  43.     group = patronymic = surname = name = L"";
  44.     point = 0;
  45. }
  46. student::student(const student & _student) {
  47.     this->surname = _student.surname;
  48.     this->name = _student.name;
  49.     this->patronymic = _student.patronymic;
  50.     this->group = _student.group;
  51.     this->point = _student.point;
  52. }
  53. student student::operator =(student & _student) {
  54.     this->surname = _student.surname;
  55.     this->name = _student.name;
  56.     this->patronymic = _student.patronymic;
  57.     this->group = _student.group;
  58.     this->point = _student.point;
  59.     return *this;
  60. }
  61. void student::input() {
  62.     wcout << L"Введите фамилия:      "; getline(wcin, surname);
  63.     wcout << L"Введите имя:          "; getline(wcin, name);
  64.     wcout << L"Введите отчество:     "; getline(wcin, patronymic);
  65.     wcout << L"Введите группу:       "; getline(wcin, group); 
  66.     do {       
  67.         wcout << L"Введите средний балл: "; cin >> point;
  68.         if (cin.good() && point > 0) break;
  69.         else {
  70.             cin.clear();
  71.             cin.ignore(80,'\n');
  72.             wcout << L"\aВы ошиблись!\n";
  73.         }
  74.     } while (true);
  75.     fflush(stdin);
  76.     system("cls");
  77. }
  78. void student::output() {
  79.     wchar_t v = ' ';
  80.     streamsize accuracy = 2;
  81.     wcout << v << surname
  82.           << v << name
  83.           << v << patronymic
  84.           << v << group
  85.           << v << fixed << setprecision(accuracy) << point << endl;
  86. }
  87. void ru() {
  88.     wcout.imbue(locale("rus_rus.866"));
  89.     wcin.imbue(locale("rus_rus.866"));
  90. }
RAW Paste Data