You are on page 1of 15

Encabezado: WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 1

Student : Nicolas Esteban Beltrán Ramos

Code : 67001076

Mail : nebeltran76@ucatolica.edu.co

Bogotá D.C

15/02/2023
WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 2

Introduction

In this work we will show the development of workshop #1 of cut #1. The workshop

consists of 8 points which deal with the resolution of application of problems about

conditionals in the C++ programming language, in this case the conditional "if".

Keywords: (C++, workshop, conditional, programming).

Objectives

General Objective

- Correctly and completely develop the resolution of workshop 1 of cut 1.

Specific Objectives

- Set out the input, output and conditions of each application problem.

- Create the respective code for each application problem.

- To show failures in the code


WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 3

Exercise 1

Content

Inputs: 3, values, integer type

Outputs: 3 , Positive discriminant, Discriminant equal to 0 and Negative discriminant

show message " the equation has no real roots ".

Entry conditions: x1 = (-b+(sqrt(b*b-4*a*c)))/(2*a);

x2 = (-b-(sqrt(b*b-4*a*c)))/(2*a);

Exit conditions: (b*b-4*a*c > 0) , (b*b-4*a*c == 0)

#include <iostream>
#include <math.h >
using namespace std;
int main(int argc, char *argv[]) {
float a,b,c;
float x1,x2;
cout<<"Ingrese el valor de a "<<endl;
cin>>a;
cout<<"Ingrese el valor de b "<<endl;
cin>>b;
cout<<"Ingrese el valor de c "<<endl;
cin>>c;

x1 = (-b+(sqrt(b*b-4*a*c)))/(2*a);
x2 = (-b-(sqrt(b*b-4*a*c)))/(2*a);
WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 4

#include <iostream>
//Si el discriminante es positivo
if (b*b-4*a*c > 0){
cout<<"x1 = "<< x1<<endl;
cout<<"x2 = "<< x2<<endl;
}

//Si el discriminante es igual a 0


else if (b*b-4*a*c == 0){
cout<<"x1 = "<< x1<<endl;

cout<<"La ecuación tiene una raiz "<<x1<<endl;


}
//Si el discriminante es negativo
else {
cout<<" La ecuación no tiene raíces reales "<<endl;
}
return 0;

Exercise 2

Content

Inputs: 6, values, real type

Outputs: 2, result for x, result for y, equation has no solution

Entry conditions: values >0, values ¡= 0

Exit conditions: w = (a*d - b*c);

x = (e*d - b*f) / (a*d - b*c); y = (a*f - e*c) / (a*d - b*c);


WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 5

#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {

float a,b,c,d,e,f,x,y,w;

cout<< " Ingrese el valor de a " <<endl;


cin>> a;
cout<< " Ingrese el valor de b " <<endl;
cin>> b;
cout<< " Ingrese el valor de c " <<endl;
cin>> c;
cout<< " Ingrese el valor de d " <<endl;
cin>> d;
cout<< " Ingrese el valor de e " <<endl;
cin>> e;
cout<< " Ingrese el valor de f " <<endl;
cin>> f;

cout<<endl;

w= (a*d - b*c);

if ( w != 0) {

x = (e*d - b*f) / (a*d - b*c);

y = (a*f - e*c) / (a*d - b*c);

cout<<" el resultado para x es : " << x <<endl;

cout<<" el resultado par y es : " << y <<endl;

}else{

cout<< " La ecuacion no tiene solucion " ;

return 0;

}
WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 6

Exercise 3

Content

Inputs: 1 integer for today's weekday and future number

Outputs: Show today's day and future day

Entry conditions: Integer

Exit conditions: Show today's day and future day

#include <iostream>
using namespace std;
int main(){

int dia1,dia2,p;

cout<<"Ingrese el dia de hoy"<<endl;


cout<<"1. Lunes"<<endl;
cout<<"2. Martes"<<endl;
cout<<"3. Miercoles"<<endl;
cout<<"4. Jueves"<<endl;
cout<<"5. Viernes"<<endl;
cout<<"6. Sabado"<<endl;
cout<<"0. Domingo"<<endl;
cin>>dia1;

cout<<"Ingrese el número de días futuros que desea calcular"<<endl;


cin>>dia2;

p = dia1 + dia2;
if (dia1 == 1){
cout<<"Hoy es lunes "<<endl;
}
if (dia1 == 2){
cout<<"Hoy es Martes"<<endl;
}
if (dia1 == 3){
cout<<"Hoy es Miercoles "<<endl;
WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 7

#include <iostream>
}

if (dia1 == 4){
cout<<"Hoy es Jueves "<<endl;
}
if (dia1 == 5){
cout<<"Hoy es Viernes "<<endl;
}
if (dia1 == 6){
cout<<"Hoy es Sabado "<<endl;
}
if (dia1 == 0){
cout<<"Hoy es Domingo"<<endl;
}

p = p % 7;

if (p == 0){
cout<<"El dia futuro es domingo"<<endl;
}
if (p == 1){
cout<<"El dia futuro es lunes"<<endl;
}
if (p == 2){
cout<<"El dia futuro es martes"<<endl;
}
if (p == 3){
cout<<"El dia futuro es miércoles"<<endl;
}
if (p == 4){
cout<<"El dia futuro es jueves"<<endl;
}
if (p == 5){
cout<<"El dia futuro es viernes"<<endl;
}
if (p == 6){
cout<<"El dia futuro es sábado"<<endl;
}

return 0;
}
WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 8

Exercise 4.

Content

Inputs: 3 integers, num1, num2 and num3

Outputs: 3 numbers sorted from smallest to largest

Entry conditions: 3 integers

Exit conditions: num1<=num2<=num3

#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
int num1,num2,num3;

cout<<"Ingrese el valor del primer número entero. "<<endl;


cin>>num1;
cout<<"Ingrese el valor del segundo número entero. "<<endl;
cin>>num2;
cout<<"Ingrese el valor del tercer número entero. "<<endl;
cin>>num3;
// num1,num2,num3
if (num1 < num2 && num2 < num3){
cout<< num1 << ", "<< num2 << ", "<< num3 <<endl;
}
// num1,num3,num2
if (num1 < num3 && num3 < num2){
cout<< num1 <<", "<< num3 << ", "<< num2 <<endl;
}
// num2,num1,num3
if (num2 < num1 && num1 < num3){
cout<< num2 <<", "<< num1 <<", "<< num3 <<endl;
}
// num2,num3,num1
if (num2 < num3 && num3 < num1){
cout<< num2 <<", "<< num3 <<", "<< num1 <<endl;
}
WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 9

#include <iostream>
// num3,num1,num2
if (num3 < num1 && num1 < num2){
cout<< num3 <<", "<< num1 <<", "<< num2 <<endl;
}
// num3,num2,num1
if (num3 < num2 && num2 < num1){
cout<< num3 <<", "<< num2 <<", "<< num1 <<endl;
}
return 0;
}

Exercise 5.

Content

Inputs: Month and year

Outputs: Number of days

Entry conditions: Integer number from 1 to 12

Exit conditions: Show month, year and days

#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
int c,a;
cout << "Menú" << endl;
cout << "Digite el número del mes del cuál desea saber el número de días. "
<<endl;
cin>> c;
cout << "También digite el año. "<<endl;
cin>> a;
WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 10

switch (c) {
case 1:
cout<< " Enero " << "Del año "<< a << " Tiene 31 días. "<< endl;
break;
case 2:
cout<< " Febrero " << "Del año "<< a << " Tiene 28 o 29 días. " << endl;
break;
case 3:
cout<< " Marzo " << "Del año "<< a << " Tiene 31 días. " << endl;
break;
case 4:
cout<< " Abril " << "Del año "<< a << " Tiene 30 días. " << endl;
break;
case 5:
cout<< " Mayo " << "Del año "<< a << " Tiene 31 días. " << endl;
break;
case 6:
cout<< " Junio " << "Del año "<< a << " Tiene 30 días. " << endl;
break;
case 7:
cout<< " Julio " << "Del año "<< a << " Tiene 31 días. " << endl;
break;
case 8:
cout<< " Agosto " << "Del año "<< a << " Tiene 31 días. " << endl;
break;
case 9:
cout<< " Septiembre " << "Del año "<< a << " Tiene 30 días. " << endl;
break;
case 10:
cout<< " Octubre " << "Del año "<< a << " Tiene 31 días. " << endl;
break;
case 11:
cout<< " Noviembre " << "Del año " << a << " Tiene 30 días. " << endl;
break;
case 12:
cout<< " Diciembre " << "Del año " << a << " Tiene 31 días. "<< endl;
}
return 0;
}
WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 11

Exercise 6

Content

Inputs: 1 , integer type value

Outputs: divisible by 5 and 6, by 5 or 6, by neither 5 nor 6

Entry conditions: integers

Exit conditions: n % 5 == 0 && n % 6 == 0 , n % 5 == 0 && n % 6 != 0 , n % 5 != 0

&& n % 6 == 0 , n % 5 != 0 && n % 6 != 0

#include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
int n;
cout<< “ ingrese un número entero “<<endl;
cin>>n;
if( n % 5 == 0 && n % 6 == 0){
cout<<” el número “ << n << “ es divisible en entre 5 y 6 “<<endl;
}
if (n % 5 == 0 && n % 6 ¡= 0){
cout << “ el número es divisible por 5”<<endl;
}else if (n % 5 ¡= 0 && n % 6 == 0){
cout<<”el número es divisible por 6”<<endl;
}
if(n % 5 ¡= 0 && n % 6 ¡= 0 ){
cout<<” el número no es divisible ni por 5 ni por 6 “<<endl;
}
return 0;
}
WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 12

Exercise 7

Content

Inputs: 6, day,month,year,a,b,c, type integer

Outputs: day of week, type string

Entry conditions: day,month,year > 0,type integer

Exit conditions: c=dia + 13*(mes+1)/5 + a + a/4 + b/4 + 5*b;

#include <iostream>
using namespace std;
int main()
{
int dia,mes,anno,a,b,c;

do
{
cout << "Introduce una fecha valida" << endl;
cout << "Introduce el dia: "; cin >> dia;
WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 13

#include <iostream>
cout << "Introduce el mes: "; cin >> mes;
cout << "Introduce el anno: "; cin >> anno;
}while (anno<1600 || mes>12 || dia>31);
if(mes<=2)
{
mes=mes+12;
anno--;
}
a=anno%100;
b=anno/100;
c=dia + 13*(mes+1)/5 + a + a/4 + b/4 + 5*b;
// c=dia + 13*(mes+1)/5 + a + a/4 + b/4 - 2*b; // (otra posibilidad)
c=c%7;
switch(c)
{
case 0: cout << "Ese dia cae en sabado" << endl; break;
case 1: cout << "Ese dia cae en domingo" << endl; break;
case 2: cout << "Ese dia cae en lunes" << endl; break;
case 3: cout << "Ese dia cae en martes" << endl; break;
case 4: cout << "Ese dia cae en miercoles" << endl; break;
case 5: cout << "Ese dia cae en jueves" << endl; break;
case 6: cout << "Ese dia cae en viernes" << endl; break;
}
return 0;
}
WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 14

Exercise 8

Content

Inputs: 6, r1,r2,x1,x2,y1,y2

Outputs: 3,circle 2 inside 1, circle two overlaps 1, erroneous data

Entry conditions: float type, > =0

Exit conditions: find distance between the centers, compare

#include<iostream>
#include <math.h>
using namespace std;
int main(){
float r1,r2,x1,x2,y1,y2;
double distancia;
//ingresar datos
cout<<"CIRCULO 1"<<endl;
cout<<"Ingrese las cordenadas centrales "<<endl;
cout<<"punto x: "<<endl;
cin>>x1;
cout<< " punto y:" <<endl;
cin>>y1;
cout<<"Ingrese el radio :"<<endl;
WORKSHOP 1 CUT 1 IMPERATIVE PROGRAMMING 15

#include<iostream>
cin>>r1;
cout<<"CIRCULO 2"<<endl;
cout<<"Ingrese las cordenadas centrales "<<endl;
cout<<"punto x: "<<endl;
cin>>x2;
cout<<" punto y:"<<endl;
cin>>y2;
cout<<"Ingrese el radio"<<endl;
cin>>r2;
// hallar distacia entre los dos centros
distancia=(((x2-x1)+(y2-y1)),(1/2));
// comparar
if (distancia<=(r1-r2)){
cout<<"El circulo 2 esta dentro del circulo 1"<<endl;
}
else if(distancia<=(r1+r2)){
cout<<"El circulo 2 se superpone al círculo 1"<<endl;
}else{
cout<<"Datos erroneos"<<endl;
}
return 0;
}

Conclusions

It could be evidenced that the conditional "if" is indispensable for our code in many

problems that arise because this conditional will help us to explain the facts that will

surely occur in the future, it is a prediction of something that will happen yes or yes.

Bibliography

(Hidalgo, 2020) Ejercicio 10. Circunferencias - Manolo Hidalgo

(deividcoptero Programacion, 2019) https://www.youtube.com/watch?v=z5ZPXnS9SQ8

(ALGORITMODETAREA, 2021) https://www.youtube.com/watch?v=NrwLEDlOtHU

(TavCode, 2020) (634) 12. Fórmula Cuadrática Programa en C++ (Dev C++) - YouTube

You might also like