Hyluss icon

Bank tworzenie klasy, funkcji w klasie, konstruktor domyslny

Hyluss | PRO | 07/02/16 06:05:40 PM UTC | 0 ⭐ | 447 👁️ | Never ⏰ | []
C |

2.37 KB

|

None

|

0 👍

/

0 👎

// Tworzenie klasy, obiektu, konstruktor parametryczny, funkcje w klasie
 
// bank.cpp : Defines the entry point for the console application.
//
 
#include "stdafx.h"
#include <conio.h>
 
 
class Bank {
float limit;
float kasa;
 
public:
Bank ();
 
void Wplac (float hajs);
float Wyplac (float hajs);
float Procent (float stopa);
void Zadluz (float lim);
float WyswietlL ();
float WyswietlK ();
};
 
float Bank::WyswietlL() {
return limit;
}
 
float Bank::WyswietlK() {
return kasa;
}
 
void Bank::Zadluz(float lim) {
    limit = lim;
}
 
 
float Bank::Procent (float stopa) {
    float zarobisz;
    zarobisz= stopa/100 * kasa/12;
    return zarobisz;
}
 
void Bank::Wplac (float hajs) {
    kasa += hajs;
}
 
float Bank::Wyplac (float hajs) {   
float cos;
float (zwracamkase);
 
cos = (kasa)-(hajs);
    if ((cos) < (limit))
        {
        (zwracamkase) = kasa - limit;
        kasa-= zwracamkase;
        }
        else
        {
            kasa -= hajs;
            zwracamkase = hajs;
        }
    return (zwracamkase);
}
 
Bank::Bank(): limit (0), kasa (0) {}
 
 
int _tmain(int argc, _TCHAR* argv[])
{
int wybor;
float hajs;
float stopa=1;
float lim;
 
Bank bank;
 
 
do {
printf ("\n\n1 - Wyswietl\n2 - Wplac\n3 - Wyplac\n4 - pokaz oprocentowanie miesieczne\n5 - zmien limit\n6 - koniec programu\n");
scanf ("%d",&wybor);
 
switch (wybor) {
    case 1:
        {
            printf ("Stan konta wynosi %.2f ,a limit ustawiony jest na %.2f\n",bank.WyswietlK(), bank.WyswietlL());
            break;
        }
    case 2:
        {
            do {
                printf ("ile chcesz wplacic?\n");
                scanf ("%f",&hajs);
            } while ((hajs)<0);
            
            bank.Wplac (hajs);  
            break;
        }
 
    case 3:
        {
            do {
                printf ("ile chcesz wyplacic?\n");
                scanf ("%f",&hajs);
            } while ((hajs)<0);
 
            printf ("Wyplaciles %.2f pieniedzy\n",bank.Wyplac (hajs));
            break;
        }
 
    case 4:
        {
            do {
            if (stopa<=0) printf ("Stopa procentowa powinna byc wieksza od 0\n");
            printf ("Podaj stope procentowa roczna\n");
            scanf ("%f",&stopa);
            } while (stopa<0);
            printf ("Twoje oprocentowanie miesieczne wynosi %.2f\n",bank.Procent(stopa));
            break;
        }
 
    case 5:
        {
            printf ("Na ile chcesz zmienic limit konta?\n");
            scanf ("%f",&lim);
            bank.Zadluz(lim);
            break;
        }
 
    case 6:
        {           
            return 0;
            break;
        }
    default:
        {
            printf ("nie ma takiej opcji\n");
            break;
        }
 
}
 
} while ((wybor)!=6);
 
    _getch();
    return 0;
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎