pawelkl

kodzikkalkulatorek

Mar 9th, 2011
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace Kalkulator
  7. {
  8.     class Ekran
  9.     {
  10.         public static void RysujMenu()
  11.         {
  12.             Console.WriteLine("    Menu\n---------------------------");
  13.             Console.WriteLine(" Wybierz operacje:");
  14.             Console.WriteLine(" 1. Wprowadź argumenty");
  15.             Console.WriteLine(" 2. Zsumuj argumenty");
  16.             Console.WriteLine(" 3. Odejmij argumenty");
  17.             Console.WriteLine(" 4. Pomnóż argumenty");
  18.             Console.WriteLine(" 5. Podziel argumenty");
  19.             Console.WriteLine(" 6. KONIEC");
  20.             Console.WriteLine("\n---------------------------");
  21.         }
  22.         public static void CzyscMenu()
  23.         {
  24.             Console.Clear();
  25.         }
  26.         public static char ZlapZnak()
  27.         {
  28.             return Console.ReadKey(true).KeyChar;
  29.         }
  30.         public static void PokazWynik(float w, string s)
  31.         {
  32.             Console.WriteLine("{0} {1,2:f}",s,w);
  33.         }
  34.         public static int PobierzDana(string s)
  35.         {
  36.             int liczba;
  37.             do
  38.             {
  39.                 Console.WriteLine(s);
  40.             } while (!int.TryParse(Console.ReadLine(), out liczba));
  41.             return liczba;
  42.         }
  43.         public static void WyswBlad(string s)
  44.         {
  45.             Console.WriteLine(s);
  46.         }
  47.     }
  48.     class Rozwiaz
  49.     {
  50.         public static int Zsumuj(int a, int b)
  51.         {
  52.             return a + b;
  53.         }
  54.         public static int Odejmij(int a, int b)
  55.         {
  56.             return a - b;
  57.         }
  58.         public static int Iloczyn(int a, int b)
  59.         {
  60.             return a * b;
  61.         }
  62.         public static float Iloraz(int a, int b)
  63.         {
  64.             return a / (float)b;
  65.         }
  66.     }
  67.     class Program
  68.     {
  69.         static void Main(string[] args)
  70.         {        
  71.             char c='a';
  72.             int x1 = 0, x2 = 0, de = 0;
  73.             do
  74.             {
  75.                
  76.                 Ekran.CzyscMenu();
  77.                 Ekran.RysujMenu();
  78.                 if (de==0) c = Ekran.ZlapZnak();
  79.                 switch (c)
  80.                 {
  81.                     case '1': //pobierz argumenty
  82.                         x1 = Ekran.PobierzDana("Podaj pierwszy argument");
  83.                         x2 = Ekran.PobierzDana("Podaj drugi argument");
  84.                         break;
  85.                     case '2': // dodawanie
  86.                         Ekran.PokazWynik(Rozwiaz.Zsumuj(x1,x2), "Suma argumentów wynosi: ");
  87.                         break;
  88.                     case '3': // odejmowanie
  89.                         Ekran.PokazWynik(Rozwiaz.Odejmij(x1, x2), "Różnica argumentów wynosi: ");
  90.                         break;
  91.                     case '4': // mnozenie
  92.                         Ekran.PokazWynik(Rozwiaz.Iloczyn(x1, x2), "Iloczyn argumentów wynosi: ");
  93.                         break;
  94.                     case '5': // dzielenie
  95.                         if (x2 == 0) { Ekran.WyswBlad("Nie można dzielic przez zero !"); break; }
  96.                         Ekran.PokazWynik(Rozwiaz.Iloraz(x1, x2), "Iloraz argumentów wynosi: ");
  97.                         break;
  98.                     case '6': // WYJŚCIE
  99.                         return;
  100.                 }
  101.                 de = 1;
  102.                 c = Ekran.ZlapZnak();                
  103.             } while (true);
  104.         }
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment