Advertisement
eXulW0lf

lab2_Card.cpp

Nov 21st, 2019
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.38 KB | None | 0 0
  1. #include <iostream>
  2. #include "Card.h"
  3.  
  4. using namespace std;
  5.  
  6. Card::Card(long long number, std::string lastName, int year, double balance) {
  7.     this->number = number;
  8.     this->lastName = lastName;
  9.     this->year = year;
  10.     this->balance = balance;
  11. }
  12.  
  13. Card::Card() {
  14.     int iBuf;
  15.     string sBuf;
  16.     cout << "Введите номер карты: ";
  17.     iBuf = getchar();
  18.     if (iBuf != 10) {
  19.         cin >> sBuf;
  20.         getchar(); // Сброс буфера
  21.         this->number = stoll((char)iBuf + sBuf);
  22.     } else throw 2;
  23.     cout << "Введите фамилию: ";
  24.     cin >> this->lastName;
  25.     cout << "Введите срок действия карты: ";
  26.     cin >> this->year;
  27.     cout << "Введите баланс карты: ";
  28.     cin >> this->balance;
  29.     getchar(); // Сброс буфера
  30. }
  31.  
  32. string Card::getCard() {
  33.     string result;
  34.     result += to_string(this->number) + ' ';
  35.     result += this->lastName + ' ';
  36.     result += to_string(this->year) + ' ';
  37.     auto bal = to_string(this->balance);
  38.     result += bal.substr(0, bal.find('.') + 3) + '\n';
  39.     return result;
  40. }
  41.  
  42. void Card::getMinBalance(vector<Card>* cards) {
  43.     int iMin = 0;
  44.     double bMin = (*cards)[iMin].balance;
  45.     for (int i = 1; i < cards->size(); i++) {
  46.         if ((*cards)[i].balance < bMin) {
  47.             bMin = (*cards)[i].balance;
  48.             iMin = i;
  49.         }
  50.     }
  51.     cout << "Минимальный баланс у пользователя " << (*cards)[iMin].lastName << endl;
  52. }
  53.  
  54. void Card::edit() {
  55.     int iBuf;
  56.     string sBuf;
  57.     getchar(); // Сброс буфера
  58.     cout << "Используйте Enter, чтобы не изменять данные\n";
  59.     cout << "Введите номер карты: ";
  60.     iBuf = getchar();
  61.     if (iBuf != 10) {
  62.         cin >> sBuf;
  63.         getchar(); // Сброс буфера
  64.         this->number = stoll((char)iBuf + sBuf);
  65.     }
  66.     cout << "Введите имя владельца карты: ";
  67.     iBuf = getchar();
  68.     if (iBuf != 10) {
  69.         cin >> sBuf;
  70.         getchar(); // Сброс буфера
  71.         this->lastName = (char)iBuf + sBuf;
  72.     }
  73.     cout << "Введите срок действия карты: ";
  74.     iBuf = getchar();
  75.     if (iBuf != 10) {
  76.         cin >> sBuf;
  77.         getchar(); // Сброс буфера
  78.         this->year = stoi((char)iBuf + sBuf);
  79.     }
  80.     cout << "Введите баланс карты: ";
  81.     iBuf = getchar();
  82.     if (iBuf != 10) {
  83.         cin >> sBuf;
  84.         getchar(); // Сброс буфера
  85.         this->balance = (int)(stof((char)iBuf + sBuf) * 100) / 100.0;
  86.     }
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement