Advertisement
LightProgrammer000

4 Operações [Orientado a Objeto]

Dec 8th, 2018
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.43 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace EX_29
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // Variáveis
  14.             double a, b;
  15.  
  16.             // Instanciações
  17.             Soma som = new Soma();
  18.             Multiplicacao mul = new Multiplicacao();
  19.             Subtracao sub = new Subtracao();
  20.             Divisao div = new Divisao();
  21.            
  22.             // Entrada de Dados
  23.             Console.Write("\n - Digite N1: ");
  24.             a = double.Parse(Console.ReadLine());
  25.  
  26.             Console.Write("\n - Digite N2: ");
  27.             b = double.Parse(Console.ReadLine());
  28.  
  29.             // Soma
  30.             som.N1 = a;
  31.             som.N2 = b;
  32.  
  33.             // Subtração
  34.             sub.A = a;
  35.             sub.B = b;
  36.  
  37.             // Multiplicação
  38.             mul.SetA(a);
  39.             mul.SetB(b);
  40.  
  41.             // Divisão
  42.             div.SetA(a);
  43.             div.SetB(b);
  44.  
  45.             Console.WriteLine("\n ---------- RELATÓRIO ---------- ");
  46.             Console.Write("\n - Soma: " + som.Somatorio(som.N1,som.N2) );
  47.             Console.Write("\n - Subtração: " + Subtracao.Sub(sub.A,sub.B) );
  48.             Console.Write("\n - Multiplicação: " + mul.Multiplica(mul.GetA(), mul.GetB()));
  49.             Console.Write("\n - Divisão: " + Divisao.Divide(div.GetA(),div.GetB()));
  50.             Console.WriteLine("\n");
  51.         }
  52.     }
  53. }
  54. /*
  55. //////////////////////// CLASSE DIVISÃO ////////////////////////
  56. using System;
  57. using System.Collections.Generic;
  58. using System.Linq;
  59. using System.Text;
  60. using System.Threading.Tasks;
  61.  
  62. namespace EX_29
  63. {
  64.     class Divisao
  65.     {
  66.         // Atributos
  67.         private double a;
  68.         private double b;
  69.  
  70.         // Metodologia
  71.         public static double Divide( double valor_1, double valor_2)
  72.         {
  73.             return (valor_1 / valor_2);
  74.         }
  75.  
  76.         // Encapsulamento
  77.         public double GetA()
  78.         {
  79.             return a;
  80.         }
  81.  
  82.         public void SetA(double a)
  83.         {
  84.             this.a = a;
  85.         }
  86.  
  87.         public double GetB()
  88.         {
  89.             return b;
  90.         }
  91.  
  92.         public void SetB(double b)
  93.         {
  94.             this.b = b;
  95.         }
  96.     }
  97. }
  98.  
  99. //////////////////////// CLASSE MULTIPLICAÇÃO ////////////////////////
  100.  
  101. using System;
  102. using System.Collections.Generic;
  103. using System.Linq;
  104. using System.Text;
  105. using System.Threading.Tasks;
  106.  
  107. namespace EX_29
  108. {
  109.     class Multiplicacao
  110.     {
  111.         // Atributos
  112.         private double a;
  113.         private double b;
  114.  
  115.         // Métodos
  116.         public double Multiplica(double valor_1, double valor_2 )
  117.         {
  118.             return (valor_1 * valor_2);
  119.         }
  120.  
  121.         // Encapsulamento
  122.         public double GetA()
  123.         {
  124.             return a;
  125.         }
  126.  
  127.         public void SetA(double a)
  128.         {
  129.             this.a = a;
  130.         }
  131.  
  132.         public double GetB()
  133.         {
  134.             return b;
  135.         }
  136.  
  137.         public void SetB(double b)
  138.         {
  139.             this.b = b;
  140.         }
  141.     }
  142. }
  143.  
  144. //////////////////////// CLASSE SOMA ////////////////////////
  145. using System;
  146. using System.Collections.Generic;
  147. using System.Linq;
  148. using System.Text;
  149. using System.Threading.Tasks;
  150.  
  151. namespace EX_29
  152. {
  153.     class Soma
  154.     {
  155.         // Atributos
  156.         double n1, n2;
  157.  
  158.         // Métodos
  159.         public double Somatorio(double n1,  double n2)
  160.         {
  161.             return (n1 + n2);
  162.         }
  163.  
  164.         // Encapsulamento
  165.         public double N1
  166.         {
  167.             get => n1;
  168.             set => n1 = value;
  169.         }
  170.  
  171.         public double N2
  172.         {
  173.             get => n2;
  174.             set => n2 = value;
  175.         }
  176.     }
  177. }
  178.  
  179. //////////////////////// CLASSE SUBTRAÇÃO ////////////////////////
  180. using System;
  181. using System.Collections.Generic;
  182. using System.Linq;
  183. using System.Text;
  184. using System.Threading.Tasks;
  185.  
  186. namespace EX_29
  187. {
  188.     public class Subtracao
  189.     {
  190.         private double a;
  191.         private double b;
  192.  
  193.         public static double Sub( double valor_1, double valor_2 )
  194.         {
  195.             return( valor_1 - valor_2);
  196.         }
  197.  
  198.         // Encapsulamento
  199.         public double A
  200.         {
  201.             get => a;
  202.             set => a = value;
  203.         }
  204.  
  205.         public double B
  206.         {
  207.             get => b;
  208.             set => b = value;
  209.         }
  210.     }
  211. }
  212. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement