Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "Card.h"
- using namespace std;
- Card::Card(long long number, std::string lastName, int year, double balance) {
- this->number = number;
- this->lastName = lastName;
- this->year = year;
- this->balance = balance;
- }
- Card::Card() {
- int iBuf;
- string sBuf;
- cout << "Введите номер карты: ";
- iBuf = getchar();
- if (iBuf != 10) {
- cin >> sBuf;
- getchar(); // Сброс буфера
- this->number = stoll((char)iBuf + sBuf);
- } else throw 2;
- cout << "Введите фамилию: ";
- cin >> this->lastName;
- cout << "Введите срок действия карты: ";
- cin >> this->year;
- cout << "Введите баланс карты: ";
- cin >> this->balance;
- getchar(); // Сброс буфера
- }
- string Card::getCard() {
- string result;
- result += to_string(this->number) + ' ';
- result += this->lastName + ' ';
- result += to_string(this->year) + ' ';
- auto bal = to_string(this->balance);
- result += bal.substr(0, bal.find('.') + 3) + '\n';
- return result;
- }
- void Card::getMinBalance(vector<Card>* cards) {
- int iMin = 0;
- double bMin = (*cards)[iMin].balance;
- for (int i = 1; i < cards->size(); i++) {
- if ((*cards)[i].balance < bMin) {
- bMin = (*cards)[i].balance;
- iMin = i;
- }
- }
- cout << "Минимальный баланс у пользователя " << (*cards)[iMin].lastName << endl;
- }
- void Card::edit() {
- int iBuf;
- string sBuf;
- getchar(); // Сброс буфера
- cout << "Используйте Enter, чтобы не изменять данные\n";
- cout << "Введите номер карты: ";
- iBuf = getchar();
- if (iBuf != 10) {
- cin >> sBuf;
- getchar(); // Сброс буфера
- this->number = stoll((char)iBuf + sBuf);
- }
- cout << "Введите имя владельца карты: ";
- iBuf = getchar();
- if (iBuf != 10) {
- cin >> sBuf;
- getchar(); // Сброс буфера
- this->lastName = (char)iBuf + sBuf;
- }
- cout << "Введите срок действия карты: ";
- iBuf = getchar();
- if (iBuf != 10) {
- cin >> sBuf;
- getchar(); // Сброс буфера
- this->year = stoi((char)iBuf + sBuf);
- }
- cout << "Введите баланс карты: ";
- iBuf = getchar();
- if (iBuf != 10) {
- cin >> sBuf;
- getchar(); // Сброс буфера
- this->balance = (int)(stof((char)iBuf + sBuf) * 100) / 100.0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement