Está en la página 1de 3

#include "stdafx.

h"
#include <iostream>
#include <fstream> //LIBRERIA PARA ABRIR, CREAR Y CERRAR ARCHIVOS
using namespace std;
void Ingresos_Datos();
void Mostrar_Datos();
//VARIABLES Y ESTRUCTURAS GLOBALES
struct ALUMNOS
{
int carnet;
char nombre[40];
int P1;
int P2;
int zona;
int PF;
int EF;
};
int salir;
ALUMNOS estudiante[3];
int main()
{
int opcion;
do
{
cout<<"\tMENU"<<endl;
cout<<"1 =====> Ingreso de Datos"<<endl;
cout<<"2 =====> Mostrar Datos"<<endl;
cout<<"3 =====> Salir"<<endl;
cout<<"Ingrese una opcion: ";
cin>>opcion;
switch (opcion)
{
case 1:
{
Ingresos_Datos();
break;
}
case 2:
{
Mostrar_Datos();
break;
}
case 3:
{
cout<<"Ingrese una letra y enter para salir. . .
"<<endl;
cin>>salir;
break;
}
default:
{
break;
}
}
}
while (opcion != 3);
}
void Ingresos_Datos()
{
for(int i = 0; i < 3; i++) {
cout<<("Ingrese el Carnet: ");
cin>>estudiante[i].carnet;
cin.get();
cout<<("Ingrese el Nombre: ");
cin.getline(estudiante[i].nombre,30);
cout<<"Ingrese la nota del Primer parcial: ";
cin>>estudiante[i].P1;
cout<<"Ingrese la nota del Segundo parcial: ";
cin>>estudiante[i].P2;
cout<<"Ingrese la Zona: ";
cin>>estudiante[i].zona;
cout<<"Ingrese la nota del Proyecto: ";
cin>>estudiante[i].PF;
cout<<"Ingrese la nota del Exame final: ";
cin>>estudiante[i].EF;
cout<<endl<<endl;
}
ofstream guardar; //DECLARACION DEL ARCHIVO
guardar.open("datos.txt",ios::app); //CREACION O APERTURA DEL ARCHIVO
for(int i = 0; i < 3; i++)
{
guardar<<estudiante[i].carnet<<" "<<estudiante[i].nombre<<" "<<e
studiante[i].P1<<" "<<estudiante[i].P2<<" "<<estudiante[i].zona<<" "<<estudiante
[i].PF<<" "<<estudiante[i].EF<<endl;
}
}
void Mostrar_Datos()
{
ifstream leer;//DECLARACION DE UN FICHERO DE LECTURA
leer.open("datos.txt");//ABRO ARCHIVO PARA LECTURA
system("cls");//LIMPIAR PANTALLA
char carnet[20], nombre[20], PP[20], SP[20], zona[20], PROYF[20], EXF[20
];
leer>>carnet; //LECTURA ADELANTADA
cout<<("\t\t ALUMNOS ALMACENADOS\n\n");
while (!leer.eof()) //"eof()" DEVUELVE TRUE SI SE HA ALCANZADOEL FINAL D
EL FICHERO Y FALSO EN CUALQUIER OTRO CASO
{
leer>>nombre>>PP>>SP>>zona>>PROYF>>EXF;
cout<<"CARNET.\t\t"<<"NOMBRE.\t\t"<<"PRIMER PARCIAL.\t\t"<<"SEGU
NDO PARCIAL."<<endl;
cout<<carnet<<"\t\t"<<nombre<<"\t\t\t"<<PP<<"\t\t\t"<<SP<<"\t\t\
t"<<endl;
cout<<"ZONA.\t\t"<<"PROYECTO FINAL.\t"<<"EXAMEN FINAL."<<endl;
cout<<zona<<"\t\t"<<PROYF<<"\t\t\t"<<EXF<<endl;
cout<<endl<<endl<<endl;
leer>>carnet;
}
leer.close();//CIERRO EL FICHERO
system("pause");
}

También podría gustarte