online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
#include "Alumno.h" #include "Arreglo.h" #include "MetOrdena.h" #include<iostream> using namespace std; int main() { Arreglo<Alumno> Escuela; Escuela.Lectura(); /* IntercDirectoIzq<Alumno> Orden; Orden.Ordena(&Escuela); */ Escuela.Escribe(); if (Escuela.RegresaTam() != 0) cout<<"Los datos del primer alumno son:"<<endl; cout<< Escuela.RegresaValor(0); return 0; }
#ifndef ALUMNO_H //add include guards #define ALUMNO_H #include <iostream> //removed using namespace std; class Alumno { private: int Clave; char Nombre[64]; public: Alumno(); Alumno(int, char *); int operator > (Alumno); friend std::istream &operator >> (std::istream &, Alumno &); friend std::ostream &operator << (std::ostream &,const Alumno &); //made the second parameter a reference to const Alumno }; #endif
#include "Alumno.h" #include<stdio.h> #include<cstring> Alumno::Alumno() {} Alumno::Alumno(int Cla, char Nom[]) { Clave= Cla; strcpy(Nombre, Nom); } int Alumno::operator > (Alumno ObjAl) { if (Clave > ObjAl.Clave) return 1; else return 0; } std::istream &operator>>(std::istream &Lee,Alumno &ObjAl) { std::cout<<"\n\nIngrese clave del alumno: "; Lee>>ObjAl.Clave; std::cout<<"\n\nIngrese nombre del alumno: "; Lee>>ObjAl.Nombre; return Lee; } std::ostream &operator << (std::ostream &Escribe,const Alumno &ObjAl)//made the second parameter a reference to const Alumno { Escribe<<"\n\nDatos del alumno\n"; Escribe<<"\nClave: "<<ObjAl.Clave; Escribe<<"\nNombre: "<<ObjAl.Nombre<<"\n"; return Escribe; }
#ifndef METORDENA_H #define METORDENA_H #define MAX 100 template <class T> class Arreglos { //private: public: T Datos[MAX]; int Tam; Arreglos(); int RegresaTam(); T RegresaValor(int); void AsignaValor(int, T); void Intercambia(int, int); void IntercDirectoIzq(); void InsercionDirecta(); void SeleccionDirecta(); void QuickSort(); void Reduce(int, int); void Lectura(); void Escribe(); }; template <class T> Arreglos<T>::Arreglos() { Tam=0; } template <class T> void Arreglos<T>::Intercambia(int Ind1, int Ind2) { T Auxiliar; Auxiliar= Datos[Ind1]; Datos[Ind1]= Datos[Ind2]; Datos[Ind2]= Auxiliar; } template <class T> void Arreglos<T>::IntercDirectoIzq() { int Ind1, Ind2; for (Ind1= 1; Ind1< Tam; Ind1++) for (Ind2= Tam-1; Ind2 >= Ind1; Ind2--) if (Datos[Ind2-1] > Datos[Ind2]) Intercambia(Ind2-1, Ind2); } template <class T> void Arreglos<T>::InsercionDirecta() { int Auxiliar, Indice, IndAux; for (Indice= 1; Indice < Tam; Indice++) { Auxiliar= Datos[Indice]; IndAux= Indice - 1; while ((IndAux >= 0) && (Auxiliar < Datos[IndAux])) { Datos[IndAux+1]= Datos[IndAux]; IndAux--; } Datos[IndAux+1]= Auxiliar; } } template <class T> void Arreglos<T>::SeleccionDirecta() { int Menor, Ind1, Ind2, Ind3; for (Ind1= 0; Ind1 < Tam-1; Ind1++) { Menor= Datos[Ind1]; Ind2= Ind1; for (Ind3= Ind1+1; Ind3 < Tam; Ind3++) if (Datos[Ind3] < Menor) { Menor= Datos[Ind3]; Ind2= Ind3; } Datos[Ind2]= Datos[Ind1]; Datos[Ind1]= Menor; } } template <class T> void Arreglos<T>::QuickSort() { Reduce(0, Tam-1); } template <class T> void Arreglos<T>::Reduce(int Inicio, int Fin) { if ( Tam > 0) { int Izq, Der, Posic, Bandera; Izq= Inicio; Der= Fin; Posic= Inicio; Bandera= 1; while (Bandera) { Bandera= 0; while ((Datos[Posic] <= Datos[Der]) && (Posic != Der)) Der--; if (Posic != Der) { Intercambia(Posic, Der); Posic= Der; while ((Datos[Posic] >= Datos[Izq]) && (Posic != Izq)) Izq++; if (Posic != Izq) { Bandera=1; Intercambia(Posic, Izq); Posic= Izq; } } } if ((Posic-1) > Inicio) Reduce(Inicio, Posic-1); if (Fin > (Posic+1)) Reduce(Posic+1, Fin); } } #endif
#ifndef ARREGLO_H #define ARREGLO_H #include<iostream> #include<stdio.h> #define MAX 100 using namespace std; template <class T> class Arreglo { private: T Datos[MAX]; int Tam; public: Arreglo(); int RegresaTam(); T RegresaValor(int); void AsignaValor(int, T); void Lectura(); void Escribe(); }; template <class T> Arreglo<T>::Arreglo() { Tam= 0; } template <class T> int Arreglo<T>::RegresaTam() { return Tam; } template <class T> T Arreglo<T>::RegresaValor(int Indice) { return Datos[Indice]; } template <class T> void Arreglo<T>::AsignaValor(int Indice, T Valor) { Datos[Indice]= Valor; } template <class T> void Arreglo<T>::Lectura() { int Indice; do { cout<<"\n\n Ingrese total de elementos: "; cin>> Tam; } while (Tam < 1 || Tam > MAX); for (Indice= 0; Indice < Tam; Indice++) { cout<<"\nIngrese el "<<Indice + 1<<" dato: "; cin>> Datos[Indice]; } } template <class T> void Arreglo<T>::Escribe() { int Indice; if (Tam > 0) { cout<<"\n\n"; for (Indice= 0; Indice < Tam; Indice++) cout<< "\t" << Datos[Indice]; cout<<"\n\n"; } else cout<< "\n No hay elementos almacenados."; } #endif

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue