SlideShare una empresa de Scribd logo
1 de 3
/*A) Una función de nombre crear que es llamada desde main crea el archivo
recibido como
agumento mediante un puntero a un array de caracteres. Esta función retorna
true en caso de que se pueda crear exitosamente el archivo o false en caso
contrario. El retorno ( true o false) se mostrará con un cartél desde
main indicando el Exito o Fracaso al crear el archivo ( true / false
respectivamente)

B)Una función de nombre menú generará el siguiente menú:

1)   Crear el Archivo idicando nombre.
2)   Mostrar el contenido del archivo
3)   Agregar texto al archivo.
4)   Borrar fichero.
5)   Salir

La función menú no recibe arguemnto y retorna solamente 1,2 ,3 o S.
Cualquier otra tecla será ignorada y se mostrará un cartel con el texto:
"Opción no valida, intente nuevamete".

Para el caso del punto 1 llamará a la función ya explicada de nombre crear del
punto A

C)La función invocada en el punto 2 permitirá mostrar el contenido del
archivo por pantalla, esta recibirá como arguemento un puntero.-

D)La función del punto 3 recibirá también un puntero al archivo
y agregará el texto ingresado por teclado al final del archivos.*/
//////////////////////////////////////////
#include<iostream>
#include<fstream>
using namespace std;
char menu(void);
bool crear (char *puntero);
void mostrar(char *puntero);
void agregar(char *puntero);
///////////////////////////////////////////
int main()
{
    system("title EL INGRESO DEL NOMBRE DEL ARCHIVO DEBERA SER ASI: miarchivo .
extension ");
    char select,vec[16];
    char *p;
    bool a=false;
    p=&vec[0];
    do
    {
    select=menu();
    switch(select)
           {
             case '1':
                  {
                       system("cls");
                       cin.get();
                       cout<<endl<<"Ingrese nombre del archivo: ";
                       cin.getline(vec,16);
                       a=crear (p);
                       if(a==true)
                       cout<<endl<<"El fichero se ha creado exitosamente";
                       else cout<<endl<<"Fichero no creado: verifique si el
fichero ya existe";
                       cin.get();
                       }
                  break;
case '2':
                 {
                     system("cls");
                     cin.get();
                      cout<<"Ingrese el nombre del archivo a leer: ";
                      cin.getline(vec,16);
                   mostrar(p);
                   }
                   break;
             case '3':
                   {
                       system("cls");
                       cin.get();
                        cout<<"Ingrese el nombre del   archivo a escribir: ";
                        cin.getline(vec,16);
                   agregar(p);
                   }
                   break;
             case '4':
                   {
                        system("cls");
                        cin.get();
                        cout<<"Ingrese el nombre del   archivo a eliminar: ";
                        cin.getline(vec,16);
                        remove(p);
                        }
                   break;
                   }
    }while(select!='5');
    return(0);
    }
////////////////////////////////////////
char menu(void)
{
char sel;
do
{
      system("cls");
      printf("En cada caso se debe cargar el nombre    correcto del archivo seguido
del punto y su extension tenga cuidado con el uso      de letras en mayuscula y/o
minuscula n ");
cout<<endl<<endl<<"1) Crear el archivo";
cout<<endl<<"2) Mostrar el contenido del archivo";
cout<<endl<<"3) Agregar texto al archivo";
cout<<endl<<"4) Borrar archivo";
cout<<endl<<"5) Salir"<<endl<<endl;
cin.get(sel);
}while(sel!='1'&& sel!='2'&& sel!='3'&& sel!='4'&&     sel!='5' );
      return(sel);
      }
//////////////////////////////////////////
bool crear (char *puntero)
{
      char cadena[16];
      system("cls");
      for(int i=0;i<16;i++)
      cadena[i]=*(puntero+i);
ifstream fich(cadena);
if( !fich.good())
      {
    ofstream fich(cadena);
    fich.close();
    if(fich.good())
    {
fich.close();
    return(true);
     }
     }
     else
     {
     fich.close();
     return(false);
}
}
////////////////////////////////////////////
void mostrar(char *puntero)
{
       char cadena[128];
       system("cls");
       ifstream fich(puntero);
if( fich.good())
       {
     ifstream fich(puntero);
     while(!fich.eof())
     {
     fich.getline(cadena,128);
     cout << cadena << endl;
     }
     fich.close();
     }
else cout<<endl<<"El archivo no existe o esta danado";
   cout<<'n'<<'n';
     system("pause");
}
//////////////////////////////////////////
void agregar(char *puntero)
{
  char    resultado[300];
  ifstream fich(puntero);
if(fich.good())
       {
     cout<<endl<<"Ingrese texto: ";
       cin.getline(resultado,300);
ofstream outfile;
                          outfile.open (puntero, ios_base::app);
                          outfile<<resultado<<endl;
                          outfile.close();
       }
else
  cout<<endl<<"El archivo no existe o se encuentra danado";
  cout<<'n'<<'n';
  system("pause");
     }
/////////////////////////////////////////

Más contenido relacionado

Último

LA OVEJITA QUE VINO A CENAR CUENTO INFANTIL.pdf
LA OVEJITA QUE VINO A CENAR CUENTO INFANTIL.pdfLA OVEJITA QUE VINO A CENAR CUENTO INFANTIL.pdf
LA OVEJITA QUE VINO A CENAR CUENTO INFANTIL.pdfNataliaMalky1
 
Mapa Mental de estrategias de articulación de las areas curriculares.pdf
Mapa Mental de estrategias de articulación de las areas curriculares.pdfMapa Mental de estrategias de articulación de las areas curriculares.pdf
Mapa Mental de estrategias de articulación de las areas curriculares.pdfvictorbeltuce
 
periodico mural y sus partes y caracteristicas
periodico mural y sus partes y caracteristicasperiodico mural y sus partes y caracteristicas
periodico mural y sus partes y caracteristicas123yudy
 
ÉTICA, NATURALEZA Y SOCIEDADES_3RO_3ER TRIMESTRE.pdf
ÉTICA, NATURALEZA Y SOCIEDADES_3RO_3ER TRIMESTRE.pdfÉTICA, NATURALEZA Y SOCIEDADES_3RO_3ER TRIMESTRE.pdf
ÉTICA, NATURALEZA Y SOCIEDADES_3RO_3ER TRIMESTRE.pdfluisantoniocruzcorte1
 
SISTEMA INMUNE FISIOLOGIA MEDICA UNSL 2024
SISTEMA INMUNE FISIOLOGIA MEDICA UNSL 2024SISTEMA INMUNE FISIOLOGIA MEDICA UNSL 2024
SISTEMA INMUNE FISIOLOGIA MEDICA UNSL 2024gharce
 
c3.hu3.p1.p2.El ser humano y el sentido de su existencia.pptx
c3.hu3.p1.p2.El ser humano y el sentido de su existencia.pptxc3.hu3.p1.p2.El ser humano y el sentido de su existencia.pptx
c3.hu3.p1.p2.El ser humano y el sentido de su existencia.pptxMartín Ramírez
 
PPT GESTIÓN ESCOLAR 2024 Comités y Compromisos.pptx
PPT GESTIÓN ESCOLAR 2024 Comités y Compromisos.pptxPPT GESTIÓN ESCOLAR 2024 Comités y Compromisos.pptx
PPT GESTIÓN ESCOLAR 2024 Comités y Compromisos.pptxOscarEduardoSanchezC
 
FICHA DE MONITOREO Y ACOMPAÑAMIENTO 2024 MINEDU
FICHA DE MONITOREO Y ACOMPAÑAMIENTO  2024 MINEDUFICHA DE MONITOREO Y ACOMPAÑAMIENTO  2024 MINEDU
FICHA DE MONITOREO Y ACOMPAÑAMIENTO 2024 MINEDUgustavorojas179704
 
Fundamentos y Principios de Psicopedagogía..pdf
Fundamentos y Principios de Psicopedagogía..pdfFundamentos y Principios de Psicopedagogía..pdf
Fundamentos y Principios de Psicopedagogía..pdfsamyarrocha1
 
DECÁGOLO DEL GENERAL ELOY ALFARO DELGADO
DECÁGOLO DEL GENERAL ELOY ALFARO DELGADODECÁGOLO DEL GENERAL ELOY ALFARO DELGADO
DECÁGOLO DEL GENERAL ELOY ALFARO DELGADOJosé Luis Palma
 
Fisiologia.Articular. 3 Kapandji.6a.Ed.pdf
Fisiologia.Articular. 3 Kapandji.6a.Ed.pdfFisiologia.Articular. 3 Kapandji.6a.Ed.pdf
Fisiologia.Articular. 3 Kapandji.6a.Ed.pdfcoloncopias5
 
TRIPTICO-SISTEMA-MUSCULAR. PARA NIÑOS DE PRIMARIA
TRIPTICO-SISTEMA-MUSCULAR. PARA NIÑOS DE PRIMARIATRIPTICO-SISTEMA-MUSCULAR. PARA NIÑOS DE PRIMARIA
TRIPTICO-SISTEMA-MUSCULAR. PARA NIÑOS DE PRIMARIAAbelardoVelaAlbrecht1
 
TEST DE RAVEN es un test conocido para la personalidad.pdf
TEST DE RAVEN es un test conocido para la personalidad.pdfTEST DE RAVEN es un test conocido para la personalidad.pdf
TEST DE RAVEN es un test conocido para la personalidad.pdfDannyTola1
 
Introducción:Los objetivos de Desarrollo Sostenible
Introducción:Los objetivos de Desarrollo SostenibleIntroducción:Los objetivos de Desarrollo Sostenible
Introducción:Los objetivos de Desarrollo SostenibleJonathanCovena1
 
PPT_Formación integral y educación CRESE (1).pdf
PPT_Formación integral y educación CRESE (1).pdfPPT_Formación integral y educación CRESE (1).pdf
PPT_Formación integral y educación CRESE (1).pdfEDILIAGAMBOA
 
LA ECUACIÓN DEL NÚMERO PI EN LOS JUEGOS OLÍMPICOS DE PARÍS.pdf
LA ECUACIÓN DEL NÚMERO PI EN LOS JUEGOS OLÍMPICOS DE PARÍS.pdfLA ECUACIÓN DEL NÚMERO PI EN LOS JUEGOS OLÍMPICOS DE PARÍS.pdf
LA ECUACIÓN DEL NÚMERO PI EN LOS JUEGOS OLÍMPICOS DE PARÍS.pdfJAVIER SOLIS NOYOLA
 

Último (20)

LA OVEJITA QUE VINO A CENAR CUENTO INFANTIL.pdf
LA OVEJITA QUE VINO A CENAR CUENTO INFANTIL.pdfLA OVEJITA QUE VINO A CENAR CUENTO INFANTIL.pdf
LA OVEJITA QUE VINO A CENAR CUENTO INFANTIL.pdf
 
Mapa Mental de estrategias de articulación de las areas curriculares.pdf
Mapa Mental de estrategias de articulación de las areas curriculares.pdfMapa Mental de estrategias de articulación de las areas curriculares.pdf
Mapa Mental de estrategias de articulación de las areas curriculares.pdf
 
periodico mural y sus partes y caracteristicas
periodico mural y sus partes y caracteristicasperiodico mural y sus partes y caracteristicas
periodico mural y sus partes y caracteristicas
 
ÉTICA, NATURALEZA Y SOCIEDADES_3RO_3ER TRIMESTRE.pdf
ÉTICA, NATURALEZA Y SOCIEDADES_3RO_3ER TRIMESTRE.pdfÉTICA, NATURALEZA Y SOCIEDADES_3RO_3ER TRIMESTRE.pdf
ÉTICA, NATURALEZA Y SOCIEDADES_3RO_3ER TRIMESTRE.pdf
 
SISTEMA INMUNE FISIOLOGIA MEDICA UNSL 2024
SISTEMA INMUNE FISIOLOGIA MEDICA UNSL 2024SISTEMA INMUNE FISIOLOGIA MEDICA UNSL 2024
SISTEMA INMUNE FISIOLOGIA MEDICA UNSL 2024
 
TL/CNL – 2.ª FASE .
TL/CNL – 2.ª FASE                       .TL/CNL – 2.ª FASE                       .
TL/CNL – 2.ª FASE .
 
c3.hu3.p1.p2.El ser humano y el sentido de su existencia.pptx
c3.hu3.p1.p2.El ser humano y el sentido de su existencia.pptxc3.hu3.p1.p2.El ser humano y el sentido de su existencia.pptx
c3.hu3.p1.p2.El ser humano y el sentido de su existencia.pptx
 
PPT GESTIÓN ESCOLAR 2024 Comités y Compromisos.pptx
PPT GESTIÓN ESCOLAR 2024 Comités y Compromisos.pptxPPT GESTIÓN ESCOLAR 2024 Comités y Compromisos.pptx
PPT GESTIÓN ESCOLAR 2024 Comités y Compromisos.pptx
 
FICHA DE MONITOREO Y ACOMPAÑAMIENTO 2024 MINEDU
FICHA DE MONITOREO Y ACOMPAÑAMIENTO  2024 MINEDUFICHA DE MONITOREO Y ACOMPAÑAMIENTO  2024 MINEDU
FICHA DE MONITOREO Y ACOMPAÑAMIENTO 2024 MINEDU
 
VISITA À PROTEÇÃO CIVIL _
VISITA À PROTEÇÃO CIVIL                  _VISITA À PROTEÇÃO CIVIL                  _
VISITA À PROTEÇÃO CIVIL _
 
Fundamentos y Principios de Psicopedagogía..pdf
Fundamentos y Principios de Psicopedagogía..pdfFundamentos y Principios de Psicopedagogía..pdf
Fundamentos y Principios de Psicopedagogía..pdf
 
DECÁGOLO DEL GENERAL ELOY ALFARO DELGADO
DECÁGOLO DEL GENERAL ELOY ALFARO DELGADODECÁGOLO DEL GENERAL ELOY ALFARO DELGADO
DECÁGOLO DEL GENERAL ELOY ALFARO DELGADO
 
Fisiologia.Articular. 3 Kapandji.6a.Ed.pdf
Fisiologia.Articular. 3 Kapandji.6a.Ed.pdfFisiologia.Articular. 3 Kapandji.6a.Ed.pdf
Fisiologia.Articular. 3 Kapandji.6a.Ed.pdf
 
TRIPTICO-SISTEMA-MUSCULAR. PARA NIÑOS DE PRIMARIA
TRIPTICO-SISTEMA-MUSCULAR. PARA NIÑOS DE PRIMARIATRIPTICO-SISTEMA-MUSCULAR. PARA NIÑOS DE PRIMARIA
TRIPTICO-SISTEMA-MUSCULAR. PARA NIÑOS DE PRIMARIA
 
TEST DE RAVEN es un test conocido para la personalidad.pdf
TEST DE RAVEN es un test conocido para la personalidad.pdfTEST DE RAVEN es un test conocido para la personalidad.pdf
TEST DE RAVEN es un test conocido para la personalidad.pdf
 
Tema 7.- E-COMMERCE SISTEMAS DE INFORMACION.pdf
Tema 7.- E-COMMERCE SISTEMAS DE INFORMACION.pdfTema 7.- E-COMMERCE SISTEMAS DE INFORMACION.pdf
Tema 7.- E-COMMERCE SISTEMAS DE INFORMACION.pdf
 
Introducción:Los objetivos de Desarrollo Sostenible
Introducción:Los objetivos de Desarrollo SostenibleIntroducción:Los objetivos de Desarrollo Sostenible
Introducción:Los objetivos de Desarrollo Sostenible
 
PPT_Formación integral y educación CRESE (1).pdf
PPT_Formación integral y educación CRESE (1).pdfPPT_Formación integral y educación CRESE (1).pdf
PPT_Formación integral y educación CRESE (1).pdf
 
LA ECUACIÓN DEL NÚMERO PI EN LOS JUEGOS OLÍMPICOS DE PARÍS.pdf
LA ECUACIÓN DEL NÚMERO PI EN LOS JUEGOS OLÍMPICOS DE PARÍS.pdfLA ECUACIÓN DEL NÚMERO PI EN LOS JUEGOS OLÍMPICOS DE PARÍS.pdf
LA ECUACIÓN DEL NÚMERO PI EN LOS JUEGOS OLÍMPICOS DE PARÍS.pdf
 
DIA INTERNACIONAL DAS FLORESTAS .
DIA INTERNACIONAL DAS FLORESTAS         .DIA INTERNACIONAL DAS FLORESTAS         .
DIA INTERNACIONAL DAS FLORESTAS .
 

Destacado

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Destacado (20)

AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 

Manejo de-ficheros-C++

  • 1. /*A) Una función de nombre crear que es llamada desde main crea el archivo recibido como agumento mediante un puntero a un array de caracteres. Esta función retorna true en caso de que se pueda crear exitosamente el archivo o false en caso contrario. El retorno ( true o false) se mostrará con un cartél desde main indicando el Exito o Fracaso al crear el archivo ( true / false respectivamente) B)Una función de nombre menú generará el siguiente menú: 1) Crear el Archivo idicando nombre. 2) Mostrar el contenido del archivo 3) Agregar texto al archivo. 4) Borrar fichero. 5) Salir La función menú no recibe arguemnto y retorna solamente 1,2 ,3 o S. Cualquier otra tecla será ignorada y se mostrará un cartel con el texto: "Opción no valida, intente nuevamete". Para el caso del punto 1 llamará a la función ya explicada de nombre crear del punto A C)La función invocada en el punto 2 permitirá mostrar el contenido del archivo por pantalla, esta recibirá como arguemento un puntero.- D)La función del punto 3 recibirá también un puntero al archivo y agregará el texto ingresado por teclado al final del archivos.*/ ////////////////////////////////////////// #include<iostream> #include<fstream> using namespace std; char menu(void); bool crear (char *puntero); void mostrar(char *puntero); void agregar(char *puntero); /////////////////////////////////////////// int main() { system("title EL INGRESO DEL NOMBRE DEL ARCHIVO DEBERA SER ASI: miarchivo . extension "); char select,vec[16]; char *p; bool a=false; p=&vec[0]; do { select=menu(); switch(select) { case '1': { system("cls"); cin.get(); cout<<endl<<"Ingrese nombre del archivo: "; cin.getline(vec,16); a=crear (p); if(a==true) cout<<endl<<"El fichero se ha creado exitosamente"; else cout<<endl<<"Fichero no creado: verifique si el fichero ya existe"; cin.get(); } break;
  • 2. case '2': { system("cls"); cin.get(); cout<<"Ingrese el nombre del archivo a leer: "; cin.getline(vec,16); mostrar(p); } break; case '3': { system("cls"); cin.get(); cout<<"Ingrese el nombre del archivo a escribir: "; cin.getline(vec,16); agregar(p); } break; case '4': { system("cls"); cin.get(); cout<<"Ingrese el nombre del archivo a eliminar: "; cin.getline(vec,16); remove(p); } break; } }while(select!='5'); return(0); } //////////////////////////////////////// char menu(void) { char sel; do { system("cls"); printf("En cada caso se debe cargar el nombre correcto del archivo seguido del punto y su extension tenga cuidado con el uso de letras en mayuscula y/o minuscula n "); cout<<endl<<endl<<"1) Crear el archivo"; cout<<endl<<"2) Mostrar el contenido del archivo"; cout<<endl<<"3) Agregar texto al archivo"; cout<<endl<<"4) Borrar archivo"; cout<<endl<<"5) Salir"<<endl<<endl; cin.get(sel); }while(sel!='1'&& sel!='2'&& sel!='3'&& sel!='4'&& sel!='5' ); return(sel); } ////////////////////////////////////////// bool crear (char *puntero) { char cadena[16]; system("cls"); for(int i=0;i<16;i++) cadena[i]=*(puntero+i); ifstream fich(cadena); if( !fich.good()) { ofstream fich(cadena); fich.close(); if(fich.good()) {
  • 3. fich.close(); return(true); } } else { fich.close(); return(false); } } //////////////////////////////////////////// void mostrar(char *puntero) { char cadena[128]; system("cls"); ifstream fich(puntero); if( fich.good()) { ifstream fich(puntero); while(!fich.eof()) { fich.getline(cadena,128); cout << cadena << endl; } fich.close(); } else cout<<endl<<"El archivo no existe o esta danado"; cout<<'n'<<'n'; system("pause"); } ////////////////////////////////////////// void agregar(char *puntero) { char resultado[300]; ifstream fich(puntero); if(fich.good()) { cout<<endl<<"Ingrese texto: "; cin.getline(resultado,300); ofstream outfile; outfile.open (puntero, ios_base::app); outfile<<resultado<<endl; outfile.close(); } else cout<<endl<<"El archivo no existe o se encuentra danado"; cout<<'n'<<'n'; system("pause"); } /////////////////////////////////////////