AULA 17 - 08/06/11 e AULA 18 - 15/06/11 - TRABALHO ALGORITMOS
Autor: Jefferson Figueiredo | Publicado: 2011-06-02T06:13:00-07:00

Nesta aula o professor nos passou um trabalho que servirá para recuperar a nota da prova o qual contém 3 questões que seguem abaixo resolvidas.

1) Em uma eleição presidencial existem quatro candidatos. Os votos são informados por meio de código. Os códigos utilizados são: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
   1, 2, 3, 4   Votos para os respectivos candidatos  
   5   Voto nulo  
   6   Voto em branco  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Faça um programa que calcule e mostre:-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o total de votos para cada candidato;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o total de votos nulos;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; o total de votos em branco;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a percentagem de votos nulos sobre o total de votos;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; a percentagem de votos em branco sobre o total de votos.&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Para finalizar o conjunto de votos, tem-se o valor ZERO e, para códigos inválidos, o programa deverá mostrar uma mensagem.
&nbsp;algoritmo "exercicio1"
var
&nbsp;&nbsp; voto,cont1,cont2,cont3,cont4,cont5,cont6:inteiro
&nbsp;&nbsp; pnulo,pbranco,cont7:real
inicio
&nbsp;&nbsp; cont1&lt;-0
&nbsp;&nbsp; cont2&lt;-0
&nbsp;&nbsp; cont3&lt;-0
&nbsp;&nbsp; cont4&lt;-0
&nbsp;&nbsp; cont5&lt;-0
&nbsp;&nbsp; cont6&lt;-0
&nbsp;&nbsp; repita
&nbsp;&nbsp; escreval("Informe o seu voto 1-2-3-4 ou 5-nulo 6-branco ou 0-sair")
&nbsp;&nbsp; leia(voto)
&nbsp;&nbsp; se(voto&lt;&gt;0)e(voto&lt;&gt;6)e(voto&lt;&gt;1)e(voto&lt;&gt;2)e(voto&lt;&gt;3)e(voto&lt;&gt;4)e(voto&lt;&gt;5)entao
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; repita
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; escreval("Código invalido, Informe novamente seu voto")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leia(voto)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ate(voto&gt;=0)e(voto&lt;=6)
&nbsp;&nbsp; fimse
&nbsp;&nbsp; se(voto=1)entao
&nbsp;&nbsp;&nbsp;&nbsp; cont1&lt;-cont1+1
&nbsp;&nbsp; senao
&nbsp;&nbsp;&nbsp;&nbsp; se(voto=2)entao
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cont2&lt;-cont2+1
&nbsp;&nbsp;&nbsp;&nbsp; senao
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se(voto=3)entao
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cont3&lt;-cont3+1
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; senao
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se(voto=4)entao
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cont4&lt;-cont4+1
&nbsp;&nbsp;&nbsp;&nbsp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bsp;&nbsp;&nbsp; fimse
&nbsp;&nbsp;&nbsp;&nbsp; fimse
&nbsp;&nbsp; ate voto = 0
&nbsp;&nbsp; cont7&lt;-cont1+cont2+cont3+cont4+cont5+cont6
&nbsp;&nbsp; pnulo&lt;-(cont5*100/cont7)
&nbsp;&nbsp; pbranco&lt;-(cont6*100/cont7)
&nbsp;&nbsp; escreval("Total de votos candidato 1",cont1," votos")
&nbsp;&nbsp; escreval("Total de votos candidato 2",cont2," votos")
&nbsp;&nbsp; escreval("Total de votos candidato 3",cont3," votos")
&nbsp;&nbsp; escreval("Total de votos candidato 4",cont4, " votos")
&nbsp;&nbsp; escreval("Total de votos nulos",cont5," votos")
&nbsp;&nbsp; escreval("Total de votos brancos",cont6," votos")
&nbsp;&nbsp; escreval("Percentagem nulos",pnulo,"% do total de votos")
&nbsp;&nbsp; escreval("Percentagem branco",pbranco,"% do total de votos")
fimalgoritmo
2) Faça um programa que receba um conjunto de valores inteiros e positivos, calcule e mostre o maior e o menor valor do conjunto. Considere que:-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; para encerrar a entrada de dados, deve ser digitado valor zero;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; para valores negativos, deve ser enviada uma mensagem;-&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; os valores negativos ou iguais a zero não entram nos cálculos.
algoritmo "exercicio2"
var
j,k,n:inteiro
inicio
j&lt;-0
k&lt;-0
repita
&nbsp;&nbsp; escreval("Informe um número ou 0-encerrar")
&nbsp;&nbsp; leia(n)
&nbsp;&nbsp; se (n&lt;0)entao
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; repita
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; escreval("ERRO. Esse programa nao aceita numero negativo, informe outro numero")
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leia(n)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ate(n&gt;=0)
&nbsp;&nbsp; fimse
&nbsp;&nbsp; se(j=0)entao
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j&lt;-n
&nbsp;&nbsp; fimse
&nbsp;&nbsp; se(k=0)entao
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; k&lt;-n
&nbsp;&nbsp; fimse
&nbsp;&nbsp; se(n&gt;j)e(n&lt;&gt;0)entao
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j&lt;-n
&nbsp;&nbsp; fimse
&nbsp;&nbsp; se(n&lt;k)e(n&lt;&gt;0)entao
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; k&lt;-n
&nbsp;&nbsp; fimse
ate(n=0)
escreval("O maior número é",,j)
escreval("O menor número é",k)
fimalgoritmo
3) Faça um programa que receba os dados a seguir de vários produtos: preço unitário, país de origem (1- Brasil, 2- Portugal e 3 – outros), meio de transporte (T – terrestre, F – fluvial e A – aéreo), carga perigosa (S- sim, N – não), finalize a entrada de dados com um preço inválido, ou seja, menor ou igual a zero e que calcule e mostre:O valor do      imposto, usando a tabela a seguir.

    Preço unitário    Percentual de imposto sobre o preço unitário   
  
   Até R$ 280,00   5.00%  
   Maior que R$ 280,00   10.00%  

O valor do      transporte usando a tabela a seguir

    Carga Perigosa    País de Origem    Valor do Transporte   
  
   S   1   R$ 140,00  
   2   R$ 59,00  
   3   R$ 67,00  
   N   1   R$ 34,00  
   2   R$ 59,00  
   3   R$ 168,00  

O valor do      seguro, usando a regra a seguir:
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Os produtos que vêm de Portugal e os produtos que utilizam transporte &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; aéreo pagam metade do valor do seu preço unitário como seguro.
O preço final,      ou seja, preço unitário mais imposto mais valor do transporte mais valor      do seguro.
O total dos      impostos (somando impostos de todos os produtos).
algoritmo "exercicio3" var &nbsp;&nbsp; preco,imposto:real &nbsp;&nbsp; pais:inteiro &nbsp;&nbsp; transporte,carga:caracter inicio &nbsp;&nbsp; imposto&lt;-0 &nbsp;&nbsp; repita &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; escreval("Informe o preco do produto") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leia(preco) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; escreval("Informe o pais 1-Brasil 2-Portugal 3-outros") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leia(pais) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; escreval("Informe o meio de transporte T-terrestre F-fluvial A-aereo") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leia(transporte) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; escreval("Carga perigosa ? S-sim N-não") &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; leia(carga) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se(preco &lt;= 280)entao &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+((preco/100)*5) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; senao &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+((preco/100)*10) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimse &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se(pais = 1)e(carga = "n")e((transporte="t")ou(transporte="f"))entao &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+34 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imposto&lt;-imposto+34 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimse &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se(pais = 1)e(carga = "n")e(transporte="a")entao &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+34 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+(preco/2) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imposto&lt;-imposto+34 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimse &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se(pais = 1)e(carga = "s")e((transporte="t")ou(transporte="f"))entao &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+140 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imposto&lt;-imposto+140 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimse &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se(pais = 1)e(carga = "s")e(transporte="a")entao &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+140 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+(preco/2) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imposto&lt;-imposto+140 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimse &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se(pais = 2)entao &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+59 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imposto&lt;-imposto+59 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimse &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se(pais = 3)e(carga = "s")e((transporte="t")ou(transporte="f"))entao &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+67 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imposto&lt;-imposto+67 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimse &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se(pais = 3)e(carga = "n")e((transporte="t")ou(transporte="f"))entao &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+168 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imposto&lt;-imposto+168 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimse &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se(pais = 3)e(carga = "n")e(transporte="a")entao &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+168 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+(preco/2) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imposto&lt;-imposto+168 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimse &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; se(pais = 3)e(carga = "s")e(transporte="a")entao &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+67 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; preco&lt;-preco+(preco/2) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; imposto&lt;-imposto+67 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fimse &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; escreval("Valor final é =",preco) &nbsp;&nbsp; ate (preco&lt;=0) &nbsp;&nbsp; escreval("Total dos impostos é =",imposto) fimalgoritmo

&nbsp;Na aula 17 foi nos passado esses 3 exercícios em forma de trabalho que servirá para recuperar a nota da prova, tive bastante dificuldade no exercício 3. Na aula 18 o professor corrigiu os exercícios e deu para ver que todos os algoritmos da turma haviam algum erro, só vendo a correção é que se percebe que um enunciado tão simples pode complicar muito forma de fazer algoritmos.&nbsp;
 


function click() {
if (event.button==2||event.button==3) {
oncontextmenu='return false'; alert ('Todos os direitos reservados');
}
}
function keypresed() {
alert(' Todos os direitos reservados ');
}
document.onkeydown=keypresed;
document.onmousedown=click
document.oncontextmenu = new Function("return false;")