Facebook
From Marcin, 4 Years ago, written in C#.
Embed
Download Paste or View Raw
Hits: 122
  1. //1. Stwórz klasę kalkulator, która pozwoli dodawać, odejmować, mnożyć i dzielić.
  2. //Jej dodatkową funkcjonalnością będzie metoda pokazLiczbyCalkowite,
  3. //która pozwoli pokazać liczby całkowite od 1 do wartości podanej jako argument metody.
  4. //Czyli pokazLiczbyCalkowite(10) pokaze liczby od 1 do 10
  5.  
  6. using System;
  7.  
  8. namespace dzien2
  9. {
  10.     class Kalkulator
  11.     {
  12.         public int _x;
  13.         public int _y;
  14.  
  15.         public int Dodawanie(int x, int y)
  16.         {
  17.             this._x = x;
  18.             this._y = y;
  19.             return x + y;
  20.         }
  21.         public int Odejmowanie(int x, int y)
  22.         {
  23.             this._x = x;
  24.             this._y = y;
  25.             return x - y;
  26.         }
  27.         public int Dzielenie(int x, int y)
  28.         {
  29.             this._x = x;
  30.             this._y = y;
  31.             return x / y;
  32.         }
  33.         public int Mnozenie(int x, int y)
  34.         {
  35.             this._x = x;
  36.             this._y = y;
  37.             return x * y;
  38.         }
  39.  
  40.         public string PokazLiczbyCalkowite(int x)
  41.         {
  42.             if (x > 0 && x%2 == 0)
  43.             {
  44.                 return "PARZYSTE";
  45.             }
  46.             else
  47.             {
  48.                 return "NIEPARZYSTE";
  49.             }
  50.         }
  51.  
  52.         public string PokazLiczbyCalkowite10()
  53.         {
  54.             return "1,2,3,4,5,6,7,8,9,10";
  55.         }
  56.  
  57.     }
  58.  
  59.     class Program
  60.     {
  61.         static void Main(string[] args)
  62.         {
  63.  
  64.             Kalkulator suma = new Kalkulator();
  65.             Console.WriteLine("Dodawanie liczb 2 i 2 = " + suma.Dodawanie(2,2));
  66.  
  67.             Kalkulator odjemnik = new Kalkulator();
  68.             Console.WriteLine("Odejmowanie liczb 2 i 2 = " + odjemnik.Odejmowanie(2, 2));
  69.            
  70.             Kalkulator dzielnik = new Kalkulator();
  71.             Console.WriteLine("Dzielenie liczb 2 i 2 = " + dzielnik.Dzielenie(2, 2));
  72.            
  73.             Kalkulator powielacz = new Kalkulator();
  74.             Console.WriteLine("Mnozenie 2 i 2 = " + powielacz.Mnozenie(2, 2));
  75.            
  76.             Kalkulator Calkowite = new Kalkulator();
  77.             Console.WriteLine("Podaj liczbe calkowite: ");
  78.             int v = Convert.ToInt32( Console.ReadLine());
  79.             Console.WriteLine(Calkowite.PokazLiczbyCalkowite(v));
  80.  
  81.             Kalkulator Kolejne = new Kalkulator();
  82.             Console.WriteLine(Kolejne.PokazLiczbyCalkowite10());
  83.  
  84.             Console.ReadKey();
  85.  
  86.         }
  87.     }
  88. }
  89.