Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- #include <iostream>
- #include <fstream>
- #include <cstdlib>
- using namespace std;
- void numeros(int n){
- if(n==0){
- cout << "Cero" << endl;
- }
- if(n==1){
- cout << "Uno" << endl;
- }
- if(n==2){
- cout << "Dos" << endl;
- }
- if(n==3){
- cout << "Tres" << endl;
- }
- if(n==4){
- cout << "Cuatro" << endl;
- }
- if(n==5){
- cout << "Cinco" << endl;
- }
- if(n==6){
- cout << "Seis" << endl;
- }
- if(n==7){
- cout << "Siete" << endl;
- }
- if(n==8){
- cout << "Ocho" << endl;
- }
- if(n==9){
- cout << "Nueve" << endl;
- }
- }
- int ctoi(char c){
- int aux = 0;
- aux = c-48;
- return aux;
- }
- void reto1(){
- int n,j=0;
- char buffer[500];
- cout << "Introduce cadena de caracteres con numeros: " << endl;
- cin >> buffer;
- while(buffer[j] != '\0'){
- if(isdigit(buffer[j])){
- n=ctoi(buffer[j]);
- numeros(n);
- }
- j++;
- }
- }
- void reto2(){
- fstream f;
- char buffer[500];
- f.open("fichero.txt");
- if(!f){
- cout << "Error al abrir el archivo" << endl;
- }else{
- cout << endl << "El contenido del fichero es: " <<endl;
- while(!f.eof()){
- f >> buffer;
- cout << buffer << endl;
- }
- }
- f.close();
- }
- int reto3(int numeros[3]){
- int max=-1;
- for(int i=0;i<4;i++){
- if(numeros[i]>max){
- max=numeros[i];
- }
- }
- return max;
- }
- int main(){
- int opcion;
- do{
- cout << "1.- Reto 1"<< endl << "2.- Reto 2"<< endl << "3.- Reto 3"<< endl << "4.- Salir" << endl;
- cin >> opcion;
- if(opcion<1) cout << "Error al seleccionar reto" << endl;
- }while(opcion>4);
- switch(opcion){
- case 1:
- reto1();
- break;
- case 2:
- reto2();
- break;
- case 3:
- int n1,n2,n3,n4;
- int num[3];
- int j=0;
- cout << "Introduce 4 numeros separados por un espacio" << endl;
- cin >> n1 >> n2 >> n3 >> n4;
- num[0]=n1; num[1]=n2; num[2]=n3; num[3]=n4;
- cout << "El mayor numero de los 4 introducidos es: " << reto3(num) << endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement