Advertisement
Guest User

retos

a guest
Sep 24th, 2012
315
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.88 KB | None | 0 0
  1. #include<cstdio>
  2. #include <iostream>
  3. #include <fstream>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8. void numeros(int n){
  9.     if(n==0){
  10.         cout << "Cero" << endl;
  11.     }
  12.     if(n==1){
  13.         cout << "Uno" << endl;
  14.     }
  15.     if(n==2){
  16.         cout << "Dos" << endl;
  17.     }
  18.     if(n==3){
  19.         cout << "Tres" << endl;
  20.     }
  21.     if(n==4){
  22.         cout << "Cuatro" << endl;
  23.     }
  24.     if(n==5){
  25.         cout << "Cinco" << endl;
  26.     }
  27.     if(n==6){
  28.         cout << "Seis" << endl;
  29.     }
  30.     if(n==7){
  31.         cout << "Siete" << endl;
  32.     }
  33.     if(n==8){
  34.         cout << "Ocho" << endl;
  35.     }
  36.     if(n==9){
  37.         cout << "Nueve" << endl;
  38.     }
  39.  
  40. }
  41.  
  42. int ctoi(char c){
  43.     int aux = 0;
  44.     aux = c-48;
  45.     return aux;
  46. }
  47.  
  48. void reto1(){
  49.     int n,j=0; 
  50.     char buffer[500];
  51.     cout << "Introduce cadena de caracteres con numeros: " << endl;
  52.     cin >>  buffer;
  53.     while(buffer[j] != '\0'){
  54.         if(isdigit(buffer[j])){
  55.             n=ctoi(buffer[j]);
  56.             numeros(n);
  57.         }
  58.         j++;
  59.     }  
  60. }
  61.  
  62. void reto2(){
  63.     fstream f;
  64.     char buffer[500];
  65.     f.open("fichero.txt");
  66.     if(!f){
  67.         cout << "Error al abrir el archivo" << endl;
  68.     }else{
  69.         cout << endl << "El contenido del fichero es: " <<endl;
  70.         while(!f.eof()){
  71.             f >> buffer;
  72.             cout << buffer << endl;
  73.         }
  74.     }
  75.     f.close();
  76. }
  77.  
  78. int reto3(int numeros[3]){
  79.     int max=-1;
  80.     for(int i=0;i<4;i++){
  81.         if(numeros[i]>max){
  82.             max=numeros[i];
  83.         }
  84.     }
  85.     return max;
  86. }
  87.  
  88. int main(){
  89.     int opcion;
  90.     do{
  91.         cout << "1.- Reto 1"<< endl << "2.- Reto 2"<< endl << "3.- Reto 3"<< endl << "4.- Salir" << endl;
  92.         cin >> opcion;
  93.         if(opcion<1) cout << "Error al seleccionar reto" << endl;
  94.     }while(opcion>4);
  95.  
  96.     switch(opcion){
  97.     case 1:
  98.         reto1();
  99.         break;
  100.     case 2:
  101.         reto2();
  102.         break;
  103.     case 3:
  104.         int n1,n2,n3,n4;
  105.         int num[3];
  106.         int j=0;
  107.         cout << "Introduce 4 numeros separados por un espacio" << endl;
  108.         cin >> n1 >> n2 >> n3 >> n4;
  109.         num[0]=n1; num[1]=n2; num[2]=n3; num[3]=n4;
  110.         cout << "El mayor numero de los 4 introducidos es: " << reto3(num) << endl;
  111.     }  
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement