Você está na página 1de 11

Arquivo: /home/ealves/Dropbox/Estudos/Materias/AEDS 3/tp1 Pgina 1 de 11

/*
* DCElement.h
*
* Created on: 29 de nov de 2016
* Author: elias
*/

#ifndef DCELEMENT_H_
#define DCELEMENT_H_
#include <iostream>
#include <cstdlib>
#include <string>
#include <string.h>

class DCElement {
long identifier;
std::string title;
std::string creator;
std::string subject;
std::string description;
std::string publisher;
std::string contributor;
time_t date;
std::string type;
std::string format;
std::string source;
std::string language;
std::string relation;
std::string coverage;
std::string rights;
/*Aqui entram demais metadados com os possveis pesos ou demais tags de
identificao*/
public:
DCElement();
DCElement(long identifier, std::string title, std::string type,
std::string creator, std::string subject);
virtual ~DCElement();

void teste() {
date = time(NULL);
}

const std::string& getContributor() const;


void setContributor(const std::string& contributor);
const std::string& getCoverage() const;
void setCoverage(const std::string& coverage);
const std::string& getCreator() const;
void setCreator(const std::string& creator);
time_t getDate() const;
void setDate(time_t date);
const std::string& getDescription() const;
void setDescription(const std::string& description);
const std::string& getFormat() const;
void setFormat(const std::string& format);
const long& getIdentifier() const;
void setIdentifier(const long& identifier);
const std::string& getLanguage() const;
void setLanguage(const std::string& language);
const std::string& getPublisher() const;
void setPublisher(const std::string& publisher);
const std::string& getRelation() const;
void setRelation(const std::string& relation);
const std::string& getRights() const;
void setRights(const std::string& rights);
const std::string& getSource() const;
Arquivo: /home/ealves/Dropbox/Estudos/Materias/AEDS 3/tp1 Pgina 2 de 11

void setSource(const std::string& source);


const std::string& getSubject() const;
void setSubject(const std::string& subject);
const std::string& getTitle() const;
void setTitle(const std::string& title);
const std::string& getType() const;
void setType(const std::string& type);
std::string printDateTime();
void createTestElement();
void createElement();
void printElement();
};

#endif /* DCELEMENT_H_ */

/*
* DCElement.cpp
*
* Created on: 29 de nov de 2016
* Author: elias
*/

#include <string>
#include <string.h>
#include <iostream>
#include <time.h>
#include "DCElement.h"

DCElement::DCElement() {
// TODO Auto-generated constructor stub

}
DCElement::DCElement(long identifier, std::string title, std::string type,
std::string creator, std::string subject){
this->identifier = identifier;
this->title = title;
this->type = type;
this->creator = creator;
this->subject = subject;
}//Construtor 1

const std::string& DCElement::getContributor() const {


return contributor;
}

void DCElement::setContributor(const std::string& contributor) {


this->contributor = contributor;
}

const std::string& DCElement::getCoverage() const {


return coverage;
}

void DCElement::setCoverage(const std::string& coverage) {


this->coverage = coverage;
}

const std::string& DCElement::getCreator() const {


return creator;
}

void DCElement::setCreator(const std::string& creator) {


this->creator = creator;
Arquivo: /home/ealves/Dropbox/Estudos/Materias/AEDS 3/tp1 Pgina 3 de 11

time_t DCElement::getDate() const {


return date;
}

void DCElement::setDate(time_t date) {


this->date = date;
}

const std::string& DCElement::getDescription() const {


return description;
}

void DCElement::setDescription(const std::string& description) {


this->description = description;
}

const std::string& DCElement::getFormat() const {


return format;
}

void DCElement::setFormat(const std::string& format) {


this->format = format;
}

const long& DCElement::getIdentifier() const {


return identifier;
}

void DCElement::setIdentifier(const long& identifier) {


this->identifier = identifier;
}

const std::string& DCElement::getLanguage() const {


return language;
}

void DCElement::setLanguage(const std::string& language) {


this->language = language;
}

const std::string& DCElement::getPublisher() const {


return publisher;
}

void DCElement::setPublisher(const std::string& publisher) {


this->publisher = publisher;
}

const std::string& DCElement::getRelation() const {


return relation;
}

void DCElement::setRelation(const std::string& relation) {


this->relation = relation;
}

const std::string& DCElement::getRights() const {


return rights;
}

void DCElement::setRights(const std::string& rights) {


this->rights = rights;
}
Arquivo: /home/ealves/Dropbox/Estudos/Materias/AEDS 3/tp1 Pgina 4 de 11

const std::string& DCElement::getSource() const {


return source;
}

void DCElement::setSource(const std::string& source) {


this->source = source;
}

const std::string& DCElement::getSubject() const {


return subject;
}

void DCElement::setSubject(const std::string& subject) {


this->subject = subject;
}

const std::string& DCElement::getTitle() const {


return title;
}

void DCElement::setTitle(const std::string& title) {


this->title = title;
}

const std::string& DCElement::getType() const {


return type;
}

void DCElement::setType(const std::string& type) {


this->type = type;
}

DCElement::~DCElement() {
// TODO Auto-generated destructor stub
}

std::string DCElement::printDateTime() {
char tempDateString[100];
strftime( tempDateString, sizeof(tempDateString), "%d.%m.%Y - %H:%M:%S",
localtime( &date ) );
return tempDateString;
}

void DCElement::createElement() {
std::cout << "Entre com os dados do Objeto de Aprendizagem" <<
std::endl;
std::cout << "Identificador: ";
std::cin >> this->identifier;
std::cout << "Ttulo: ";
std::cin >> this->title;
std::cout << "Tipo de OA: ";
std::cin >> this->type;
std::cout << "Criador: ";
std::cin >> this->creator;
std::cout << "Assunto: ";
std::cin >> this->subject;
}

void DCElement::createTestElement() {
// Seta a codificao
setlocale(LC_ALL,"Portuguese"); //Para uso de caracteres em utf-8
//Gera um ndice aleatrio
long index;
srand(time(NULL));
index = 1+rand()%(101-1);
//Preenche as informaes
Arquivo: /home/ealves/Dropbox/Estudos/Materias/AEDS 3/tp1 Pgina 5 de 11

this->identifier = index;
this->title = "Um ttulo Qualquer";
this->type = "Um tipo qualquer";
this->creator = "Fulano de tal";
this->subject = "Assuntamento de qq coisa";
std::cout << "Dados " << index << " virtuais inseridos, continuando..." <<
std::endl;
DCElement::printElement();
}

void DCElement::printElement() {
std::cout << "************************************************" <<
std::endl;
std::cout << "Identificador: " << this->identifier << std::endl;
std::cout << "Ttulo: " << this->title << std::endl;
std::cout << "Tipo de OA: " << this->type << std::endl;
std::cout << "Criador: " << this->creator << std::endl;
std::cout << "Assunto: " << this->subject << std::endl;
std::cout << "************************************************" <<
std::endl;
}

/*
* Tree.h
*
* Created on: 24 de nov de 2016
* Author: elias
*/

#ifndef TREE_H_
#define TREE_H_
#include <string>
#include "DCElement.h"

typedef struct Nodo * PointerNodo;

class Tree {
public:
class Nodo {
DCElement lob;
Nodo *pLtef;
Nodo *pRight;
public:
Nodo();
Nodo(DCElement newLob);
virtual ~Nodo();
DCElement& getLob();
void setLob(DCElement& lob);
Nodo*& getRight();
void setRight(Nodo*& pRight);
Nodo*& getLeft();
void setLeft(Nodo*& pLtef);
void setLeftNull();
void setRightNull();
};
private:
Tree::Nodo *pRoot;
Tree::Nodo **pNewNodo;
public:
Tree();
virtual ~Tree();
Tree::Nodo* getRoot();
Tree::Nodo** getNewNodo();
void setRoot(Tree::Nodo*);
Arquivo: /home/ealves/Dropbox/Estudos/Materias/AEDS 3/tp1 Pgina 6 de 11

bool SearchIdentificator(DCElement *pLObject, Tree::Nodo **pNodo);


bool SearchName(std::string nome, Tree::Nodo* pNodo);
void InsertsNodo(DCElement pLObject, Tree::Nodo **pNewNodo);
Tree::Nodo** Predecessor (Tree::Nodo *pNodoQ, Tree::Nodo **pNodoR);
void RemovesNodo(long identifier, Tree::Nodo **pNewNodo);
void ioTraversal(Tree::Nodo *pNodo);
};

#endif /* TREE_H_ */

/*
* DCElement.cpp
*
* Created on: 29 de nov de 2016
* Author: elias
*/

#include <string>
#include <string.h>
#include <iostream>
#include <time.h>
#include "DCElement.h"

DCElement::DCElement() {
// TODO Auto-generated constructor stub

}
DCElement::DCElement(long identifier, std::string title, std::string type,
std::string creator, std::string subject){
this->identifier = identifier;
this->title = title;
this->type = type;
this->creator = creator;
this->subject = subject;
}//Construtor 1

const std::string& DCElement::getContributor() const {


return contributor;
}

void DCElement::setContributor(const std::string& contributor) {


this->contributor = contributor;
}

const std::string& DCElement::getCoverage() const {


return coverage;
}

void DCElement::setCoverage(const std::string& coverage) {


this->coverage = coverage;
}

const std::string& DCElement::getCreator() const {


return creator;
}

void DCElement::setCreator(const std::string& creator) {


this->creator = creator;
}

time_t DCElement::getDate() const {


return date;
}
Arquivo: /home/ealves/Dropbox/Estudos/Materias/AEDS 3/tp1 Pgina 7 de 11

void DCElement::setDate(time_t date) {


this->date = date;
}

const std::string& DCElement::getDescription() const {


return description;
}

void DCElement::setDescription(const std::string& description) {


this->description = description;
}

const std::string& DCElement::getFormat() const {


return format;
}

void DCElement::setFormat(const std::string& format) {


this->format = format;
}

const long& DCElement::getIdentifier() const {


return identifier;
}

void DCElement::setIdentifier(const long& identifier) {


this->identifier = identifier;
}

const std::string& DCElement::getLanguage() const {


return language;
}

void DCElement::setLanguage(const std::string& language) {


this->language = language;
}

const std::string& DCElement::getPublisher() const {


return publisher;
}

void DCElement::setPublisher(const std::string& publisher) {


this->publisher = publisher;
}

const std::string& DCElement::getRelation() const {


return relation;
}

void DCElement::setRelation(const std::string& relation) {


this->relation = relation;
}

const std::string& DCElement::getRights() const {


return rights;
}

void DCElement::setRights(const std::string& rights) {


this->rights = rights;
}

const std::string& DCElement::getSource() const {


return source;
}

void DCElement::setSource(const std::string& source) {


this->source = source;
Arquivo: /home/ealves/Dropbox/Estudos/Materias/AEDS 3/tp1 Pgina 8 de 11

const std::string& DCElement::getSubject() const {


return subject;
}

void DCElement::setSubject(const std::string& subject) {


this->subject = subject;
}

const std::string& DCElement::getTitle() const {


return title;
}

void DCElement::setTitle(const std::string& title) {


this->title = title;
}

const std::string& DCElement::getType() const {


return type;
}

void DCElement::setType(const std::string& type) {


this->type = type;
}

DCElement::~DCElement() {
// TODO Auto-generated destructor stub
}

std::string DCElement::printDateTime() {
char tempDateString[100];
strftime( tempDateString, sizeof(tempDateString), "%d.%m.%Y - %H:%M:%S",
localtime( &date ) );
return tempDateString;
}

void DCElement::createElement() {
std::cout << "Entre com os dados do Objeto de Aprendizagem" <<
std::endl;
std::cout << "Identificador: ";
std::cin >> this->identifier;
std::cout << "Ttulo: ";
std::cin >> this->title;
std::cout << "Tipo de OA: ";
std::cin >> this->type;
std::cout << "Criador: ";
std::cin >> this->creator;
std::cout << "Assunto: ";
std::cin >> this->subject;
}

void DCElement::createTestElement() {
// Seta a codificao
setlocale(LC_ALL,"Portuguese"); //Para uso de caracteres em utf-8
//Gera um ndice aleatrio
long index;
srand(time(NULL));
index = 1+rand()%(101-1);
//Preenche as informaes
this->identifier = index;
this->title = "Um ttulo Qualquer";
this->type = "Um tipo qualquer";
this->creator = "Fulano de tal";
this->subject = "Assuntamento de qq coisa";
std::cout << "Dados " << index << " virtuais inseridos, continuando..." <<
Arquivo: /home/ealves/Dropbox/Estudos/Materias/AEDS 3/tp1 Pgina 9 de 11

std::endl;
DCElement::printElement();
}

void DCElement::printElement() {
std::cout << "************************************************" <<
std::endl;
std::cout << "Identificador: " << this->identifier << std::endl;
std::cout << "Ttulo: " << this->title << std::endl;
std::cout << "Tipo de OA: " << this->type << std::endl;
std::cout << "Criador: " << this->creator << std::endl;
std::cout << "Assunto: " << this->subject << std::endl;
std::cout << "************************************************" <<
std::endl;
}

//============================================================================
// Name : main.cpp
// Author : Elias Alves
// Version : 0.0.1
// Copyright : Apache License Version 2.0
// Description : Sistema de Organizao de Objetos de Aprendizagem
//============================================================================

#include <new>
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <string.h>
#include <cstddef>
#include <libxml2/libxml/tree.h>
#include <libxml2/libxml/parser.h>
#include "DCElement.h"
#include "Tree.h"

using namespace std;

int Menu();

int main(int argc, char *argv[]){

// inicializar a rvore

Tree *pTree;
pTree = new Tree();//Arvore de registros
DCElement *pDCElement;
string nome = "";
long identifier;
bool testes;

/*fstream fio("Teste.txt"); // Abre arquivo para gravao


//em modo texto
char ch;
cout << "Digite um texto ";
cout << "\nPressione CTRL_Z para encerrar ";
cin.get(ch); // L um caracter do teclado
fio.put(ch); // Grava o caracter no arquivo
fio.close();*/

cout << "Digite 0 se voc deseja criar regitros de teste" << endl;
cout << "Digite 1 se voc deseja criar registros reais" << endl;
cin >> testes;
Arquivo: /home/ealves/Dropbox/Estudos/Materias/AEDS 3/tp1 Pgina 10 de 11

int menu = Menu();

while (menu != 0){


// abre um arquivo para escrita de nome Teste.txt

switch (menu) {
case 1:{
cout << "Inserir Registro" << endl;
pDCElement = new DCElement(); //Para guardar os
dados que sero inseridos
if (testes){
pDCElement->createElement();
}else{
pDCElement->createTestElement();
}
pTree->InsertsNodo(*pDCElement, pTree->getNewNodo
());

break;
}
case 2:{
cout << "Apagar Registro" << endl;
cout << "Entre com indice desejado: ";
cin >> identifier;
pTree->RemovesNodo(identifier, pTree->getNewNodo
());

break;
}
case 3:{
cout << "Imprimir Registros" << endl;
pTree->ioTraversal(pTree->getRoot());
break;
}
case 4:{
cout << "Busca por Nome" << endl;
cout << "Digite a chave de busca: ";
cin >> nome;
pTree->SearchName(nome, pTree->getRoot());
break;
}
case 5:{
cout << "Busca por Chave" << endl;
cout << "Entre com indice desejado: ";
cin >> identifier;
pDCElement = new DCElement(); //Para guardar os
dados que sero inseridos
pDCElement->setIdentifier(identifier);
if (pTree->SearchIdentificator(pDCElement, pTree-
>getNewNodo()))
pDCElement->printElement();
break;
}
case 6:{
cout << "Sair";
break;
}
default:{
cout << "Tente novamente com uma opo vlida" <<
endl;
break;
}
}
Arquivo: /home/ealves/Dropbox/Estudos/Materias/AEDS 3/tp1 Pgina 11 de 11

menu = Menu();
};

return 0;
};

int Menu(){
int menu;
cout << "****************** Menu de aes *************" << endl;
cout << "* 1 - Inserir Registro | 4 - Busca por Nome *" << endl;
cout << "* 2 - Apagar Registro | 5 - Busca por Chave *" << endl;
cout << "* 3 - Imprimir Registros | 0 - Sair *" << endl;
cout << "* Escolha uma opo: ";
cin>>menu;
return menu;
};

Você também pode gostar