vitomtolindo
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Session one: Recomeçar | Fundamentos da Lógica **Autor**: Vitório Trindade Santana **Turma**: Informática C **Número**: 50 [toc] ## Exercício 1 Crie uma função que implemente a lógica para calcular a média de 4 notas de um aluno. ```csharp= public class NotasAluno { public double nota1; public double nota2; public double nota3; public double nota4; } public double CalcularMedia (NotasAluno nota) { return (nota.nota1 + nota.nota2 + nota.nota3 + nota.nota4) / 4; } NotasAluno nota = new NotasAluno (); nota.nota1 = 7; nota.nota2 = 6; nota.nota3 = 8; nota.nota4 = 9; double q1 = CalcularMedia (nota); Console.WriteLine("A média da nota do aluno é: " + q1); //A média da nota do aluno é: 7.5 ``` ## Exercício 2 Crie uma função que implemente a lógica para calcular a área do Retângulo. ```csharp= public class Retangulo { public double baseretangulo; public double altura; } public double AreaRetangulo (Retangulo dimensao) { return dimensao.baseretangulo * dimensao.altura; } Retangulo e = new Retangulo(); e.baseretangulo = 10; e.altura = 6; double q2 = AreaRetangulo (e); Console.WriteLine("A área do retângulo é: " + q2); //A área do retângulo é: 60 ``` ## Exercício 3 Crie uma função que a partir da base e altura de dois triângulos diferentes, crie uma função que verifique se o [Triângulo-1] possui a área igual ao [Triângulo-2], retorne verdadeiro se forem iguais e falso se forem diferentes. ```csharp= public class Triangulo { public double basetriangulo; public double alturatriangulo; } public bool AreasIguais (Triangulo dimensao1, Triangulo dimensao2) { double trian1 = (dimensao1.basetriangulo * dimensao1.alturatriangulo) / 2; double trian2 = (dimensao2.basetriangulo * dimensao2.alturatriangulo) / 2; bool a = trian1 == trian2; return a; } Triangulo t1 = new Triangulo (); t1.basetriangulo = 5; t1.alturatriangulo = 10; Triangulo t2 = new Triangulo (); t2.basetriangulo = 2; t2.alturatriangulo = 25; bool q3 = AreasIguais (t1, t2); Console.WriteLine("A área dos triângulos são iguais?: " + q3); //A área dos triângulos são iguais?: True ``` ## Exercício 4 Crie uma função que a partir da quantidade de açaí pequenos, médios e grandes comprados por um cliente, calcule o total a pagar sabendo que os valores do açaí são R$ 10,00, R$ 12,00 e R$ 14,00 respectivamente e não sofrerão alteração de preço. ```csharp= public class PedidoAcai { public int qtdPequeno; public int qtdMedio; public int qtdGrande; } public double VendaAcai (PedidoAcai qtd) { double pequeno = 10; double medio = 12; double grande = 14; double calculo = (qtd.qtdPequeno * pequeno) + (qtd.qtdMedio * medio) + (qtd.qtdGrande * grande); return calculo; } PedidoAcai qtd = new PedidoAcai (); qtd.qtdPequeno = 1; qtd.qtdMedio = 0; qtd.qtdGrande = 2; double q4 = VendaAcai (qtd); Console.WriteLine("O valor da compra de açaí foi: " + q4); //O valor da compra de açaí foi: 38 ``` ## Exercício 5 Crie uma função que a partir do preço de um veículo e o total de parcelas que será financiado, calcule o valor final pago considerando uma taxa de 5% por mês. ```csharp= public class CompraVeiculo { public double preco; public double parcelas; } public double CalcularTotalVeiculo (CompraVeiculo compra) { double juros = compra.preco * compra.parcelas * 0.05; double total = compra.preco + juros; return total; } CompraVeiculo compra = new CompraVeiculo(); compra.preco = 17500; compra.parcelas = 9; double q5 = CalcularTotalVeiculo (compra); Console.WriteLine("O total a se pagar no veículo é: " + q5); //O total a se pagar no veículo é: 25375 ``` ## Exercício 6 Crie uma função que a partir do nome de uma pessoa e um CEP, verifique se o CEP contém o caractere hífen (-) e possui um total de 9 caracteres. Se o CEP for válido, retorne: “XXX, o resultado da validação de seu CEP é: true” ou “XXX, o resultado da validação de seu CEP é: false”. ```csharp= public class Endereco { public string nomePessoa; public string cep; } public string ValidarCep (Endereco end) { bool vc = end.cep.Length == 9 && end.cep.Contains("-"); string frase = end.nomePessoa + ", o resultado da validação de seu CEP é: " + vc; return frase; } Endereco np = new Endereco (); np.nomePessoa = "João Alvarez Costa"; np.cep = "67450-098"; string q6 = ValidarCep (np); Console.WriteLine(q6); //João Alvarez Costa, o resultado da validação de seu CEP é: True ``` ## Exercício 7 Crie uma função composta que a partir de três nomes completos, retorne verdadeiro/falso se as pessoas são da mesma família, comparando o último nome das três pessoas ```csharp= public class Pessoa { public string nomeCompleto; } public bool MesmaFamilia(Pessoa p1, Pessoa p2, Pessoa p3) { bool parentes = ExtrairSobrenome(p1.nomeCompleto) == ExtrairSobrenome(p2.nomeCompleto) && ExtrairSobrenome(p2.nomeCompleto) == ExtrairSobrenome(p3.nomeCompleto); return parentes; } public string ExtrairSobrenome(string nome) { int posicaoSobrenome = nome.LastIndexOf(" "); string sobrenome = nome.Substring(posicaoSobrenome); return sobrenome; } Pessoa p1 = new Pessoa (); p1.nomeCompleto = "José Alves Ferreira Costa"; Pessoa p2 = new Pessoa (); p2.nomeCompleto = "Maria Andrade Costa"; Pessoa p3 = new Pessoa (); p3.nomeCompleto = "Antônio Carlos Costa"; bool q7 = MesmaFamilia (p1, p2, p3); Console.WriteLine("São parentes? " + q7); //São parentes? True ``` ## Exercício 8 Crie uma função composta que a partir dos valores 'a', 'b' e 'c', calcule o valor de xi e xii baseado na equação de segundo grau. ```csharp= public class Equacao { public int a; public int b; public int c; } public class Resultado { public double x1; public double x2; } public double Delta (Equacao termo) { double delta = Math.Pow(termo.b, 2) - 4 * termo.a * termo.c; return delta; } public Resultado EquacaoSegundoGrau (Equacao termo) { double resX1 = (-termo.b + Math.Sqrt(Delta(termo))) / 2 * termo.a; double resX2 = (-termo.b - Math.Sqrt(Delta(termo))) / 2 * termo.a; Resultado res = new Resultado(); res.x1 = resX1; res.x2 = resX2; return res; } Equacao termos = new Equacao (); termos.a = 1; termos.b = -1; termos.c = -12; Resultado q8 = EquacaoSegundoGrau (termos); Console.WriteLine("O valor de x1 é: " + q8.x1); Console.WriteLine("O valor de x2 é: " + q8.x2); //O valor de x1 é: 4 //O valor de x2 é: -3 ``` ## Exercício 9 Crie uma função composta que implemente a lógica da seguinte situação: Em uma festa temática de Astrologia, só podem entrar pessoas que são de libra e maiores de 18 anos. Você deve retornar se um casal que irá a festa poderão entrar. ```csharp= public class Casal { public DateTime nascPessoa1; public DateTime nascPessoa2; } public bool PermitirEntradaCasal (Casal data) { bool maiores = Maior18(data.nascPessoa1) == true && Maior18(data.nascPessoa2) == true; bool libra = Libra (data.nascPessoa1) == true && Libra (data.nascPessoa2) == true; bool aptos = maiores == true && libra == true; return aptos; } public bool Maior18 (DateTime data) { DateTime a = DateTime.Now; DateTime b = a.AddYears(-18); bool confere = data <= b; return confere; } public bool Libra (DateTime nasc) { bool opcao1 = nasc.Month == 9 && nasc.Day > 22; bool opcao2 = nasc.Month == 10 && nasc.Day < 23; bool confirmar = opcao1 == true || opcao2 == true; return confirmar; } Casal datas = new Casal (); datas.nascPessoa1 = new DateTime(2003, 9, 23); datas.nascPessoa2 = new DateTime(2002, 10, 17); bool q9 = PermitirEntradaCasal (datas); Console.WriteLine("O casal pode entrar na festa? " + q9); //O casal pode entrar na festa? False ``` ## Exercício 10 Crie uma função que implemente a lógica da seguinte situação: Para ir e voltar do trabalho uma pessoa abastece o carro semanalmente. A distância percorrida na ida e volta são diferentes, já que ele percorre caminhos diferentes para fugir do trânsito. No dia do rodízio, ele ainda percorre outros caminhos de ida e volta para não levar multa. Sabendo que a pessoa trabalha apenas de segunda a sexta e que o carro será abastecido com gasolina, calcule o total que será gasto no mês considerando que um mês possui 4 semanas. Crie uma função para calcular o total gasto a partir das quilometragens de ida e volta, considerando o dia de rodízio e o consumo por litro do veículo. ```csharp= public class Trajeto { public double distanciaIda; public double distanciaVolta; } public double GastoMensalAbastecimento (Trajeto comum, Trajeto rodizio, double consumo) { double totalKmMes = (((comum.distanciaIda + comum.distanciaVolta) * 4) + rodizio.distanciaIda + rodizio.distanciaVolta) * 4; double totalGastoMes = (totalKmMes / consumo) * 4.38; return totalGastoMes; } Trajeto comum = new Trajeto (); comum.distanciaIda = 14; comum.distanciaVolta = 12; Trajeto rodizio = new Trajeto (); rodizio.distanciaIda = 16; rodizio.distanciaVolta = 18; double q10 = GastoMensalAbastecimento (comum, rodizio, 15); Console.WriteLine("O total gasto por mês é: " + q10); //O total gasto por mês é: 161.184 ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully