Problema de los peces
#include <iostream>
using namespace std;
int main()
{
int totalfish, id;
double average, p1, p2, p3, p4, p5, totalweight;
cout << "Fisherman, give me your id: ";
cin >> id;
cout << "How many fish did you fish? ";
cin >> totalfish;
cout << "What is the weight of the first fish in pounds? ";
cin >> p1;
cout << "What is the weight of the second fish in pounds? ";
cin >> p2;
cout << "What is the weight of the third fish in pounds? ";
cin >> p3;
cout << "What is the weight of the fourth fish in pounds? ";
cin >> p4;
cout << "What is the weight of the fifth fish in pounds? ";
cin >> p5;
totalweight= (p1+p2+p3+p4+p5)/2;
cout << "The total weight in kilos is: " <<totalweight<<endl;
average= (totalweight*2)/5;
cout << "The result of the average is: " <<average;
return 0;
}
cpp.sh/7f5y
1. Ask a person to enter 3 random numbers, then ask another person to enter
other 3 random numbers, calculate the average of each person and a final
average for both people. show each result
#include <iostream>
using namespace std;
int main ()
{
double x, y, z, a, b, c;
double average1, average2, averaget;
cout << "The following 3 number are from the first person: ";
cout << "Give me the first number: ";
cin >> x;
cout << "Give me the second number: ";
cin >> y;
cout << "Give me the third number: ";
cin >> z;
cout << "The following 3 number are from the second person: ";
cout << "Give me the first number: ";
cin >> a;
cout << "Give me the second number: ";
cin >> b;
cout << "Give me the third number: ";
cin >> c;
average1= (x+y+z)/3;
average2= (a+b+c)/3;
averaget= (average1+average2)/2;
cout << "The average of the number of the first person is: " <<average1<<endl;
cout << "The average of the number of the second person is: " <<average2<<endl;
cout << "The final average for both people is: " <<averaget;
return 0;
}
cpp.sh/62y3t
2. Ask an employee how many hours does he work per week and how much he
gets paid per hour, calculate the gross salary (salario bruto- horas trabajas x
valor hora), how much he gets in deductions (4% health, 4% pension), net
salary (salario neto- salario bruto menos deducciones) show each result.
#include <iostream>
using namespace std;
int main ()
{
double horas, pago;
double sb, ds, dp, sn;
cout << "How many hours do you work per week? ";
cin >> horas;
cout << "How much do you get paid per hour? ";
cin >> pago;
sb= horas*pago;
ds= 0.04*sb;
dp= 0.04*sb;
sn= sb-(ds+dp);
cout << "The gross salary is: " <<sb<<endl;
cout << "The health deductions are: " <<ds<<endl;
cout << "The pension deductions are: " <<dp<<endl;
cout << "The net salary is: " <<sn;
return 0;
}
cpp.sh/4ysms
3. Ask a person how much money he/she has in his/her bank account, calculate
an interest of 3% for that amount of money. Each month he/she receives that
interest in his account. How much money will he/she have after 8 months?
Show the result
#include <iostream>
using namespace std;
int main ()
{
double money;
double interesm, interes8, dinerot;
cout << "How much money do you have in your bank account? ";
cin >> money;
interesm= money*0.03;
interes8= interesm*8;
dinerot= interes8+money;
cout << "The interest per month in your account will be: " <<interesm<<endl;
cout << "After 8 months, the total of interests that you will receive is: "
<<interes8<<endl;
cout << "The total money, after 8 months will be: " <<dinerot;
return 0;
}
cpp.sh/5aor
4.. Ask a person how much money he/she has in his/her bank account. Tell him
to make a deposit (add money) and a withdraw ( extract money). Calculate the
final balance after the deposit and the withdraw.
Show the result
#include <iostream>
using namespace std;
int main ()
{
double money, d, r;
double moneyt;
cout << "How much money do you have in your bank account? ";
cin >> money;
cout << "How much money are you going to deposit in your account? ";
cin >> d;
cout << "How much money are you going to withdraw from your account? ";
cin >> r;
moneyt= money+d-r;
cout << "The final balance in your bank account is: " <<moneyt;
return 0;
}
cpp.sh/7hc5
Conditionals
1. ¿Qué clase de triángulo es?
#include <iostream>
using namespace std;
int main()
{
int lado1, lado2, lado3;
cout<< "El primer lado mide ";
cin>> lado1;
cout<< "El segundo lado mide ";
cin>> lado2;
cout<< "El tercer lado mide ";
cin>> lado3;
if ((lado1==lado2)&&(lado2==lado3)&&(lado1==lado3))
{
cout<<"El triangulo es equilatero " <<endl;
}
if ((lado1!=lado2)&&(lado2!=lado3)&&(lado1!=lado3))
{
cout<< "El triangulo es escaleno" <<endl;
}
else
{
cout<<"El triangulo es isosceles" <<endl;
}
}
cpp.sh/4ubh
2. Notas de estudiantes
#include <iostream>
using namespace std;
int main ()
{
int score;
cout << "Give me your score: ";
cin >> score;
if ((score>=90) && (score<=100))
{
cout << "You got an A" <<endl;
}
if ((score>=80) && (score<=89))
{
cout << "You got a B" <<endl;
}
if ((score>=70) && (score<=79))
{
cout << "You got a C" <<endl;
}
if ((score>=60) && (score<=69))
{
cout << "You got a D" <<endl;
}
if ((score>=0) && (score<=59))
{
cout << "You got a F" <<endl;
}
}
cpp.sh/5sn7

Programación

  • 1.
    Problema de lospeces #include <iostream> using namespace std; int main() { int totalfish, id; double average, p1, p2, p3, p4, p5, totalweight; cout << "Fisherman, give me your id: "; cin >> id; cout << "How many fish did you fish? "; cin >> totalfish; cout << "What is the weight of the first fish in pounds? "; cin >> p1; cout << "What is the weight of the second fish in pounds? "; cin >> p2; cout << "What is the weight of the third fish in pounds? "; cin >> p3; cout << "What is the weight of the fourth fish in pounds? "; cin >> p4; cout << "What is the weight of the fifth fish in pounds? "; cin >> p5; totalweight= (p1+p2+p3+p4+p5)/2; cout << "The total weight in kilos is: " <<totalweight<<endl; average= (totalweight*2)/5; cout << "The result of the average is: " <<average; return 0; } cpp.sh/7f5y
  • 2.
    1. Ask aperson to enter 3 random numbers, then ask another person to enter other 3 random numbers, calculate the average of each person and a final average for both people. show each result #include <iostream> using namespace std; int main () { double x, y, z, a, b, c; double average1, average2, averaget; cout << "The following 3 number are from the first person: "; cout << "Give me the first number: "; cin >> x; cout << "Give me the second number: "; cin >> y; cout << "Give me the third number: "; cin >> z; cout << "The following 3 number are from the second person: "; cout << "Give me the first number: "; cin >> a; cout << "Give me the second number: "; cin >> b; cout << "Give me the third number: "; cin >> c; average1= (x+y+z)/3; average2= (a+b+c)/3; averaget= (average1+average2)/2; cout << "The average of the number of the first person is: " <<average1<<endl; cout << "The average of the number of the second person is: " <<average2<<endl; cout << "The final average for both people is: " <<averaget; return 0; } cpp.sh/62y3t
  • 3.
    2. Ask anemployee how many hours does he work per week and how much he gets paid per hour, calculate the gross salary (salario bruto- horas trabajas x valor hora), how much he gets in deductions (4% health, 4% pension), net salary (salario neto- salario bruto menos deducciones) show each result. #include <iostream> using namespace std; int main () { double horas, pago; double sb, ds, dp, sn; cout << "How many hours do you work per week? "; cin >> horas; cout << "How much do you get paid per hour? "; cin >> pago; sb= horas*pago; ds= 0.04*sb; dp= 0.04*sb; sn= sb-(ds+dp); cout << "The gross salary is: " <<sb<<endl; cout << "The health deductions are: " <<ds<<endl; cout << "The pension deductions are: " <<dp<<endl; cout << "The net salary is: " <<sn; return 0; } cpp.sh/4ysms
  • 4.
    3. Ask aperson how much money he/she has in his/her bank account, calculate an interest of 3% for that amount of money. Each month he/she receives that interest in his account. How much money will he/she have after 8 months? Show the result #include <iostream> using namespace std; int main () { double money; double interesm, interes8, dinerot; cout << "How much money do you have in your bank account? "; cin >> money; interesm= money*0.03; interes8= interesm*8; dinerot= interes8+money; cout << "The interest per month in your account will be: " <<interesm<<endl; cout << "After 8 months, the total of interests that you will receive is: " <<interes8<<endl; cout << "The total money, after 8 months will be: " <<dinerot; return 0; } cpp.sh/5aor
  • 5.
    4.. Ask aperson how much money he/she has in his/her bank account. Tell him to make a deposit (add money) and a withdraw ( extract money). Calculate the final balance after the deposit and the withdraw. Show the result #include <iostream> using namespace std; int main () { double money, d, r; double moneyt; cout << "How much money do you have in your bank account? "; cin >> money; cout << "How much money are you going to deposit in your account? "; cin >> d; cout << "How much money are you going to withdraw from your account? "; cin >> r; moneyt= money+d-r; cout << "The final balance in your bank account is: " <<moneyt; return 0; } cpp.sh/7hc5
  • 6.
    Conditionals 1. ¿Qué clasede triángulo es? #include <iostream> using namespace std; int main() { int lado1, lado2, lado3; cout<< "El primer lado mide "; cin>> lado1; cout<< "El segundo lado mide "; cin>> lado2; cout<< "El tercer lado mide "; cin>> lado3; if ((lado1==lado2)&&(lado2==lado3)&&(lado1==lado3)) { cout<<"El triangulo es equilatero " <<endl; } if ((lado1!=lado2)&&(lado2!=lado3)&&(lado1!=lado3)) { cout<< "El triangulo es escaleno" <<endl; } else { cout<<"El triangulo es isosceles" <<endl; } } cpp.sh/4ubh
  • 7.
    2. Notas deestudiantes #include <iostream> using namespace std; int main () { int score; cout << "Give me your score: "; cin >> score; if ((score>=90) && (score<=100)) { cout << "You got an A" <<endl; } if ((score>=80) && (score<=89)) { cout << "You got a B" <<endl; } if ((score>=70) && (score<=79)) { cout << "You got a C" <<endl; } if ((score>=60) && (score<=69)) { cout << "You got a D" <<endl; } if ((score>=0) && (score<=59)) { cout << "You got a F" <<endl; } } cpp.sh/5sn7