template <typename T1, typename T2>
class Search {
public:
void setRegisters(Register<T1,T2> reg[],int n);
int getNumElems(){return _n;}
T1 getInfo(int i){return _reg[i].info;}
T2 getKey(int i){return _reg[i].key;}
int lineal(T2 key);
int binary(T2 key) {_key = key; return bs(0,_n-1);}
friend ostream & operator << <>(ostream &, Search<T1,T2> &);
private:
/*Hacer en clase*/
//Implementar el algoritmo de busqueda binaria
int bs(int inf, int sup);
private:
Register<T1,T2> *_reg;
int _n;
int _key;
};
---------------------------------------------------------------------------------------------------------------
/*Práctia 24 de Abril, los archivos de pueden descargar de la carpeta de Colas*/
template <typename T>
class Queue: public AbstQueue <T> {
protected:
Node<T> * front;
Node<T> * rear;
int nNodes;
public:
Queue();
~Queue();
bool isEmpty(){return front == 0;}
/*Hacer en clase*/
bool enQueue(T);
bool deQueue(T &);
int getNumElems(){return nNodes;}
Node<T> * getFront(){return front;}
Node<T> * getRear(){return rear;}
friend ostream & operator << <>(ostream &, Queue <T> &);
};
/****************************************************************************/
/*Práctia 19 de Abril, los archivos se pueden descargar de la carpeta Pilas*/
template <typename T>
class Stack: public AbstStack <T> {
protected:
Node<T> * top;
int nnodes;
public:
Stack();
~Stack();
bool isEmpty(){return top == 0;}
/*Hacer en clase*/
bool push(T);
bool pop(T&);
int getNumElems(){return nnodes;}
T& getTop(){return top -> info;}
bool setTop(T info);
friend ostream & operator << <>(ostream &, Stack <T> &);
};
/*Práctica para el 12 de Abril */
/*Descargar los archivos en la carpeta Listas en el repositorio*/
template <typename T>
class Conjunto : public SLList<T> {
private:
//int card; //no es necesario, por qué ?
public:
Conjunto();
bool agregaElem(T);
bool pertenece(T);
bool getCard(){return SLList<T>::nnodes;}
/*Hacer en clase*/
template<typename U>
friend Conjunto<U> & Union(Conjunto<U> &, Conjunto<U> &);
// /* Hacer de Tarea*/
// template<typename U>
// friend Conjunto<U> & Iterseccion(Conjunto<U> &, Conjunto<U> &);
// template<typename U>
// friend Conjunto<U> & Diferencia(Conjunto<U> &, Conjunto<U> &);
// template<typename U>
// friend Conjunto<U> & DSimetrica(Conjunto<U> &, Conjunto<U> &);
};
/*****************************************************/
/*Práctica para 13 y 15 de Marzo 2012*/
/*Implementar los métodos indicados*/
/*Los archivos se pueden bajar desde el repositorio */
/*en la carpeta POO/practica13Feb*/
class Matriz
{
protected:
double ** elems;
int n,m;
public:
Matriz(int, int);
// ~Matriz(void); Implementar en clase
double& operator () (int,int);
friend Matriz& operator + (Matriz&, Matriz&); // Implementar en clase
friend Matriz& operator * ( Matriz&,Matriz&); // Implementar
friend Matriz& operator - ( Matriz&,Matriz&); // Implementar
int getNReng(){return n;}
int getNCol(){return m;}
Matriz& trans (void); // Transpuesta,implementar en clase
double Traza (void); // Traza, implementar en clase
friend ostream & operator << (ostream & , Matriz &); };
class EqsLns: public Matriz {
private: int nEqs;
double *solucion;
private:
//Terminar en clase
void Generate();
public:
//Implementar en clase
EqsLns(int n);
~EqsLns();
void Solve();
//Hacer en clase
friend ostream & operator << (ostream & , EqsLns &);
};
/*********************************************************************/ /* Practica Jueves 8 de Marzo
Funciones amigas y sobrecarga de operadores
Descargar de la carpeta POO/practica8Feb
*/
class Punto2D { private: float x,y; public: Punto2D(){} Punto2D(float,float); float getX(){return x;} float getY(){return y;} float distancia(Punto2D &); friend Punto2D operator +(const Punto2D &, const Punto2D &); //Explicar friend ostream &operator << (ostream& Out, const Punto2D &); //Hacer en clase //friend distancia(const Punto2D &, const Punto2D &); //friend Punto2D operator -(const Punto2D &, const Punto2D &); //void operator++(); };
/***********************************************************/
Práctica Viernes 2 de Marzo.
Implementar los métodos de la siguiente clase de Conjunto.
Descargar los archivos del repositorio en la carpeta POO
#ifndef CONJUNTO_H
#define CONJUNTO_H
class Conjunto{
public:
Conjunto(); //Constructor por defecto, el conjunto no tiene elems
Conjunto(int n); //Constructor, el construstor tendra a lo mas n elems
~Conjunto(){delete [] elems;}; //Destructor
bool AgregaElem(int);
void Imprime();
int GetCard(){return card;}
Conjunto * Union(Conjunto *);
//hacer en clase
Conjunto(int n, unsigned int seed); //Construye un conjunto con aleatorios
Conjunto * Interseccion( Conjunto *);
Conjunto * Diferencia( Conjunto *);
Conjunto * DifSimetrica(Conjunto *);
private:
int GetElem(int i){return elems[i];}
bool resize(int n);
bool Pertenece(int x);
int max(int n, int m);
private:
int *elems;
int card;
int n;
};
#endif
/*******************************************************************/
/********************************************************
* Curso de programacion II
* Daniel Cervantes
* Hector Barron
*
* Practica para el 21 de Febrero, operaciones con conjuntos de enteros
*
*
**********************************************************/
#include<iostream>
#include<time.h>
#include<stdlib.h>
using namespace std;
//Prototipo de funciones
void Inicializa(int Conj[],int n);
void Random(int Conj[],int n);
bool Pertenece(int x, int Conj[],int n);
void Imprime(int Conj[],int n );
//Hacer en clase:
void Union(int Conj1[], int n, int Conj2[], int m, int Conj3[]);
void Interseccion(int Conj1[], int n, int Conj2[], int m, int Conj3[]);
//A\B
void Resta(int Conj1[], int n, int Conj2[], int m, int Conj3[]);
//A\B Union B\A
void DifSimetrica(int Conj1[], int n, int Conj2[], int m, int Conj3[]);
int main(){
const int n = 10;
const int m = 10;
int x = 1;
int Conjunto[n];
Random(Conjunto,n);
Imprime(Conjunto,n);
if(Pertenece(x,Conjunto,n))
cout << x << " pertence al conjunto" << endl;
}
//Defincion de funciones
void Inicializa(int Conj[],int n){
for(int i=0; i < n; i++)
Conj[i]= 0;
}
void Random(int Conj[],int n){
srand(time(0));
for(int i=0; i < n; i++)
Conj[i]=rand()%10;
}
void Imprime(int Conj[], int n){
cout << "{";
for(int i=0; i < n-1; i++)
cout << Conj[i] << ", ";
cout << Conj[n-1] << "}\n";
}
bool Pertenece(int x, int Conj[], int n){
for(int i=0; i < n; i++)
if(x == Conj[i])
return true;
return false;
}