THIS IS THE SOURCE:
#include <iostream>
#include "gestor.h"
using namespace std;
int menu()
{
int opc;
cout << "Faca a sua escolha!" << endl;
cout << "1-> inserir avaria!" << endl;
cout << "2-> listar avaria!" << endl;
cout << "0-> sair" << endl;
cin >> opc;
return opc;
}
gestor *criargestor()
{
gestor*g;
g = new gestor();
return g;
}
void destruirgestor(gestor*g)
{
delete g;
}
void main()
{
gestor *g;
g = criargestor();
int opcao;
do
{
opcao = menu();
switch (opcao)
{
case 1: g->addavaria();
break;
case 2:g->listaravarias();
break;
case 0:
break;
default:
cout << "invalido!\n" << endl;
}
} while (opcao!= 0);
destruirgestor(g);
}
THIS AND HEADER FILE malfunction.h
#pragma once
#include<string>
#include<iostream>
#include<locale.h>
using namespace std;
class avaria
{
int codigoavaria;
string nome;
string descricao;
public:
avaria(void);
avaria(int cod,string nm,string des);
void mostrar();
~avaria();
};
THIS IS THE FAILURE.CPP
#include "avaria.h"
avaria::avaria(void)// construtor da função vai inicializar as variáveis.
{
cout << " passei na função= [" << __FUNCTION__ << "]" << endl;
}
avaria::avaria(int cod, string nm,string des)
{
setlocale(LC_ALL, "portuguese");
cout << " passei na função= [" << __FUNCTION__ << "]" << endl;
codigoavaria = cod;
nome =nm;
descricao = des;
}
void avaria::mostrar()
{
setlocale(LC_ALL, "portuguese");
cout << " passei na função= [" << __FUNCTION__ << "]" << endl;
cout << " codigo =" << codigoavaria << endl;
cout << "nome =" << "[" << nome << "]" << endl;
cout << "descrição" << "[" << descricao << "]" << endl;
}
avaria::~avaria()
{
setlocale(LC_ALL, "portuguese");
cout << " passei na função= [" << __FUNCTION__ << "]" << endl;
}
THIS IS THE MANAGER.H
#pragma once #include #include #include "malfunction.h" class manager { list lav;
public:
gestor();
void addavaria();
void listaravarias();
~gestor();
};
THIS IS THE MANAGER.CPP
#include "gestor.h"
gestor::gestor()
{
}
void gestor::addavaria()
{
setlocale(LC_ALL, "portuguese");
string descricao;
string nome;
int tipo;
avaria*av = NULL;
cout << "Introduza o tipo de avaria! (1) electrica (2) mecanica" << endl;
cin >> tipo;
cin.ignore();
cout << " Introduza o nome da avaria!" << endl;
getline(cin, nome);
cout << "Introduza a descrição da avaria!" << endl;
getline(cin,descricao);
av = new avaria (tipo,nome,descricao);
}
void gestor::listaravarias()
{
cout << "N. de Elementos da Lista = " << lav.size() << endl;
for (list<avaria*>::iterator Iter = lav.begin();
Iter != lav.end(); Iter++)
{
cout << "................................." << endl;
cout << endl;
(*Iter)->mostrar();
cout << endl;
cout << "..................................." << endl;
}
}
gestor::~gestor()
{
}
What happens is that the addavaria () function does not seem to add any malfunction to the list, every time I compile it I add a malfunction and then I show it and the function says that zero elements are added to the list. the program is in C ++ and is working with a manager class (it does not have hierarchy) that is to manage all the faults of the class malaria.