Está en la página 1de 9

EJERCICIOS A DESARROLLAR

#include <iostream>
#include <fstream>
#include <windows.h>

using namespace std;

int menu(){
int x;
system("cls");
cout<<"---------Bienvenidos------->>"<<endl<<endl;
cout<<"1. Agregar Persona"<<endl;
cout<<"2. Ver Persona"<<endl;
cout<<"3. Salir"<<endl;
cout<<"Opcion ";
cin>> x;
return x;
}

void agregar (ofstream &es){


system("cls");
string Nom;
string Dir;
string Ciu;
string CodP;
string Tel;
string Edad;
es.open("Agenda.txt", ios::out | ios::app);
cout<<"Nombre ";
cin>>Nom;
cout<<"Direccion ";
cin>>Dir;
cout<<"Ciudad ";
cin>>Ciu;
cout<<"Codigo Postal ";
cin>>CodP;
cout<<"Telefono ";
cin>>Tel;
cout<<"Edad ";
cin>>Edad;
es<<Nom<<" "<<Dir<<" "<<Ciu<<" "<<CodP<<" "<<Tel<<" "<<Tel<<Edad<<" ";
es.close();

void verRegistro (ifstream &Lec) {


system("cls");
string nom;
string Dir;
string Ciu;
string CoP;
string Tel;
string Edad;
Lec.open("Agenda.txt", ios::in);
Lec>>nom;
while(!Lec.eof()){
Lec>>Dir;
Lec>>Ciu;
Lec>>CoP;
Lec>>Tel;
Lec>>Edad;
cout<<"Nombre----------: "<<nom<<endl;
cout<<"Direccion-------: "<<Dir<<endl;
cout<<"Ciudad----------: "<<Ciu<<endl;
cout<<"Codigo Postal---: "<<CoP<<endl;
cout<<"Telefono--------: "<<Tel<<endl;
cout<<"Edad------------: "<<Edad<<endl;
cout<<"-----------------------------------"<<endl;
}
Lec.close();
system("Pause");
}

int main(){
ofstream Esc;
ifstream Lec;
int op;
do{
system("cls");
op = menu();
switch(op){
case 1:
agregar(Esc);
break;

case 2:
verRegistro(Lec);

break;

}while (op != 3);


}

(1) Algoritmo de numero creciente


definir n,x,a,b,c como real
Escribir "Escribe 3 numeros"
Para x = 1 Hasta 3 Con Paso 1 Hacer
Leer n
Si x == 1 Entonces
a=n
FinSi
Si x == 2 Entonces
Si a < n Entonces
b=a
a=n
SiNo
b=n
FinSi
FinSi
Si x == 3 Entonces
Si a < n Entonces
c=b
b=a
a=n
SiNo
Si b < n Entonces
c=b
b=n
SiNo
c=n
FinSi
FinSi
FinSi

FinPara
Escribir c
Escribir b
Escribir a
FinAlgoritmo
#2

(2) #include<stdio.h>
(3) #include<stdlib.h>
(4) #include <string.h>
(5)
(6) int main()
(7) {
(8) int n;
(9) printf("Ingrese cantidad de nombres a ingresar: ");
(10) scanf("%d", &n);
(11) char s[n][20],aux[20];
(12)
(13) int i,j;
(14)
(15) float comp;
(16)
(17) for(i=0;i<n;i++)
(18) {
(19) printf("Ingresa un nombre: \n");
(20) scanf("%s", s[i]);
(21) }
(22) system("cls");
(23) for (i=0;i<n;i++)
(24) {
(25) for (j=0;j<n-i; j++)
(26) {
(27) comp = strcmp (s[j], s[j+1]);
(28) if(comp > 0)
(29) {
(30) strcmp (s[j],s[j+1]);
(31) if (comp> 0)
(32) {
(33) strcpy (aux, s[j]);
(34) strcpy (s[j], s[j+1]);
(35) strcpy (s[j+1], aux);
(36) }
(37) }
(38)
(39) }
(40) printf("Los nombres ordenados alfabeticamente son: \n");
(41) for(i=1; i<=n; i++)
(42) {
(43) printf("%d. - %s \n",i,s[i]);
(44) }
(45) system("PAUSE");
(46) return 0;
(47)
(48) }
(49) }

#3

#include<iostream>

using namespace std;

int main(){
int numero;

cout<<"Digite un numero entre 1-3";


cin>> numero;

switch(numero){
case 1: cout<<"Metodo Burbuja: ";
{
int array[8] = {42,57,14,40,96,19, 8,68};
int i,j,aux;

for(i=0;i<8;i++){
for(j=0;j<8;j++){
if(array[j] > array[j+1]){
aux = array[j];
array[j] = array[j+1];
array[j+1] = aux;
}
}
}

cout<<"Numeros de forma Ascendente: \n";


for(i=0;i<8;i++){
cout<<array[i]<<" ";
}

cout<<"\nNumeros de forma Descendente: \n";


for(i=8;i>=0;i--){
cout<<array[i]<<" ";
break;
}
}

case 2: cout<<"Metodo Seleccion: ";

int numeros[8] = {42,57,14,40,96,19, 8,68};


int i,j,aux,min;
for(i=0;i<8;i++){
min = i;
for(j=i+1;j<8;j++){
if(numeros[j] < numeros[min]){
min = j;
}
}
aux = numeros[i];
numeros[i] = numeros[min];
numeros[min] = aux;
}

cout<<"Orden Ascendente: \n";


for(i=0;i<8;i++){
cout<<numeros[i]<<" ";
}

cout<<"\nOrden Descendente: \n";


for(i=8;i>0;i--){
cout<<numeros[i]<<" ";
break;
}

}
system ("pause");
return 0;
}
#include<iostream>

using namespace std;

int main(){
int numeroArreglo[10];
int i = 0 ;
int numeroabuscar = 0;
int bandera = 0;
for(i = 0; i < 10; i++){
cout<<"Ingrese el numero " <<i <<": ";
cin >> numeroArreglo[i];
}
for (i = 0; i < 10; i++){
cout << "Numero "<<i << ": "<< numeroArreglo[i]<<endl;
}
cout<<"\nIngrese numero a buscar: ";
cin>> numeroabuscar;

for(i=0;i<10 && bandera==0;i++){


if(numeroArreglo[i]== numeroabuscar){
bandera = 1;
}
}
if (bandera==0){
cout<<"El elemento no existe";
}else{
cout<<"El elemento fue encontrado";
}
return 0;
}

También podría gustarte