CENTRO UNIVERSITARIO UAEM
ATLACOMULCO
LICENCIATURA EN
INGENIERÍA EN COMPUTACIÓN
NOMBRE DEL DOCENTE:
INGENIERO.
HÉCTOR CABALLERO HERNÁNDEZ
NOMBRE MATERIA:
AUTÓMATAS Y LENGUAJES FORMALES
NOMBRE DE LA ALUMNA:
HEIVILINA PÉREZ ARIAS
GRUPO:
ICO-19
TURNO:
MATÚTINO
TRABAJO A ENTREGAR:
CODIGO EN C++ DE LAS REGLAS DE
PRODUCCION
FECHA DE ENTREGA:
MAYO DE 2015.
CODIGO EN C++ DE LAS REGLAS DE
PRODUCCION
#include
<iostream>
#include
<string>
#include
<stdlib.h>
#include
<iomanip>
#include
<fstream>
FILE *doc;
using
namespace std;
void
introducirLetra (char *,char *,char *, int);
void
mostrarReglasDeProduccion();
void
lecturaDeArchivo();
const int
num=1000;
struct
Gramaticas{
char regla[100];
char
produccion[100];
char letras[100];
};
Gramaticas
gram[num];
int main(int
argc, char** argv) {
cout<<"\nCENTRO
UNIVERSITARIO UAEM ATLACOMULCO "<<endl;
cout<<"\nAUTOMATAS Y
LENGUAJES FORMALES"<<endl;
cout<<"\nPROGRAMA DE
REGLAS DE PRODUCCION"<<endl;
cout<<"\nELABORADO
POR:"<<endl;
cout<<"---->
HEIVILINA PEREZ ARIAS"<<endl;
cout<<"----> MAYTE
RICARDO CRUZ"<<endl;
lecturaDeArchivo();
mostrarReglasDeProduccion ();
system("pause");
return EXIT_SUCCESS;
}
void
lecturaDeArchivo(){
ifstream
lecturaArchivo("produccion.txt", ios::in);
if(!lecturaArchivo){
cerr<<"No
se pudo abrir el archivo"<<endl;
exit(1);
}
char reglas[100];
char
producciones[100];
char
variables[100];
int i=0;
while(lecturaArchivo>>reglas>>producciones>>variables){
introducirLetra(reglas,producciones,variables,i);
i++;
}
}
void
introducirLetra(char *nx,char *ox,char *dx, int posicion){
if(posicion==-1){
cout<<"Ya
no hay lugar"<<endl;
return;
}
strcpy
(gram[posicion].regla, nx);
strcpy
(gram[posicion].produccion,ox);
strcpy (gram[posicion].letras,
dx);
}
void
mostrarReglasDeProduccion(){
ofstream
salida("salida.txt");
doc=fopen("salida.txt","a+");
cout<<endl;
cout<<setw(10)<<"REGLAS
DE PRODUCCION"<<' '<<endl;
for(int i=0; i<num;i++){
if(strcmp(gram[i].regla,"")!=0){
cout<<setw(10)<<gram[i].regla<<'
'<<endl;
doc=fopen("salida.txt",
"a+");
}
}
}
No hay comentarios:
Publicar un comentario