Advertisement
amarek

OOP LV1 - Analiza

Nov 11th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.46 KB | None | 0 0
  1. //1. Definirajte klasu koja predstavlja bankovni tekući račun s atributima za stanje,
  2. //za postavljanje i dohvaćanje atributa, metode za uplatu i isplatu
  3. //(voditi računa o limitu), metodu za pripis kamate te metodu za ispis stanja.
  4. //Povesti računa o enkapsulaciji.
  5.  
  6. #include <iostream>
  7.  
  8. using namespace std;
  9.  
  10. class BankAccount {
  11. private:
  12.     float mBalance;
  13.     float mInterest;
  14.     float mLimit;
  15. public:
  16.     float GetBalance() { return mBalance; }
  17.     float GetInterest() { return mInterest; }
  18.     float GetLimit() { return mLimit; }
  19.     void SendPayment(float);
  20.     void RequestPayment(float);
  21.     void InterestAssignment(float);
  22.     BankAccount();
  23.     BankAccount(float, float, float);
  24. };
  25.  
  26. void BankAccount::SendPayment(float payment) {
  27.     int i, count = 0, status = 0;
  28.  
  29.     for (i = 0; i < payment; i++) {
  30.         if (mBalance >= 0) {
  31.             mBalance += 1;
  32.         }
  33.         else if (mBalance < 0) {
  34.             mBalance += 1;
  35.             count++;
  36.             status = 1;
  37.         }
  38.     }
  39.  
  40.     if (status) {
  41.         mBalance -= count * (mInterest / 100);
  42.     }
  43. }
  44.  
  45. void BankAccount::RequestPayment(float payment) {
  46.     int i, count = 0, status = 0;
  47.     float balance = mBalance;
  48.  
  49.     for (i = 0; i < payment; i++) {
  50.         if (balance >= 0) {
  51.             balance -= 1;
  52.         }
  53.         else if (balance < 0) {
  54.             balance -= 1;
  55.             count++;
  56.             status = 1;
  57.         }
  58.     }
  59.  
  60.     if (status) {
  61.         balance -= count * (mInterest / 100);
  62.     }
  63.  
  64.     count = 0;
  65.     status = 0;
  66.  
  67.     if (balance > mLimit) {
  68.         for (i = 0; i < payment; i++) {
  69.             if (mBalance >= 0) {
  70.                 mBalance -= 1;
  71.             }
  72.             else if (mBalance < 0) {
  73.                 mBalance -= 1;
  74.                 count++;
  75.                 status = 1;
  76.             }
  77.         }
  78.  
  79.         if (status) {
  80.             mBalance -= count * (mInterest / 100);
  81.         }
  82.     }
  83.     else
  84.         cout << "Error!" << endl;
  85. }
  86.  
  87. void BankAccount::InterestAssignment(float interest) {
  88.     mInterest += interest;
  89. }
  90.  
  91. BankAccount::BankAccount() : mBalance(0), mInterest(0), mLimit(0)
  92. {
  93. }
  94.  
  95. BankAccount::BankAccount(float balance, float interest, float limit) : mBalance(balance), mInterest(interest), mLimit(limit)
  96. {
  97. }
  98.  
  99. int main() {
  100.     BankAccount N(500, 4, -1000);
  101.     int menu;
  102.     float payment;
  103.     float interest;
  104.  
  105.     cout << "Welcome to your Bank Account menu." << endl;
  106.     cout << "1 - Check balance, interest and limit." << endl;
  107.     cout << "2 - Send payment." << endl;
  108.     cout << "3 - Request payment." << endl;
  109.     cout << "4 - Change interest assignment." << endl;
  110.     cout << "0 - Exit." << endl;
  111.  
  112.     do {
  113.         cout << endl << "Please enter specific number: ";
  114.         cin >> menu;
  115.         switch (menu) {
  116.         case 0:
  117.             break;
  118.         case 1:
  119.             cout << "Balance: " << N.GetBalance() << "$" << endl;
  120.             cout << "Interest: " << N.GetInterest() << "%" << endl;
  121.             cout << "Limit: " << N.GetLimit() << "$" << endl;
  122.             break;
  123.         case 2:
  124.             do {
  125.                 cout << "Enter payment amount: ";
  126.                 cin >> payment;
  127.             } while (payment < 0);
  128.             N.SendPayment(payment);
  129.             cout << "New balance: " << N.GetBalance() << "$" << endl;
  130.             break;
  131.         case 3:
  132.             do {
  133.                 cout << "Enter payment amount: ";
  134.                 cin >> payment;
  135.             } while (payment < 0);
  136.             N.RequestPayment(payment);
  137.             cout << "New balance: " << N.GetBalance() << "$" << endl;
  138.             break;
  139.         case 4:
  140.             do {
  141.                 cout << "Enter interest assignment: ";
  142.                 cin >> interest;
  143.             } while (interest < 0);
  144.             N.InterestAssignment(interest);
  145.             cout << "New interest: " << N.GetInterest() << "%" << endl;
  146.             break;
  147.         default:
  148.             cout << "1 - Check balance, interest and limit." << endl;
  149.             cout << "2 - Send payment." << endl;
  150.             cout << "3 - Request payment." << endl;
  151.             cout << "4 - Change interest assignment." << endl;
  152.             cout << "0 - Exit." << endl;
  153.             break;
  154.         }
  155.     } while (menu != 0);
  156.  
  157.     return 0;
  158. }
  159.  
  160. //2. Definirajte klasu koja predstavlja pravokutnik, omogućuje pristup atributima
  161. //te nudi mogućnost računanja površine i opsega pravokutnika.Napisati
  162. //funkciju koja uspoređuje tri pravokutnika po veličini i ispisuje površinu
  163. //najvećeg.Povesti računa o enkapsulaciji.
  164.  
  165. #include <iostream>
  166.  
  167. using namespace std;
  168.  
  169. class Rectangle {
  170. private:
  171.     int mA, mB;
  172. public:
  173.     float CalculateArea();
  174.     float CalculateExtent();
  175.     Rectangle();
  176.     Rectangle(int, int);
  177. };
  178.  
  179. float Rectangle::CalculateArea() {
  180.     return (mA * mB);
  181. }
  182.  
  183. float Rectangle::CalculateExtent() {
  184.     return (2 * mA + 2 * mB);
  185. }
  186.  
  187. Rectangle::Rectangle() : mA(0), mB(0)
  188. {
  189. }
  190.  
  191. Rectangle::Rectangle(int a, int b) : mA(a), mB(b)
  192. {
  193. }
  194.  
  195. int main() {
  196.     Rectangle N1(4, 5);
  197.     Rectangle N2(3, 7);
  198.     Rectangle N3(9, 6);
  199.  
  200.     if (N1.CalculateExtent() > N2.CalculateExtent() && N1.CalculateExtent() > N3.CalculateExtent()) {
  201.         cout << N1.CalculateExtent() << endl;
  202.     }
  203.     else if (N2.CalculateExtent() > N3.CalculateExtent()) {
  204.         cout << N2.CalculateExtent() << endl;
  205.     }
  206.     else {
  207.         cout << N3.CalculateExtent() << endl;
  208.     }
  209.  
  210.     return 0;
  211. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement