Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.66 KB | None | 0 0
  1. using System;
  2.  
  3. namespace RevisãoProva
  4. {
  5.     class Pessoa
  6.     {
  7.         public Pessoa[] z= new Pessoa[100];
  8.         public int aux;
  9.  
  10.         private string nome;
  11.         public string Nome
  12.         {
  13.             get{ return nome;}
  14.             set{ nome = value;}
  15.         }
  16.  
  17.         private string endereço;
  18.         public string Endereço
  19.         {
  20.             get{ return endereço;}
  21.             set{ endereço = value;}
  22.         }
  23.  
  24.         private string telefone;
  25.         public string Telefone
  26.         {
  27.             get{return telefone;}
  28.             set{ telefone = value;}
  29.         }
  30.  
  31.         public Pessoa(string nome, string endereço, string telefone)
  32.         {
  33.             this.nome=nome;
  34.             this.endereço=endereço;
  35.             this.telefone = telefone;
  36.  
  37.         }
  38.  
  39.         public virtual void mostrar()
  40.         {
  41.             for (int i = 0; i < aux; i++)
  42.             {
  43.                 Console.WriteLine (z [aux].nome);
  44.                 Console.WriteLine (z [aux].endereço);
  45.                 Console.WriteLine (z [aux].telefone);
  46.             }
  47.         }
  48.     }
  49.  
  50.     class PessoaFisica : Pessoa
  51.     {
  52.         private string cpf;
  53.         public string Cpf
  54.         {
  55.             get{ return cpf;}
  56.             set{ cpf = value;}
  57.         }
  58.  
  59.         private string rg;
  60.         public string Rg
  61.         {
  62.             get{ return rg;}
  63.             set{rg = value;}
  64.         }
  65.  
  66.         public PessoaFisica(string nome, string endereço, string telefone, string cpf, string rg) : base(nome, endereço, telefone)
  67.         {
  68.             this.cpf = cpf;
  69.             this.rg = rg;
  70.         }
  71.  
  72.         public void cadastrar(PessoaFisica pf1)
  73.         {
  74.             z [aux] = pf1;
  75.             aux++;
  76.         }
  77.  
  78.         public override void mostrar()
  79.         {
  80.             for (int i = 0; i < aux; i++)
  81.             {
  82.                 Console.WriteLine (z [aux].Nome);
  83.                 Console.WriteLine (z [aux].Endereço);
  84.                 Console.WriteLine (z [aux].Telefone);
  85.                 Console.WriteLine (z [aux].cpf);
  86.                 Console.WriteLine (z [aux].rg);
  87.             }
  88.         }
  89.     }
  90.  
  91.     class PessoaJuridica : Pessoa
  92.     {
  93.         private string cnpj;
  94.         public string Cnpj
  95.         {
  96.             get{ return cnpj;}
  97.             set{ cnpj = value;}
  98.         }
  99.  
  100.         public PessoaJuridica(string nome, string endereço, string telefone, string cnpj): base(nome, endereço, telefone)
  101.         {
  102.             this.cnpj = cnpj;
  103.         }
  104.  
  105.         public void cadastrari(PessoaJuridica pj1)
  106.         {
  107.             z [aux] = pj1;
  108.             aux++;
  109.         }
  110.  
  111.         public override void mostrar()
  112.         {
  113.             for (int i = 0; i < aux; i++)
  114.             {
  115.                 Console.WriteLine (z [aux].Nome);
  116.                 Console.WriteLine (z [aux].Endereço);
  117.                 Console.WriteLine (z [aux].Telefone);
  118.                 Console.WriteLine (z [aux].cnpj);
  119.  
  120.             }
  121.         }
  122.     }
  123.  
  124.        
  125.     class MainClass
  126.     {
  127.         public static void Main (string[] args)
  128.         {
  129.             Pessoa p1 = new Pessoa ("", "", "");
  130.             PessoaFisica pf;
  131.             PessoaJuridica pj;
  132.             int aux;
  133.             string nome; string endereço; string telefone; string cnpj; string cpf, rg;
  134.             int op = 0;
  135.             Console.WriteLine ("1-Pf, 2-PJ, 0-sair");
  136.             op = int.Parse(Console.ReadLine ());
  137.             while (op != 0)
  138.             {
  139.                 if (op == 1)
  140.                 {
  141.                     Console.Write ("Nome:");
  142.                     nome = Console.ReadLine ();
  143.  
  144.                     Console.Write ("Endereço:");
  145.                     endereço = Console.ReadLine ();
  146.  
  147.                     Console.Write ("Telefone:");
  148.                     telefone = Console.ReadLine ();
  149.  
  150.                     Console.Write ("CPF:");
  151.                     cpf = Console.ReadLine ();
  152.  
  153.                     Console.Write ("RG:");
  154.                     rg = Console.ReadLine ();
  155.  
  156.                     pf = new PessoaFisica (nome, endereço, telefone, cpf, rg);
  157.                     pf.cadastrar (pf);
  158.  
  159.                 }
  160.  
  161.                 if (op == 2)
  162.                 {
  163.                     Console.Write ("Nome:");
  164.                     nome = Console.ReadLine ();
  165.  
  166.                     Console.Write ("Endereço:");
  167.                     endereço = Console.ReadLine ();
  168.  
  169.                     Console.Write ("Telefone:");
  170.                     telefone = Console.ReadLine ();
  171.  
  172.                     Console.Write ("CNPJ:");
  173.                     cnpj = Console.ReadLine ();
  174.  
  175.  
  176.  
  177.                     pj = new PessoaJuridica (nome, endereço, telefone, cnpj);
  178.                     pj.cadastrari (pj);
  179.  
  180.                 }
  181.  
  182.                 if (op == 3)
  183.                 {
  184.                     p1.mostrar ();
  185.                 }
  186.  
  187.  
  188.                 Console.WriteLine ("1-Pf, 2-PJ, 3-Mostrar 0-sair");
  189.                 op = int.Parse(Console.ReadLine ());
  190.             }
  191.  
  192.         }
  193.     }
  194. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement