Gui
    • 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 Recomeçar autor: Guilherme Oliveira Verissimo turma: InfoC número: 21 [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 Media (NotasAluno notas) { return (notas.nota1 + notas.nota2 + notas.nota3) / 3; } NotasAluno nova = new NotasAluno(); nova.nota1 = 5; nova.nota2 = 8; nova.nota3 = 9; double Teste = Media (nova); Teste // 7.33333333333333 ``` ### Exercício 2 Crie uma função que implemente a lógica para calcular a área do Retângulo. ```csharp= public class Retangulo { public int basee; public int altura; } public int AreaRetangulo (Retangulo ret) { return (ret.basee * ret.altura); } Retangulo nova = new Retangulo(); nova.altura = 10; nova.basee = 15; int Teste = AreaRetangulo(nova); Teste // 150 ``` ### 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 int basee; public int altura; } public bool AreasIguais (Triangulo tri1, Triangulo tri2) { double triangulo1 = tri1.basee * tri1.altura / 2; double triangulo2 = tri2.basee * tri2.altura / 2; return triangulo1 == triangulo2; } Triangulo tri1 = new Triangulo(); tri1.altura = 10; tri1.basee = 20; Triangulo tri2 = new Triangulo(); tri2.altura = 20; tri2.basee = 10; bool Teste = AreasIguais (tri1, tri2); Teste // 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 int VendaAcai (PedidoAcai pedido) { int pequeno = pedido.qtdpequeno * 10; int medio = pedido.qtdmedio * 12; int grande = pedido.qtdgrande * 14; return pequeno + medio + grande; } PedidoAcai pedido = new PedidoAcai(); pedido.qtdpequeno = 2; pedido.qtdmedio = 3; pedido.qtdgrande = 1; int Teste = VendaAcai (pedido); Teste // 70 ``` ### 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 int parcelas; } public double CalcularTotalVeiculo (CompraVeiculo compra) { double valortaxa = compra.preco / 100 * 5 * compra.parcelas; return compra.preco + valortaxa; } CompraVeiculo compra = new CompraVeiculo(); compra.preco = 32000; compra.parcelas = 12; double Teste = CalcularTotalVeiculo (compra); Teste // 51200 ``` ### 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 hifen = end.cep.Contains("-"); bool caract = end.cep.Length == 9; bool valido = hifen && caract; return end.nomePessoa + " o resultado da validação de seu CEP é: " + valido; } Endereco end = new Endereco(); end.nomePessoa = "Guilherme"; end.cep = "05665-198"; string Teste = ValidarCep (end); Teste // Guilherme 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 string ExtrairSobrenome (string nome) { return nome.Substring(nome.LastIndexOf(" ")); } public bool MesmaFamilia (Pessoa p1, Pessoa p2, Pessoa p3) { string P1 = ExtrairSobrenome(p1.nomeCompleto); string P2 = ExtrairSobrenome(p2.nomeCompleto); string P3 = ExtrairSobrenome(p3.nomeCompleto); return P1 == P2 && P1 == P3; } Pessoa p1 = new Pessoa(); p1.nomeCompleto = "Gustavo Ferreira Sousa"; Pessoa p2 = new Pessoa(); p2.nomeCompleto = "Pedro Ferreira Sousa"; Pessoa p3 = new Pessoa(); p3.nomeCompleto = "Lucas Oliveira Ferreira Sousa"; bool Teste = MesmaFamilia (p1, p2, p3); Teste // true ``` ### Exercício 8 Crie uma função que implemente a lógica para calcular a média de 4 notas de um aluno. * pedi ajuda nessa com o erick, ficou bem parecida com a dele ```csharp= using System; 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) { return Math.Pow(termo.b, 2) - (4 * termo.a * termo.c); } public Resultado EquacaoSegundoGrau (Equacao termo) { double X1 = (-termo.b + Math.Sqrt(Delta(termo))) / (2 * termo.a); double X2 = (-termo.b - Math.Sqrt(Delta(termo))) / (2 * termo.a); n.x1 = X1; n.x2 = X2; return n; } Resultado n = new Resultado(); Equacao termo = new Equacao(); termo.a = 1; termo.b = 4; termo.c = 2; Resultado Teste = EquacaoSegundoGrau (termo); Console.WriteLine(n.x1); Console.WriteLine(n.x2); // -0.585786437626905 // -3.41421356237309 ``` ### 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= using System; public class Casal { public DateTime nascPessoa1; public DateTime nascPessoa2; } public bool Libra (DateTime nascimento) { DateTime Setembro = new DateTime(nascimento.Year,09,23); DateTime Outubro = new DateTime(nascimento.Year,10,22); return nascimento >= Setembro && Outubro >= nascimento; } public bool Maior18 (DateTime nascimento) { return nascimento.AddYears(18) < System.DateTime.Now; } public bool PermitirEntradaCasal (Casal crushes) { bool MaiorIdade1 = Maior18 (crushes.nascPessoa1); bool MaiorIdade2 = Maior18 (crushes.nascPessoa2); bool SaoMaiores = MaiorIdade1 && MaiorIdade2; bool DeLibra1 = Libra (crushes.nascPessoa1); bool DeLibra2 = Libra (crushes.nascPessoa1); bool SaoLibra = DeLibra1 && DeLibra2; return SaoMaiores && SaoLibra; } Casal crushes = new Casal(); crushes.nascPessoa1 = new DateTime(2000,09,25); crushes.nascPessoa1 = new DateTime(2001,10,12); bool Teste = PermitirEntradaCasal (crushes); Teste // true ``` ### 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... ```csharp= public class Trajeto { public double distanciaida; public double distanciavolta; } public double GastoMensalAbastecimento (Trajeto comum, Trajeto rodizio, double consumo) { double C = (comum.distanciaida + comum.distanciavolta) * 4; double R = rodizio.distanciaida + rodizio.distanciavolta; double Totalandado = C + R; return Totalandado / consumo * 4.50; } Trajeto comum = new Trajeto(); comum.distanciaida = 12; comum.distanciavolta = 10; Trajeto rodizio = new Trajeto(); rodizio.distanciaida = 15; rodizio.distanciavolta = 11; double Teste = GastoMensalAbastecimento (comum, rodizio, 9.5); Teste // 54 ```

    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