Escolar Documentos
Profissional Documentos
Cultura Documentos
Trabalho Prático 1
Trabalho Prático 1
/*
* 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);
}
#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
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"
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
#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
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"
int Menu();
// inicializar a rvore
Tree *pTree;
pTree = new Tree();//Arvore de registros
DCElement *pDCElement;
string nome = "";
long identifier;
bool testes;
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
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;
};