Good, I'm running a project for school, and at one point I realized that I had to split the work into files (because I was getting confused to find the procedures), but I'm not being able to split it, I do not think I'm using it the hpp files well, because I never gave them. Thanks for help correcting the code.
main.cpp
#include "introduzir.hpp"
#include "mostrar.hpp"
#include "eliminar.hpp"
#include "ordenar.hpp"
#include "classe.hpp"
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <unistd.h>
using namespace std;
unsigned int microseconds;
int op;
//segunda lista
copiar_lista(){
struct info *p=NULL;
struct info *q=NULL;
p=lista;
while(p!=NULL){
q=(struct info *)malloc(sizeof(struct info));
for(int i=0;i<50;i++){
q->tarefa[i]=' ';
q->tarefa[i]=p->tarefa[i];
}
for(int i=0;i<50;i++){
q->id[i]=' ';
q->id[i]=p->id[i];
}
q->nivel=p->nivel;
q->next=lista2;
lista2=q;
p=p->next;
}
}
//menu e switch para ordenar
escolha_ordenar(){
copiar_lista();
switch(op){
case 1:{
recentes();
eliminar();
break;
}
case 2:{
listar();
system("pause");
eliminar();
break;
}
case 3:{
break;
}
}
}
menu_ordenar(){
cout<<"1 - Mais recentes\n";
cout<<"2 - Mais antigos\n";
cout<<"3 - Prioridade Maior\n";
cout<<"4 - Prioridade Menor\n";
cin>>op;
escolha_ordenar();
}
//menu e switch das escolhas
escolha(){
switch(op){
case 1:{
introduzir();
break;
}
case 2:{
int esc;
listar();
cout<<"0 - Sair";
cin>>esc;
if(esc==0){
system("cls");
return 0;}
break;
}
case 3:{
eliminar();
break;
}
case 4:{
menu_ordenar();
break;
}
case 0:{
cout<<"Obrigado por utilizar este programa!\n";
break;
}
}
}
menu(){
cout<<"1 - Introduzir\n";
cout<<"2 - Listar\n";
cout<<"3 - Eliminar\n";
cout<<"4 - Ordenar\n";
cout<<"0 - Sair\n";
cin>>op;
escolha();
}
//main
int main(int argc, char** argv) {
setlocale(LC_ALL,"Portuguese");
system("color 0e");
do{
menu();
system("cls");
}while(op!=0);
system("pause");
}
enter.hpp
#ifndef INTRODUZIR_HPP
#define INTRODUZIR_HPP
#include "classe.hpp"
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <unistd.h>
using namespace std;
introduzir(){
struct info *p;
p=(struct info *)malloc(sizeof(struct info));
cout<<"Introduza o ID: ";
_flushall();
cin.getline(p->id,50);
cout<<"Introduza a tarefa: ";
_flushall();
cin.getline(p->tarefa,50);
do{
cout<<"Introduza o nível de prioridade(1-5): ";
_flushall();
cin>>p->nivel;
}while(p->nivel<1||p->nivel>5);
p->next=lista;
lista=p;
}
#endif
mostar.hpp
#ifndef MOSTRAR_HPP
#define MOSTRAR_HPP
#include "classe.hpp"
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <unistd.h>
using namespace std;
listar(){
struct info *p;
p=lista;
while(p!=NULL){
cout<<"ID: "<<p->id<<endl;
cout<<"Tarefa: "<<p->tarefa<<endl;
cout<<"Nível: "<<p->nivel<<endl;
p=p->next;
}
}
mostrar(){
struct info *p;
p=lista2;
while(p!=NULL){
cout<<"ID: "<<p->id<<endl;
cout<<"Tarefa: "<<p->tarefa<<endl;
cout<<"Nível: "<<p->nivel<<endl;
p=p->next;
}
}
#endif
delete.hpp
#idndef ELIMINAR_HPP
#define ELIMINAR_HPP
#include "classe.hpp"
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <unistd.h>
using namespace std;
eliminar(){
struct info *p;
p=lista;
while(p!=NULL){
lista=p->next;
free(p);
p=lista;
}
}
#endif
sort.hpp
#ifndef ORDENAR_HPP
#define ORDENAR_HPP
#include "classe.hpp"
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <unistd.h>
using namespace std;
recentes(){
copiar_lista();
struct info *p;
p=lista2;
struct info *prev=NULL;
struct info *next=NULL;
while(p!=NULL){
next=p->next;
p->next=prev;
prev=p;
p=next;
}
lista2=prev;
mostrar();
}
#endif
class.hpp
#ifndef CLASSE_HPP
#define CLASSE_HPP
#include <stdio.h>
#include <iostream>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <unistd.h>
struct info{
char tarefa[50],id[50];
int nivel;
struct info *next;
};
struct info *lista=NULL;
struct info *head_ref=NULL;
struct info *lista2=NULL;
#endif