Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace Kalkulator
- {
- class Ekran
- {
- public static void RysujMenu()
- {
- Console.WriteLine(" Menu\n---------------------------");
- Console.WriteLine(" Wybierz operacje:");
- Console.WriteLine(" 1. Wprowadź argumenty");
- Console.WriteLine(" 2. Zsumuj argumenty");
- Console.WriteLine(" 3. Odejmij argumenty");
- Console.WriteLine(" 4. Pomnóż argumenty");
- Console.WriteLine(" 5. Podziel argumenty");
- Console.WriteLine(" 6. KONIEC");
- Console.WriteLine("\n---------------------------");
- }
- public static void CzyscMenu()
- {
- Console.Clear();
- }
- public static char ZlapZnak()
- {
- return Console.ReadKey(true).KeyChar;
- }
- public static void PokazWynik(float w, string s)
- {
- Console.WriteLine("{0} {1,2:f}",s,w);
- }
- public static int PobierzDana(string s)
- {
- int liczba;
- do
- {
- Console.WriteLine(s);
- } while (!int.TryParse(Console.ReadLine(), out liczba));
- return liczba;
- }
- public static void WyswBlad(string s)
- {
- Console.WriteLine(s);
- }
- }
- class Rozwiaz
- {
- public static int Zsumuj(int a, int b)
- {
- return a + b;
- }
- public static int Odejmij(int a, int b)
- {
- return a - b;
- }
- public static int Iloczyn(int a, int b)
- {
- return a * b;
- }
- public static float Iloraz(int a, int b)
- {
- return a / (float)b;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- char c='a';
- int x1 = 0, x2 = 0, de = 0;
- do
- {
- Ekran.CzyscMenu();
- Ekran.RysujMenu();
- if (de==0) c = Ekran.ZlapZnak();
- switch (c)
- {
- case '1': //pobierz argumenty
- x1 = Ekran.PobierzDana("Podaj pierwszy argument");
- x2 = Ekran.PobierzDana("Podaj drugi argument");
- break;
- case '2': // dodawanie
- Ekran.PokazWynik(Rozwiaz.Zsumuj(x1,x2), "Suma argumentów wynosi: ");
- break;
- case '3': // odejmowanie
- Ekran.PokazWynik(Rozwiaz.Odejmij(x1, x2), "Różnica argumentów wynosi: ");
- break;
- case '4': // mnozenie
- Ekran.PokazWynik(Rozwiaz.Iloczyn(x1, x2), "Iloczyn argumentów wynosi: ");
- break;
- case '5': // dzielenie
- if (x2 == 0) { Ekran.WyswBlad("Nie można dzielic przez zero !"); break; }
- Ekran.PokazWynik(Rozwiaz.Iloraz(x1, x2), "Iloraz argumentów wynosi: ");
- break;
- case '6': // WYJŚCIE
- return;
- }
- de = 1;
- c = Ekran.ZlapZnak();
- } while (true);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment