Last active
August 29, 2015 14:23
-
-
Save KaterineM/d5ac67cc7ec75bdf1c97 to your computer and use it in GitHub Desktop.
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
/* | |
Copyright (C) 2015 Katerine Muñoz Tello <[email protected]> | |
This program is free software: you can redistribute it and/or modify | |
it under the terms of the GNU General Public License as published by | |
the Free Software Foundation, either version 3 of the License, or | |
(at your option) any later version. | |
This program is distributed in the hope that it will be useful, | |
but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with this program. If not, see <http://www.gnu.org/licenses/>. | |
*** Nombre: Katerine Muñoz Tello. | |
*** Objetivo: Genere un nuevo archivo, donde concatene dos palabras, la primera palabra se obtiene | |
del primer archivo y debe terminar en vocal, la segunda palabra se obtiene del segundo archivo | |
y debe comenzar en una consonante. Debe generar tantas palabras como pueda, es decir, se generan | |
palabras hasta que se terminan las palabras que terminan en vocal o las que comienzan con consonante. | |
*** SO: Ubuntu 15.04 | |
*** IDE: Sublime text 3. | |
*** Compilador: gcc version 4.9.2 (Ubuntu 4.9.2-10ubuntu13). | |
*/ | |
#include <iostream> | |
#include <string> | |
#include <fstream> | |
#include <stdlib.h> | |
using namespace std; | |
int Largo(string palabra); | |
int Vocal(string palabra, int n); | |
int Consonante(string palabra2); | |
void crearArchivoConcaternar(string palabra, string palabra2); | |
int main(){ | |
string palabra, palabra2; | |
int n; | |
ifstream texto1; | |
ifstream texto2; | |
texto1.open("texto3.txt"); | |
texto2.open("texto4.txt"); | |
if(texto1.fail() && texto2.fail()){ | |
cout << "El archivo no existe."; | |
system("PAUSE"); | |
exit (1); | |
} | |
else{ | |
while(texto1 >> palabra){ | |
n = Largo(palabra); | |
if(Vocal(palabra, n)){ | |
while(texto2 >> palabra2){ | |
if(Consonante(palabra2)){ | |
Concatenar(palabra, palabra2); | |
} | |
} | |
} | |
if(texto2.fail()){ | |
texto2.clear(); | |
texto2.seekg(0, ios::beg); | |
} | |
} | |
} | |
texto1.close(); | |
texto2.close(); | |
return 0; | |
} | |
int Largo(string palabra){ | |
int largo = palabra.length(); | |
return largo; | |
} | |
int Vocal(string palabra, int n){ | |
int es = 0; | |
if(palabra[n-1] == 'a' || palabra[n-1] == 'e' || palabra[n-1] == 'i' || palabra[n-1] == 'o' || palabra[n-1] == 'u'){ | |
es = 1; | |
} | |
return es; | |
} | |
int Consonante(string palabra){ | |
int es = 0; | |
if(palabra[0] != 'a' && palabra[0] != 'e' && palabra[0] != 'i' && palabra[0] != 'o' && palabra[0] != 'u' && palabra[0] != '0' && palabra[0] != '1' && palabra[0] != '3' && palabra[0] != '4' && palabra[0] != '5' && palabra[0] != '6' && palabra[0] != '7' && palabra[0] != '8' && palabra[0] != '9'){ | |
es = 1; | |
} | |
return es; | |
} | |
void crearArchivoConcaternar(string palabra, string palabra2){ | |
fstream newfile; | |
newfile.open("texto_concatenar.txt", ios::app); | |
newfile << palabra << palabra2 << "\t"; | |
newfile.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment