Created
April 9, 2012 01:51
-
-
Save HudsonAfonso/2340779 to your computer and use it in GitHub Desktop.
Estruturas condicionais parte 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! @file e02.cpp | |
@brief Exercício 2 - Estruturas condicionais | |
@author Hudson Afonso | |
@version 1.0.0-alpha - http://semver.org | |
@note Enviar para alexandrebrrib@gmail.com | |
@link https://gist.github.com/2340779#file_e02.cpp | |
Dados quatro números distintos, desenvolver um algoritmo que determine e | |
imprima a soma dos três menores. | |
*/ | |
#include <iostream> | |
using namespace std; | |
int num1; //!< @brief Número 1 | |
int num2; //!< @brief Número 2 | |
int num3; //!< @brief Número 3 | |
int num4; //!< @brief Número 4 | |
/*! @brief Exch troca os valores de duas variáveis. | |
@param &i Valor Inteiro a ser trocado. | |
@param &j Valor Inteiro a ser trocado. | |
@return void | |
*/ | |
void exch(int &i, int &j) | |
{ | |
int t = i; | |
i = j; | |
j = t; | |
} | |
int main() | |
{ | |
cout << "Entre com o número 1: "; | |
cin >> num1; | |
cout << "Entre com o número 2: "; | |
cin >> num2; | |
cout << "Entre com o número 3: "; | |
cin >> num3; | |
cout << "Entre com o número 4: "; | |
cin >> num4; | |
if (num1 > num2) | |
exch(num2, num1); | |
if (num1 > num3) | |
exch(num3, num1); | |
if (num1 > num4) | |
exch(num4, num1); | |
if (num2 > num3) | |
exch(num3, num2); | |
if (num2 > num4) | |
exch(num4, num3); | |
if (num3 > num4) | |
exch(num4, num3); | |
cout << "A soma dos três menores números é: " << num1 + num2 + num3 << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! @file e04.cpp | |
@brief Exercício 4 - Estruturas condicionais | |
@author Hudson Afonso | |
@version 1.0.0-alpha - http://semver.org | |
@note Enviar para alexandrebrrib@gmail.com | |
@link https://gist.github.com/2340779#file_e04.cpp | |
Desenvolver um algoritmo para ler um nuúmero X e calcular e imprimir o valor | |
de Y de acordo com as condições abaixo:\n | |
Y = X , se X < 1 ;\n | |
Y = 0 , se X = 1 ;\n | |
Y = X^2 , se X > 1. | |
*/ | |
#include <iostream> | |
using namespace std; | |
int x; //!< @brief Valor de X. | |
int y; //!< @brief Valor de Y. | |
int main() | |
{ | |
cout << "Digite o valor de X: "; | |
cin >> x; | |
if (x < 1) | |
{ | |
y = x; | |
} | |
if (x == 1) | |
{ | |
y = 0; | |
} | |
if (x > 1) | |
{ | |
y = x * x; | |
} | |
cout << "O valor de Y é: " << y << endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! @file e06.cpp | |
@brief Exercício 6 - Estruturas condicionais | |
@author Hudson Afonso | |
@version 1.0.0-alpha - http://semver.org | |
@note Enviar para alexandrebrrib@gmail.com | |
@link https://gist.github.com/2340779#file_e06.cpp | |
Desenvolver um algoritmo para ler o número de uma sala aula, sua capacidade e | |
o total de alunos matriculados na mesma e imprimir uma linha mostrando o | |
número da sala, sua capacidade, o número de cadeiras ocupadas e sua | |
disponibilidade indicando se a sala está lotada ou não. | |
*/ | |
#include <iostream> | |
using namespace std; | |
int num_sala; //!< @brief Número da sala de aula | |
int cap_sala; //!< @brief Capacidade da sala de aula | |
int matriculados; //!< @brief Total de alunos matriculados | |
int main() | |
{ | |
cout << "Entre com o número da sala: "; | |
cin >> num_sala; | |
cout << "Entre com a capacidade da sala: "; | |
cin >> cap_sala; | |
cout << "Entre com o total de alunos matriculados: "; | |
cin >> matriculados; | |
cout << "Sala: " << num_sala << " "; | |
cout << "Capacidade: " << cap_sala << " "; | |
cout << "Cadeiras ocupadas: " << matriculados << " "; | |
if (matriculados >= cap_sala) | |
{ | |
cout << "- SALA LOTADA" << endl; | |
} | |
else | |
{ | |
cout << "- SALA COM VAGAS" << endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! @file e08.cpp | |
@brief Exercício 8 - Estruturas condicionais | |
@author Hudson Afonso | |
@version 1.0.0-alpha - http://semver.org | |
@note Enviar para alexandrebrrib@gmail.com | |
@link https://gist.github.com/2340779#file_e08.cpp | |
Desenvolver um algoritmo para calcular a conta de água para a SANEAGO. O custo | |
da água varia dependendo se o consumidor é residencial, comercial ou | |
industrial. A regra para calcular a conta é:\n | |
• Residencial: R$ 5,00 de taxa mas R$ 0,05 por m^3 gastos;\n | |
• Comercial: R$ 500,00 para os primeiros 80 m^3 gastos mas R$ 0,25 por m^3 | |
gastos;\n | |
• Industrial: R$ 800,00 para os primeiros 100 m^3 gastos mas R$ 0,04 por m^3 | |
gastos.\n | |
O programa dever á ler a conta do cliente, o tipo de consumidor(residencial, | |
comercial e industrial) e o consumo de água por metros cubos, como resultado | |
imprima a conta do cliente e o valor em real a ser pago pelo mesmo. | |
*/ | |
#include <iostream> | |
using namespace std; | |
/*!< @brief Tipo de consumidor | |
1 - Residencial\n | |
2 - Comercial\n | |
3 - Industrial | |
*/ | |
int tipo; | |
string conta; //!< @brief Conta do cliente. | |
float consumo; //!< @brief Consumo de água em m^3. | |
float total; //!< @brief Valor em reais a ser pago. | |
int main() | |
{ | |
//Configura o cout para fixar em 2 casas decimais quando for float | |
cout.setf(ios::fixed); | |
cout.precision(2); | |
cout << "Entre com a conta: "; | |
cin >> conta; | |
cout << "[1] Residencial" << endl; | |
cout << "[2] Comercial" << endl; | |
cout << "[3] Industrial" << endl; | |
cout << "Entre com o número do tipo de conta: "; | |
cin >> tipo; | |
cout << "Entre com o consumo: "; | |
cin >> consumo; | |
if (tipo == 1) | |
{ | |
total = 5 + consumo * .05; | |
} | |
else | |
{ | |
if (tipo == 2) | |
{ | |
total = 500; | |
if (consumo > 80) | |
{ | |
total += (consumo - 80) * .25; | |
} | |
} | |
else | |
{ | |
total = 800; | |
if (consumo > 100) | |
{ | |
total += (consumo - 100) * .04; | |
} | |
} | |
} | |
cout << endl << "Conta: " << conta << endl; | |
cout << "Total a ser pago R$" << total; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! @file e10.cpp | |
@brief Exercício 10 - Estruturas condicionais | |
@author Hudson Afonso | |
@version 1.0.0-alpha - http://semver.org | |
@note Enviar para alexandrebrrib@gmail.com | |
@link https://gist.github.com/2340779#file_e10.cpp | |
Desenvolver um algoritmo com as opções de calcular e imprimir o volume e a | |
área de superfície de um cone reto, um cilindro ou uma esfera. O algoritmo | |
deverá ler a opção da figura desejada(cone / cilindro / esfera) e de acordo | |
com a opção escolhida calcular o volume e a área de superfície da figura | |
pedida. | |
*/ | |
#include <iostream> | |
#include <math.h> | |
using namespace std; | |
float volume; //!< @brief Volume da Figura | |
float area; //!< @brief Área da Figura | |
float raio; //!< @brief Raio | |
float altura; //!< @brief Altura | |
/*! @brief Figura desejada | |
1 - Cone Reto\n | |
2 - Cilindro\n | |
3 - Esfera | |
*/ | |
int figura; | |
int main() | |
{ | |
cout << "[1] Cone Reto" << endl; | |
cout << "[2] Cilindro" << endl; | |
cout << "[3] Esfera" << endl; | |
cout << "Entre com o número da figura desejada: "; | |
cin >> figura; | |
cout << "Entre com o raio: "; | |
cin >> raio; | |
cout << "Entre com a altura: "; | |
cin >> altura; | |
if (figura == 1) | |
{ | |
volume = M_PI * pow(raio, 2) * altura / 3; | |
area = M_PI * raio * sqrt(pow(raio, 2) + pow(altura, 2)); | |
cout << "O volume do Cone Reto em metros cubicos é: " << volume; | |
cout << "A area do Cone Reto em metros quadrados é: " << area; | |
} | |
else | |
{ | |
if (figura == 2) | |
{ | |
volume = M_PI * pow(raio, 2) * altura; | |
area = 2 * M_PI * raio * altura; | |
cout << "O volume do Cilindro em metros cubicos é: " << volume; | |
cout << "A area do Cilindro em metros quadrados é: " << area; | |
} | |
else | |
{ | |
volume = 4 / 3 * M_PI * pow(raio, 3); | |
area = 4 * M_PI * pow(raio, 2); | |
cout << "O volume da Esfera em metros cubicos é: " << volume; | |
cout << "A area da Esfera em metros quadrados é: " << area; | |
} | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! @file e12.cpp | |
@brief Exercício 12 - Estruturas condicionais | |
@author Hudson Afonso | |
@version 1.0.0-alpha - http://semver.org | |
@note Enviar para alexandrebrrib@gmail.com | |
@link https://gist.github.com/2340779#file_e12.cpp | |
Fazer um algoritmo que dado um número inteiro positivo, calcular e escreva se | |
este é positivo e múltiplo de 3 ao mesmo tempo. | |
*/ | |
#include <iostream> | |
using namespace std; | |
int num; //!< @brief Número inteiro. | |
int main() | |
{ | |
cout << "Entre com um número inteiro: "; | |
cin >> num; | |
if (num >= 0 && num % 3 == 0) | |
{ | |
cout << "O número inteiro é positivo e múltiplo de 3" << endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! @file e14.cpp | |
@brief Exercício 14 - Estruturas condicionais | |
@author Hudson Afonso | |
@version 1.0.0-alpha - http://semver.org | |
@note Enviar para alexandrebrrib@gmail.com | |
@link https://gist.github.com/2340779#file_e14.cpp | |
Fazer um algoritmo que dado três valores A, B, e C verificar se eles formam | |
um triângulo. Formando triângulo dizer se é triângulo equilátero, isósceles | |
ou escaleno. | |
*/ | |
#include <iostream> | |
#include <math.h> | |
using namespace std; | |
int a; //!< @brief Lado A do triângulo. | |
int b; //!< @brief Lado B do triângulo. | |
int c; //!< @brief Lado C do triângulo. | |
string tipo; //!< @brief Tipo do triângulo. | |
int main() | |
{ | |
cout << "Entre com o lado A: "; | |
cin >> a; | |
cout << "Entre com o lado B: "; | |
cin >> b; | |
cout << "Entre com o lado C: "; | |
cin >> c; | |
if (abs(b - c) < a && a < b + c) | |
{ | |
if (a == b && a == c && b == c) | |
{ | |
tipo = "equilátero"; | |
} | |
else | |
{ | |
if (a == b || a == c || b == c) | |
{ | |
tipo = "isósceles"; | |
} | |
else | |
{ | |
if (a != b && a != c && b != c) | |
{ | |
tipo = "escaleno"; | |
} | |
} | |
} | |
cout << "Triângulo " << tipo << endl; | |
} | |
else | |
{ | |
cout << "A, B e C não formam um Triângulo." << endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! @file e16.cpp | |
@brief Exercício 16 - Estruturas condicionais | |
@author Hudson Afonso | |
@version 1.0.0-alpha - http://semver.org | |
@note Enviar para alexandrebrrib@gmail.com | |
@link https://gist.github.com/2340779#file_e16.cpp | |
Fazer um algoritmo que calcule a média aritmética das 3 notas de um aluno e | |
mostre, além do valor da média, uma mensagem de "Aprovado", caso a média seja | |
igual ou superior a 6, ou a mensagem "Reprovado", caso contrário. | |
*/ | |
#include <iostream> | |
using namespace std; | |
float n1; //!< @brief Nota 1 | |
float n2; //!< @brief Nota 2 | |
float n3; //!< @brief Nota 3 | |
float media; //!< @brief Média aritmética | |
int main() | |
{ | |
//Configura o cout para fixar em 2 casas decimais quando for float | |
cout.setf(ios::fixed); | |
cout.precision(2); | |
cout << "Entre com a Nota 1: "; | |
cin >> n1; | |
cout << "Entre com a Nota 2: "; | |
cin >> n2; | |
cout << "Entre com a Nota 3: "; | |
cin >> n3; | |
media = (n1 + n2 + n3) / 3; | |
if (media >= 6) | |
{ | |
cout << media << " - Aprovado" << endl; | |
} | |
else | |
{ | |
cout << media << " - Reprovado" << endl; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! @file e18.cpp | |
@brief Exercício 18 - Estruturas condicionais | |
@author Hudson Afonso | |
@version 1.0.0-alpha - http://semver.org | |
@note Enviar para alexandrebrrib@gmail.com | |
@link https://gist.github.com/2340779#file_e18.cpp | |
Escreva um algoritmo que leia o código de um aluno e suas três notas. Calcule | |
a média ponderada do aluno, considerando que o peso para a maior nota seja 4 | |
e para as duas restantes, 3. Mostre o código do aluno, suas três notas, a | |
média calculada e uma mensagem "APROVADO" se a média for maior ou igual a 5 e | |
"REPROVADO" se a média for menor que 5. | |
*/ | |
#include <iostream> | |
using namespace std; | |
string codigo; //!< @brief Código do aluno | |
float n1; //!< @brief Nota 1 | |
float n2; //!< @brief Nota 2 | |
float n3; //!< @brief Nota 3 | |
float media; //!< @brief Média ponderada | |
/*! @brief Exch troca os valores de duas variáveis. | |
@param &i Valor Inteiro a ser trocado. | |
@param &j Valor Inteiro a ser trocado. | |
@return void | |
*/ | |
void exch(float &i, float &j) | |
{ | |
int t = i; | |
i = j; | |
j = t; | |
} | |
int main() | |
{ | |
//Configura o cout para fixar em 2 casas decimais quando for float | |
cout.setf(ios::fixed); | |
cout.precision(2); | |
cout << "Entre com o código do aluno: "; | |
cin >> codigo; | |
cout << "Entre com a Nota 1: "; | |
cin >> n1; | |
cout << "Entre com a Nota 2: "; | |
cin >> n2; | |
cout << "Entre com a Nota 3: "; | |
cin >> n3; | |
if (n1 > n2) | |
{ | |
exch(n2, n1); | |
} | |
if (n1 > n3) | |
{ | |
exch(n3, n1); | |
} | |
if (n2 > n3) | |
{ | |
exch(n3, n2); | |
} | |
media = (n3 * 4 + n2 * 3 + n1 * 3) / 10; | |
cout << endl; | |
cout << "Código do aluno: " << codigo << endl; | |
cout << "Nota 1: " << n1 << endl; | |
cout << "Nota 2: " << n2 << endl; | |
cout << "Nota 3: " << n3 << endl; | |
cout << "Média: " << media; | |
if (media >= 5) | |
{ | |
cout << " - APROVADO"; | |
} | |
else | |
{ | |
cout << " - REPROVADO"; | |
} | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*! @file e20.cpp | |
@brief Exercício 20 - Estruturas condicionais | |
@author Hudson Afonso | |
@version 1.0.0-alpha - http://semver.org | |
@note Enviar para alexandrebrrib@gmail.com | |
@link https://gist.github.com/2340779#file_e20.cpp | |
Tendo como dados de entrada a altura e o sexo de uma pessoa (?M? masculino e | |
?F? feminino), construa um algoritmo que calcule seu peso ideal, utilizando | |
as seguintes fórmulas:\n | |
- para homens: (72.7*h)-58 \n | |
- para mulheres: (62.1*h)-44.7 | |
*/ | |
#include <iostream> | |
using namespace std; | |
float altura; //!< @brief Altura. | |
string sexo; //!< @brief Sexo, "?M?" para masculino e "?F?" para feminino. | |
float peso; //!< @brief Peso ideal. | |
int main() | |
{ | |
//Configura o cout para fixar em 2 casas decimais quando for float | |
cout.setf(ios::fixed); | |
cout.precision(2); | |
cout << "Entre com a altura: "; | |
cin >> altura; | |
cout << "Entre com o sexo(?M? masculino e ?F? feminino): "; | |
cin >> sexo; | |
if (sexo.compare("?M?") == 0) | |
{ | |
peso = (72.7 * altura) - 58; | |
} | |
else | |
{ | |
if (sexo.compare("?F?") == 0) | |
{ | |
peso = (62.1 * altura) - 44.7; | |
} | |
} | |
cout << "Peso Ideal: " << peso; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment