Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <cmath>
- using namespace std;
- class Money {
- private:
- long int roubles;
- long int copeiki;
- public:
- Money(long int rub, long int cop) {
- roubles = rub;
- if (cop > 99) {
- roubles += cop / 100;
- copeiki = cop % 100;
- }
- else {
- copeiki = cop;
- }
- }
- Money(long int cop) {
- roubles = 0;
- if (cop > 99) {
- roubles += cop / 100;
- copeiki = cop % 100;
- }
- else {
- copeiki = cop;
- }
- }
- Money() {
- roubles = 0;
- copeiki = 0;
- }
- ~Money() {}
- void moneyAdd(long int rub, long int cop) {
- roubles += rub;
- if (copeiki + cop > 99) {
- roubles += (copeiki + cop) / 100;
- copeiki = (copeiki + cop) % 100;
- }
- else {
- copeiki += cop;
- }
- if (copeiki < 0) {
- copeiki += cop;
- }
- }
- void moneyTake(long int rub, long int cop) {
- roubles -= rub;
- copeiki -= cop;
- if (copeiki < -99) {
- roubles += copeiki / 100;
- copeiki = copeiki % 100;
- }
- if (copeiki < 0 || roubles < 0) {
- cout << "You owe us " << fabs(roubles) << " roubles and " << fabs(copeiki) << " copeek. ";
- }
- }
- void getMoney() {
- cout << "Your money: " << roubles << " roubles and " << copeiki << " copeek" << endl;
- if (copeiki < 0 || roubles < 0) {
- cout << "You owe us " << fabs(roubles) << " roubles and " << fabs(copeiki) << " copeek. ";
- }
- else {
- cout << "You owe us 0 roubles and 0 copeek. ";
- }
- }
- void display() {
- bool isWorking = true;
- while (isWorking) {
- system("cls");
- cout << "What would you like to do?" << endl;
- cout << "1. Display info about your money. " << endl;
- cout << "2. Add money. " << endl;
- cout << "3. Take money. " << endl;
- cout << "4. Exit. " << endl;
- cout << "______________________________" << endl;
- cout << "Your choice: ";
- int n = 0;
- long int rub, cop;
- cin >> n;
- switch (n) {
- case 1: {
- system("cls");
- getMoney();
- system("PAUSE");
- break;
- }
- case 2: {
- system("cls");
- cout << "How much money would you like to add?" << endl;
- cout << "Roubles: " << endl;
- cin >> rub;
- cout << "Copeiki: " << endl;
- cin >> cop;
- if (rub < 0)
- rub = fabs(rub);
- if (cop < 0)
- cop = fabs(cop);
- moneyAdd(rub, cop);
- system("PAUSE");
- break;
- }
- case 3: {
- system("cls");
- cout << "How much money would you like to take?" << endl;
- cout << "Roubles: " << endl;
- cin >> rub;
- cout << "Copeiki: " << endl;
- cin >> cop;
- if (rub < 0)
- rub = fabs(rub);
- if (cop < 0)
- cop = fabs(cop);
- moneyTake(rub, cop);
- system("PAUSE");
- break;
- }
- case 4: {
- system("cls");
- cout << "Goodbye! " << endl;
- isWorking = false;
- system("PAUSE");
- break;
- }
- }
- }
- }
- };
- int main() {
- Money mon;
- mon.display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement