Console Calculator

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5. using ConsoleApplication6;  
  6. namespace ConsoleApplication6 {  
  7.     public class MojaKlasa {  
  8.         public  
  9.         const double const_PI = 3.14;  
  10.         public readonly double readOnly_PI;  
  11.         public MojaKlasa() {  
  12.             readOnly_PI = 3.14;  
  13.         }  
  14.     }  
  15.     public class MojKrug: MojaKlasa {  
  16.         public double PI = 3.14;  
  17.         public double op1;  
  18.         public double area() {  
  19.             return op1 * op1 * PI;  
  20.         }  
  21.     }  
  22.     class Kalkulator {  
  23.         public int op1;  
  24.         public int op2;  
  25.         public double add() {  
  26.             return op1 + op2;  
  27.         }  
  28.         public double sub() {  
  29.             return op1 - op2;  
  30.         }  
  31.         public double mul() {  
  32.             return op1 * op2;  
  33.         }  
  34.         public double div() {  
  35.             return op1 / op2;  
  36.         }  
  37.         public void Operands(int op1, int op2) {  
  38.             this.op1 = op1;  
  39.             this.op2 = op2;  
  40.         }  
  41.     }  
  42.     class Program {  
  43.         static void Main(string[] args) {  
  44.             MojKrug k = new MojKrug();  
  45.             Console.Write("Operand 1: ");  
  46.             k.op1 = Convert.ToInt32(Console.ReadLine());  
  47.             System.Console.WriteLine(k.area());  
  48.             Kalkulator c = new Kalkulator();  
  49.             Console.Write("Operand 1: ");  
  50.             c.op1 = Convert.ToInt32(Console.ReadLine());  
  51.             Console.Write("Operand 2: ");  
  52.             c.op2 = Convert.ToInt32(Console.ReadLine());  
  53.             Console.Write("Operator : ");  
  54.             string oper = Console.ReadLine();  
  55.             switch (oper) {  
  56.                 case "+":  
  57.                     Console.WriteLine(c.add());  
  58.                     break;  
  59.                 case "-":  
  60.                     Console.WriteLine(c.sub());  
  61.                     break;  
  62.                 case "*":  
  63.                     Console.WriteLine(c.mul());  
  64.                     break;  
  65.                 case "/":  
  66.                     Console.WriteLine(c.div());  
  67.                     break;  
  68.             }  
  69.         }  
  70.     }