Mar 18, 2011 at 2:03am UTC
Hi, i am having problem with this program, i have to search in an array the name of the person that have a selected id from a cin, if anyone can help me, here is my entire program;is divided in section;
first section(Arreglo.cpp)
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <climits>
#include <string>
#include <cstring>
#include <cctype>
#include <cassert>
#include "Arreglo.h"
void Arreglo::ReadingFile(ifstream &Entrada)
{
string Name, Last, Id, Codigo;
char Letra;
Entrada >> Name >> Last >> Id;
while (!Entrada.eof())
{
Lista[NumberStudents].Name = Name;
Lista[NumberStudents].Last = Last;
Lista[NumberStudents].Id = Id;
for (int i=0 ; i < MAXIMOCURSOS; i++)
Entrada >> Lista[NumberStudents].Notas[i].Codigo >> Lista[NumberStudents].Notas[i].Letra;
NumberStudents++;
Entrada >> Name >> Last >> Id;
}
}
void Arreglo::SalidaOriginal(ofstream &Salida)
{
Salida << "ESTUDIANTE \t ID\t\tCODIGOS DE CURSOS Y NOTAS" << endl;
Salida << "---------- \t --\t\t-------------------------" << endl;
for (int i=0; i < NumberStudents; i++)
{
Salida << Lista[i].Name << " " << Lista[i].Last << "\t"
<< Lista[i].Id;
for (int j = 0 ; j < MAXIMOCURSOS ; j++)
Salida << "\t" << Lista[i].Notas[j].Codigo << " " << Lista[i].Notas[j].Letra;
Salida << endl;
}
Salida << endl;
}
void Arreglo::Sort()
{
Estudiante Temp;
for (int i = 0; i < NumberStudents - 1; i++)
for (int j = i + 1; j < NumberStudents; j++)
if (Lista[i].Id < Lista[j].Id)
{
Temp = Lista[i];
Lista [i] = Lista[j];
Lista [j] = Temp;
}
}
void Arreglo::Search()
{
int target;
string Id;
cout<<"Escriba el ID (000-00-0000) del estudiante para la busqueda ";
cin>>target;
for (int i=0; i < NumberStudents; i++)
Lista[i].Id= Id;
if(target == Id)
{
cout<<"Nombre:"<<Lista[i].Name<<endl;
}
else
{
cout<<"intente de Nuevo"<<endl;
}
}
second section this is Arreglo.h
#ifndef ARREGLO
#define ARREGLO
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <climits>
#include <string>
#include <cstring>
#include <cctype>
#include <cassert>
using namespace std;
const int MAXIMOESTUDIANTES = 30;
const int MAXIMOCURSOS = 6;
struct Descripcion
{
string Codigo;
char Letra;
};
typedef Descripcion Detalle;
struct Student
{
string Name;
string Last;
string Id;
Detalle Notas [MAXIMOCURSOS];
};
typedef Student Estudiante;
class Arreglo
{
public:
Arreglo();
void ReadingFile(ifstream &);
void SalidaOriginal(ofstream &);
void Sort();
void Search();
void Count(ofstream&);
// Otrs Metodos
private:
Estudiante Lista[MAXIMOESTUDIANTES];
int NumberStudents;
};
inline Arreglo::Arreglo()
{
NumberStudents = 0;
}
#endif
third section Menu.cpp
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <climits>
#include <string>
#include <cstring>
#include <cctype>
#include <cassert>
#include "Arreglo.h"
#include "Arreglo.cpp"
using namespace std;
ifstream Entrada;
ofstream Salida;
void Opening (ifstream &, ofstream &);
void Closing(ifstream &, ofstream &);
void Menu(void);
void Closing(ifstream &Entrada, ofstream &Salida)
{
Entrada.close();
Salida.close();
}
void Opening(ifstream &Entrada, ofstream &Salida)
{
Entrada.open ("Asig3.txt");
Salida.open ("aSig3.txt");
}
void Menu()
{
Arreglo funcion;
int Choice;
do
{
cout << "MENU DE OPERACIONES" << endl << endl;
cout << "1: Abre los Archivos de Entrada y Salida"<< endl;
cout << "2: Lee el Archvio de Entrada" << endl;
cout << "3: Imprimir arreglo original"<<endl;
cout << "4: Ordenar por Id"<<endl;
// cout << "5: Conteo de las Notas"<<endl;
cout<< "6: Busqueda del Estudiante"<<endl;
cout << "10: Termina la Ejecucion del Programa" << endl << endl << endl;
cout << "Make your Choice: ";
cin >> Choice;
switch (Choice)
{
case 1://LLamada a Funcion de Apertura de Archivos
Opening (Entrada, Salida);
break;
case 2://Llamada a Funcion de Lectura en Circulos
funcion.ReadingFile (Entrada);
break;
case 3://imprimir arreglo
funcion.SalidaOriginal (Salida);
break;
case 4://ordenar por edad
funcion.Sort ();
break;
// case 5://conteo de notas
// funcion.Count(Salida);
// break;
case 6://search
funcion.Search();
break;
case 10://Llamada de cierre de archivos
Closing( Entrada, Salida);
cout << "Good Bye..."<<endl;
default:;
}
} while (Choice != 10);
}
and last section asig3.cpp
#include <fstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <climits>
#include <string>
#include <cstring>
#include <cctype>
#include <cassert>
#include "Menu.cpp"
using namespace std;
void Menu(void);
int main ()
{
Menu();
}
and the txt file
Cesar Perez 333-33-3333 MATE3171 A ESPA3171 B COMP3010 A HUMA3010 C HIST3456 B QUIM1234 C
Jose Aviles 222-22-2222 MATE1234 C ESPA1234 C BIOL3015 B EDFI1234 A QUIM3232 C EDFI4321 C
Luis Rivera 111-11-1111 COMP3010 C BIOL3015 C MATE3171 C QUIM1234 C ESPA1234 B EDFI1234 C
Lucas Velez 444-44-4444 MATE1234 B ESPA1234 B BIOL3015 B HUMA3010 C HIST3456 C QUIM1234 C
kathy Torres 666-66-6666 ESPA1000 A MATE3171 C COMP3010 C ESPA3171 C QUIM1234 C EDFI4321 C
please help mee! thanks!