-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1577e8f
Showing
4 changed files
with
319 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
bool menu(int*, int*, int*); | ||
void suma(int, int, int*); | ||
void resta(int, int, int*); | ||
void multiplicacion(int, int, int*); | ||
void division(int, int, int*); | ||
|
||
|
||
int main() | ||
{ | ||
int x, y, z, operacion; | ||
|
||
if(menu(&x, &y, &z)) | ||
cout << "El resultado es: " << x << endl; | ||
else | ||
cout << "Operacion incorrecta" << endl; | ||
system("pause"); | ||
|
||
return 1; | ||
} | ||
|
||
bool menu(int* x, int* y, int* z){ | ||
int operacion; | ||
bool resp = true; | ||
|
||
cout << "Ingrese el primer numero" << endl; | ||
cin >> *y; | ||
|
||
cout << "Ingrese el segundo numero" << endl; | ||
cin >> *z; | ||
|
||
cout << "Ingrese la operacion (Suma = 1, Resta = 2, Multiplicacion = 3, Division = 4)" << endl; | ||
cin >> operacion; | ||
|
||
switch (operacion) | ||
{ | ||
case 1: | ||
suma(*y, *z, x); | ||
break; | ||
case 2: | ||
resta(*y, *z, x); | ||
break; | ||
case 3: | ||
multiplicacion(*y, *z, x); | ||
break; | ||
case 4: | ||
division(*y, *z, x); | ||
break; | ||
default: | ||
resp = false; | ||
break; | ||
} | ||
|
||
return resp; | ||
} | ||
|
||
void suma(int a, int b, int* c){ | ||
*c = a + b; | ||
} | ||
|
||
void resta(int a, int b, int* c){ | ||
*c = a - b; | ||
} | ||
|
||
void multiplicacion(int a, int b, int* c){ | ||
*c = a * b; | ||
} | ||
|
||
void division(int a, int b, int* c){ | ||
if(b == 0) | ||
*c = 0; | ||
else | ||
*c = a / b; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include <iostream> | ||
#include <vector> | ||
#include <limits> | ||
#include <string> | ||
#include <iomanip> | ||
|
||
using namespace std; | ||
|
||
struct Libro { | ||
int id; | ||
string titulo; | ||
string autor; | ||
string editorial; | ||
int anio; | ||
}; | ||
|
||
void imprimir(vector<Libro>); | ||
struct Libro cargarLibro(int); | ||
|
||
int main(){ | ||
vector<Libro> libros; | ||
char cargar = 'S'; | ||
int id = 0; | ||
|
||
while(cargar == 'S'){ | ||
|
||
libros.push_back(cargarLibro(id)); | ||
|
||
cout << "Desea cargar otro libro? [S]/[N]"; | ||
cin >> cargar; | ||
cin.sync(); | ||
|
||
id++; | ||
} | ||
|
||
imprimir(libros); | ||
|
||
system("pause"); | ||
|
||
return 1; | ||
} | ||
|
||
Libro cargarLibro(int id) | ||
{ | ||
Libro libro; | ||
|
||
cout << "Ingrese el nombre del libro " << '\n'; | ||
getline(cin, libro.titulo); | ||
|
||
cout << "Ingrese el autor del libro " << '\n'; | ||
getline(cin, libro.autor); | ||
|
||
cout << "Ingrese la editorial del libro " << '\n'; | ||
getline(cin, libro.editorial); | ||
|
||
|
||
cout << "Ingrese el anio de edicion " << '\n'; | ||
cin >> libro.anio; | ||
|
||
return libro; | ||
} | ||
|
||
void imprimir(vector<Libro> l) | ||
{ | ||
cout << setfill('*') | ||
<< setw(15) << "Nombre del Libro" | ||
<< setw(15) << "Autor" | ||
<< setw(15) << "Editorial" | ||
<< setw(10) << "Anio" | ||
<< endl; | ||
for(int i = 0; i < l.size(); i++){ | ||
|
||
cout << setfill(' ') | ||
<< setw(15) << l[i].titulo | ||
<< setw(15) << l[i].autor | ||
<< setw(15) << l[i].editorial | ||
<< setw(15) << l[i].anio | ||
<< endl; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
struct Node | ||
{ | ||
int val; | ||
Node *next; | ||
}; | ||
|
||
void addStack(Node *&, int); | ||
void popStack(Node *&, int &); | ||
|
||
int main() | ||
{ | ||
int num, opcion = 0; | ||
Node *node = NULL; | ||
//node.next = NULL; | ||
|
||
while (opcion != 3) | ||
{ | ||
cout << "Elija una de las siguientes opciones:" << endl; | ||
cout << "1) Insertar un numero..." << endl; | ||
cout << "2) Mostrar la pila..." << endl; | ||
cout << "3) Salir" << endl; | ||
cin >> opcion; | ||
|
||
if (opcion == 1) | ||
{ | ||
fflush(stdin); | ||
cout << "Ingrese un valor para PILA" << endl; | ||
cin >> num; | ||
addStack(node, num); | ||
system("cls"); | ||
cout << "Operacion exitosa" << endl << endl; | ||
} | ||
else if (opcion == 2) | ||
{ | ||
if (node == NULL){ | ||
system("cls"); | ||
cout << "PILA VACIA" << endl << endl; | ||
} | ||
else | ||
{ | ||
while (node != NULL) | ||
{ | ||
popStack(node, num); | ||
|
||
if(node != NULL){ | ||
cout << num << "->"; | ||
}else{ | ||
cout << num << "." << endl; | ||
} | ||
} | ||
|
||
} | ||
} | ||
} | ||
|
||
cout << "Hasta luego!" << endl; | ||
|
||
return 0; | ||
} | ||
|
||
void addStack(Node *&stack, int n) | ||
{ | ||
Node *newNode = new Node(); | ||
newNode->val = n; | ||
newNode->next = stack; | ||
stack = newNode; | ||
} | ||
|
||
void popStack(Node *&stack, int &n) | ||
{ | ||
Node *aux = stack; | ||
n = aux->val; | ||
stack = aux->next; | ||
delete aux; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Realizar un programa que imprima un menú y le pida al usuario su género (M, F) | ||
// y su altura en centímeros, y mostrar si puede entrar en un juego mecánico que tiene una | ||
// restricción de aultura de 130 cm para mujeres y 140 para hombres. | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
bool validaSexo(char); | ||
bool validaAltura(int); | ||
bool validaIngreso(char, int); | ||
|
||
|
||
int main(){ | ||
char sexo; | ||
int altura; | ||
bool invalido = true; | ||
|
||
while(true){ | ||
while (invalido) | ||
{ | ||
cout << "Ingrese su sexo [(M)asculino, (F)emenino] o S para Salir" << endl; | ||
cin >> sexo; | ||
|
||
if(sexo == 'S'){ | ||
cout << "Adios!" << endl; | ||
return 1; | ||
} | ||
|
||
invalido = validaSexo(sexo); | ||
} | ||
invalido = true; | ||
|
||
|
||
while (invalido) | ||
{ | ||
cout << "Ingrese su altura (en cm.)" << endl; | ||
cin >> altura; | ||
|
||
invalido = validaAltura(altura); | ||
|
||
} | ||
|
||
invalido = true; | ||
|
||
if(validaIngreso(sexo, altura)){ | ||
cout << "Usted puede ingresar" << endl; | ||
}else{ | ||
cout << "Usted no puede ingresar" << endl; | ||
} | ||
} | ||
} | ||
|
||
bool validaSexo(char s){ | ||
|
||
if(s == 'M' || s == 'F'){ | ||
return false; | ||
} | ||
|
||
cout << "Opcion invalida" << endl; | ||
return true; | ||
} | ||
|
||
bool validaAltura(int a){ | ||
|
||
if(a > 0 & a < 230){ | ||
return false; | ||
} | ||
|
||
cout << "La altura pude estar entre 1 y 230 cm." << endl; | ||
return true; | ||
} | ||
|
||
bool validaIngreso(char sexo, int altura){ | ||
if(sexo == 'M' & altura >= 140){ | ||
return true; | ||
} | ||
|
||
if(sexo == 'F' & altura >= 130){ | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|