". . . there is a huge difference between programs that merely work
and programs that are well-engineered,
just as there is a huge difference
between a log thrown over a river and a well-engineered bridge."
" . . . there is a huge difference between working programs and good programs.
A good program not only works, but is easy to read and maintain."
—P. A. Darnell, Ph. E. Margolis, Software Engineering in C
"Programs must be written for people to read, and incidentally for machines to execute."
— H. Abelson, G. Sussman, The Structure and Interpretation of Computer Programs
"Any fool can write code that a computer can understand.
Good programmers write code that humans can understand."
— Martin Fowler, Refactoring: Improving the Design of Existing Code
Fala galera!!!and programs that are well-engineered,
just as there is a huge difference
between a log thrown over a river and a well-engineered bridge."
" . . . there is a huge difference between working programs and good programs.
A good program not only works, but is easy to read and maintain."
—P. A. Darnell, Ph. E. Margolis, Software Engineering in C
"Programs must be written for people to read, and incidentally for machines to execute."
— H. Abelson, G. Sussman, The Structure and Interpretation of Computer Programs
"Any fool can write code that a computer can understand.
Good programmers write code that humans can understand."
— Martin Fowler, Refactoring: Improving the Design of Existing Code
Mais uma vez, aqui estou eu.
Seguinte, nessa Postagem, vou dispor das respostas das Atividades de Lógica e Programação. Será uma boa para vocês aproveitarem e estudarem.
Então vamos lá.
Grupo 3:
Respostas dos Exercicíos.
1 /*********************************************************
2 Esse programa retira a raiz dos numeros inteiros impares
3 *********************************************************/
4 #include <iostream>
5 #include <cmath>
6
7 int main()
8 {
9 using namespace std;
10
11 for(int i = 1; i < 21; i++){
12 if(i % 2 != 0)
13 cout << i << " - " << sqrt(i) << endl << endl;
14 }
15 return 0;
16 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
1 /***************************************************************
2 Esse programa retorna o Fatorial (n!) de um determinado número
3 inteiro positivo.
4 ***************************************************************/
5 #include <iostream>
6 using namespace std;
7
8 int fatorial(int n){
9 if(n == 1)
10 return 1;
11 else
12 return n * fatorial(n-1);
13 }
14
15 int main()
16 {
17 int x;
18
19 cout << "Entre com qualquer valor inteiro: ";
20 cin >> x;
21
22 cout << endl;
23
24 cout << fatorial(x) << endl;
25
26 system("pause");
27 return 0;
28 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
1 /***************************************************
2 Esse programa retorna a soma dos números de 1 a 10.
3 ***************************************************/
4 #include <iostream>
5 int main()
6 {
7 using namespace std;
8 for(int i = 1; i < 11; ++i){
9
10 cout << i << "-----" << i + i - 1 << endl;
11 }
12
13 return 0;
14 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Grupo 2:
Respostas dos Exercicíos.
1 /********************************************************
2 Esse programa calcula o IMC de uma determinada pessoa.
3 ********************************************************/
4 #include <stdio.h>
5 #include <locale>
6 #include <conio.h>
7 #include <stdlib.h>
8
9 using namespace std;
10
11 int main()
12 {
13 setlocale(LC_ALL, "portuguese");
14
15 float p, alt, IMC;
16 char Q;
17
18 while((Q != 'N') && (Q != 'n')){
19
20 system("cls");
21
22 Q = 0;
23
24 printf("*** Tratamento de Pacientes com Deficiência em Peso ***");
25
26 printf("\n\n");
27
28 printf("Peso: ");
29 scanf("%f", &p);
30
31 printf("Altura: ");
32 scanf("%f", &alt);
33
34 IMC = p / (alt * alt);
35
36 printf("\nO rsultado obtido pelo Peso de %3.2f kg. e pela Altura de %1.2f o IMC é = %3.2f", p, alt, IMC);
37
38 printf("\n");
39
40 if(IMC >= 18 && IMC <= 25){
41 printf("\nVoce possui um peso normal.\n\n\n");
42 }else{
43 printf("\nVoce se encontra fora do peso ideal.\n\n\n");
44 }
45
46 printf("*** INFORMAÇÕES ***");
47 printf("\n\nPesos entre 18,5 kg e 25 kg = Peso Normal.\n");
48 printf("\nPesos abaixo de 18,5 kg ou acima de 25 kg = Fora do peso Ideal.\n");
49 printf("\nIMC entre 30 e 35 kg = Obesidade (Grau I).\n");
50 printf("\nIMC entre 35 e 40 kg = Obesidade (Grau II).\n");
51 printf("\nIMC acima de 40 = Peso Morbido.\n");
52
53
54 while((Q != 'n') && (Q != 'N') && (Q != 's') && (Q != 'S')){
55
56 printf("\n\nPara fazer outra operacao digite 's' ou 'n' para sair do programa: ");
57 Q = getch();
58 }
59 }
60
61 return 0;
62 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
1 /************************************************************
2 Este programa retorna a média do aluno e informa seu estado:
3 Aprovado, Exame ou Reprovado.
4 ************************************************************/
5 #include <iostream>
6 using namespace std;
7
8 int main()
9 {
10 float n1, n2, media;
11
12 cout << "Entre com a primeira nota: ";
13 cin >> n1;
14
15 cout << "Entre com a segunda nota: ";
16 cin >> n2;
17
18 media = (n1 + n2) / 2;
19 cout << "\nMedia do Aluno: " << media << endl;
20
21 if(media >= 7){
22 cout << "\nAluno Aprovado.\n";
23 }else if(media >= 3){
24 cout << "\nAluno de Exame.\n";
25 }else if(media < 3){
26 cout << "\nAluno Reprovado\n";
27 }
28 }
Implementação.
1 /************************************************************
2 Este programa calcula a media do aluno e informa seu estado:
3 Aprovado, Exame ou Reprovado.
4 ************************************************************/
5 #include <iostream>
6 using namespace std;
7
8 int main()
9 {
10 float n1, n2, media, NE;
11
12 cout << "Entre com a primeira nota: ";
13 cin >> n1;
14
15 cout << "Entre com a segunda nota: ";
16 cin >> n2;
17
18 media = (n1 + n2) / 2;
19 cout << "\nMedia do Aluno: " << media << endl;
20
21 if(media >= 7){
22 cout << "\nAluno Aprovado.\n";
23 }else if(media >= 3){
24 cout << "\nAluno de Exame.\n";
25 //Implementação para se saber a nota que o Aluno terá que obter no Exame para ser Aprovado.
26 NE = 10 - media;
27 cout << "\nO Aluno necessita tirar " << NE << ", para ser aprovado no Exame." << endl;
28 }else if(media < 3){
29 cout << "\nAluno Reprovado\n";
30 }
31 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
1 /******************************************************************************
2 Esse Programa calcula o recolhimento de IAPAS sobre
3 o salário de um funcionário. O desconto será conforme
4 a ordem: até 3 salarios - 8%, entre 3 e 5 - 9%, entre 5 e 10 ou acima - 11%.
5 ******************************************************************************/
6 #include <iostream>
7 using namespace std;
8
9 int main()
10 {
11 float sf, sm;
12
13 cout << "Entre Salario do Funcionario: ";
14 cin >> sf;
15
16 cout << "Entre Valor do Salario Minimo Atual: ";
17 cin >> sm;
18
19 if((sf / 3) <= sm){
20
21 sf = sf * 8 / 100;
22
23 cout << "Recolhimento IAPAS descontado = " << sf << endl;
24 }else if((sf / 4 || sf / 5) <= sm){
25 sf = sf * 9 / 100;
26 cout << "Recolhimento IAPAS descontado = " << sf << endl;
27 }else if((sf / 6 || sf / 7 || sf / 8 || sf / 9 || sf / 10) >= sm){
28 sf = sf * 11 / 100;
29 cout << "Recolhimento IAPAS descontado = " << sf << endl;
30
31 }
32
33 system("pause");
34 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
1 /**********************************************************
2 Esse programa calcula os valores dos produtos, calcula
3 o desconto e retorna o valor a ser pago pelo cliente.
4 **********************************************************/
5 #include <iostream>
6 using namespace std;
7
8 int main()
9 {
10 float PP = 1.99, TT, Desc, totalPagar;
11 int produto;
12
13 cout << "Entre quantidade de Produtos: ";
14 cin >> produto;
15
16 if(produto >= 20 && produto < 50){
17 TT = produto * PP;
18 cout << "Preco total dos produtos: R$" << TT << endl;
19 Desc = TT * 10 / 100;
20 totalPagar = TT - Desc;
21 cout << "Desconto da compra: R$" << Desc << endl;
22 cout << "Total a pagar: R$" << totalPagar << endl;
23
24 }else if(produto >= 50){
25 TT = produto * PP;
26 cout << "Preco total dos produtos: R$" << TT << endl;
27 Desc = TT * 15 / 100;
28 totalPagar = TT - Desc;
29 cout << "Desconto da compra: R$" << Desc << endl;
30 cout << "Total a pagar: R$" << totalPagar << endl;
31 }
32 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
Grupo 1:
Respostas dos Exercicíos.
1 /***************************************************
2 Esse programa calcula a idade da pessoa sabendo-se
3 seu ano de nascimento, e também recebe o Ano Atual.
4 ***************************************************/
5 #include <iostream>
6 #include <cstdlib>
7 using namespace std;
8
9 int main()
10 {
11 int aAtual, aNasc, id;
12
13 cout << "Entre com o Ano atual: ";
14 cin >> aAtual;
15
16 cout << "\nEntre com o Ano de seu Nascimento: ";
17 cin >> aNasc;
18
19 id = aAtual - aNasc;
20
21 cout << "\nVoce tem " << id << " anos.";
22
23 cout << "\n\n";
24
25 system("pause");
26 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
1 /************************************************************************
2 Esse programa retorna o Total dos produtos, Valor do desconto
3 e Total a pagar pelo cliente.
4 ************************************************************************/
5 #include <iostream>
6 #include <stdlib.h> //Permite o uso de system(); como por exemplo o system("cls");
7 #include <stdio.h>
8 #include <conio.h> //Permite o uso de getch();
9
10 using namespace std;
11
12 int main()
13 {
14 float pp, vd, vf, t = 10;
15 char r;
16
17 while(r != 'n'){
18
19 system("cls");
20
21 r = 0;
22
23 cout << "Entre Valor Produto: ";
24 cin >> pp;
25
26 vd = pp * t / 100;
27 vf = pp - vd;
28
29 printf("O Valor do Produto: %8.2f \n", pp);
30
31 printf("O Valor do Desconto: %8.2f \n", vd);
32
33 printf("O Valor a Pagar: %8.2f \n", vf);
34
35 cout << "\n\n\n\n";
36
37 while((r != 'n') && (r != 's')){
38
39 cout << "Para continuar digite s/, para sair do programa digite n/: ";
40
41 r = getch();
42
43 }
44 }
45 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
1 /***********************************************************
2 Esse programa recebe km_percorridos e qtd_litros, e retorna
3 o consumo_medio.
4 ***********************************************************/
5 #include <iostream>
6 #include <cstdlib>
7 using namespace std;
8
9 int main()
10 {
11 float consumo_medio, km_percorridos, qtd_litros;
12
13 cout << "Encha o tanque: ";
14 cin >> qtd_litros;
15
16 cout << "De que distancia estamos falando? ";
17 cin >> km_percorridos;
18
19 consumo_medio = km_percorridos / qtd_litros;
20
21 cout << "Consumo medio de combustivel e: " << consumo_medio << endl;
22
23 system("pause");
24 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
1 /**********************************************************************
2 Este programa faz a conversão de Graus Celsius para Graus Fahrenheit
3 *********************************************************************/
4 #include <stdio.h>
5 #include <cstdlib>
6 using namespace std;
7
8 int main()
9 {
10 float c, f; //Formula da conversão: f = c * 1,8 + 32
11
12 printf("Entre com o valor da Temparatura em Graus Celsius: ");
13 scanf("%f", &c);
14
15 f = c * 1.8 + 32;
16
17 printf("\nA conversao de %2.2f Graus Celsius para Fahrenheit"
18 " e igual a %2.2f Graus Fahrenheit.\n\n", c, f);
19
20 system("pause");
21 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
1 /****************************************************************************
2 Esse programa calcula os gastos de um determinado cliente em uma lanchone,
3 e retorna o valor total a ser pago.
4 ***************************************************************************/
5 #include <iostream>
6 #include <stdio.h>
7 using namespace std;
8
9 int main()
10 {
11 float H = 3.00, qtd_H, BF = 2.50, qtd_BF;
12 float Ref = 2.00, qtd_Ref;
13
14 cout << "Qtd de Hamburguers: ";cin >> qtd_H;
15
16 qtd_H *= H;
17
18 printf( "Total: R$%5.2f \n", qtd_H );
19
20 cout << "\n\n";
21
22 cout << "Qtd de Batatas Fritas: ";cin >> qtd_BF;
23
24 qtd_BF *= BF;
25
26 printf( "Total: R$%5.2f \n",qtd_BF );
27
28 cout << "\n\n";
29
30 cout << "Qtd de Refrigerantes: ";cin >> qtd_Ref;
31
32 qtd_Ref *= Ref;
33
34 printf( "Total: R$%5.2f \n", qtd_Ref );
35
36 cout << "\n\n";
37
38 printf( "Total a pagar: R$%5.2f \n", qtd_BF + qtd_H + qtd_Ref );
39 }
//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\//////////////////////////////////////////////////////////////////////////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
É isso ai.
Qualquer coisa, deixa um comentário aqui abaixo.
T+.
Fala Rodrigo blz...
ResponderExcluirMuito legal seu blog..
e nois..
sucesso!!!
Obrigado Angelo.
ExcluirPSEUDOCÓDIGO 02. ESSE TA OSSO.?
ResponderExcluirPara as questões abaixo considere o seguinte conjunto de
instruções:
SE VALOR-COM = 01 OR 10
SE VALOR-FINAC = 35 OR 36 OR 38 OR 40 OR 42
INDICADOR-SITUACAO = 2
SENAO
INDICADOR-SITUACAO = 1
FIM-SE
SE (VALOR-COM = 01 AND (VALOR-FINANC = 36 OR 38)) OR
(CLASSIF-SERVICO = 'LIRT' AND INDICADOR-SITUACAO = 1)
EXIBIR 'SITUACAO A'
SENAO
SE (CLASSIF-SERVICO = 'LTCA' OR 'LTRA' OR 'TUPC' OR 'TUPM' OR DDRD') AND
(VALOR-COM = 15 OR 16 OR 17)
EXIBIR 'SITUACAO B'
FIM-SE
FIM-SE
SENAO
SE VALOR-FINANC = 35 OR 36 OR 38 OR 40 OR 42
EXIBIR 'SITUACAO D'
SENAO
SE VALOR-FINANC NOT = 36 AND 38 AND CLASSIF-SERVICO = 'LIRT'
EXIBIR 'SITUACAO E'
SENAO
EXIBIR 'SITUACAO F'
FIM-SE
FIM-SE
FIM-SE
Qual situação será exibida se o programa chegar neste trecho com o
VALOR-COM=08, VALOR-FINANC=38 e CLASSIF-SERVICO=LIRA?
A: Situação A
B: Situação B
C: Situação C
D: Situação D