3
I am doing a job for the college in which I have to put together a program to manage a restaurant that only makes deliveries the orders are made by phone and internet using object orientation and pointers in C++.
I’m doing it this way:
Use two files for each class one .cpp
and a .hpp
, below my implementation Client class.
Client.
#ifndef CLIENTE_HPP
#define CLIENTE_HPP
#include "Principal.hpp"
#include "Bibliotecas.hpp"
class Cliente {
public:
Cliente();
int idCliente;
string enderecoCliente;
string nomeCliente;
string cpfCliente;
void inserirCliente();
void alterarCliente();
void listarCliente();
void incrementaVetor();
int excluirCliente();
int pesquisar(int id);
virtual ~Cliente();
protected:
private:
Cliente *clientes;
Principal *principal;
int TAM;
int cont;
int indice;
};
#endif // CLIENTE_HPP
Client.cpp
include "Cliente.hpp"
Cliente::Cliente() {
idCliente = 0;
enderecoCliente = "";
nomeCliente = "";
cpfCliente = "";
TAM = 2;
cont = 1;
indice = 0;
clientes = NULL;
principal = new Principal();
}
void Cliente::inserirCliente() {
if(clientes == NULL) {
clientes = new Cliente[TAM];
}
cout << "\n";
principal->centralizaTexto("Cadastro de Clientes");
cout << "\n";
cout << endl << endl;
principal->alinhaTexto("ID Cliente: ", 5, 14);
cout << cont << endl;
clientes[indice].idCliente = cont;
cout << endl;
cin.ignore();
do {
principal->alinhaTexto("Informe o nome: ", 6, 14);
getline(cin, clientes[indice].nomeCliente);
cout << endl;
} while(clientes[indice].nomeCliente == "");
do {
principal->alinhaTexto("Informe o endereço: ", 6, 14);
getline(cin, clientes[indice].enderecoCliente);
cout << endl;
} while(clientes[indice].enderecoCliente == "");
do {
principal->alinhaTexto("Informe o número do CPF: ", 6, 14);
getline(cin, clientes[indice].cpfCliente);
cout << endl;
} while(clientes[indice].cpfCliente == "");
cont++;
indice++;
if(indice == TAM) {
incrementaVetor();
}
cout << endl;
principal->centralizaTexto("Cliente cadastrado com sucesso!", 10);
principal->pause();
}
int Cliente::excluirCliente() { ... }
void Cliente::alterarCliente() { ... }
void Cliente::listarCliente() { ... }
void Cliente::incrementaVetor() { ... }
int Cliente::pesquisar(int id) {
for(int i = 0; i < indice; i++) {
if (clientes[i].idCliente == id)
return i;
}
return -1;
}
I have two more classes implemented in this way Menu and Driver. But my problem is in the class I have to do now, which is the Requests class, where I need to search for the information contained in the object vectors of the other classes (vectors are pointers). For example I need from within the Orders class to access the client name variable of any of the clients vector to pick up its content.
My class Requests for now this way:
Requests.hpp
#ifndef PEDIDOS_HPP
#define PEDIDOS_HPP
#include "Principal.hpp"
#include "Bibliotecas.hpp"
#include "Cliente.hpp"
class Pedidos {
public:
Pedidos();
int idPedido;
string clientePedido;
string motoristaPedido;
string itemsPedido;
string placaVeiculoPedido;
void inserirPedido();
void alterarPedido();
void listarPedido();
void incrementaVetor();
int excluirPedido();
int pesquisar(int id);
virtual ~Pedidos();
protected:
private:
Cliente *clientes;
};
#endif // PEDIDOS_HPP
Requests.cpp
#include "Pedidos.hpp"
#include "Cliente.hpp"
Pedidos::Pedidos() {
idPedido = 0;
clientePedido = "";
motoristaPedido = "";
itemsPedido = "";
placaVeiculoPedido = "";
}
void Pedidos::inserirPedido() {
}
void Pedidos::alterarPedido() {}
void Pedidos::listarPedido() {}
void Pedidos::incrementaVetor() {}
int Pedidos::excluirPedido() {}
int Pedidos::pesquisar(int id) {}
Pedidos::~Pedidos() {
//dtor
}
I tried several ways, some gave access error and closed the program others the program continued but did not show the result.
Another question is how much my research function is in the class Cliente
, how do I return an object of the pointer type?
The question is too long, try to attack one problem at a time, don’t make us analyze all your code. Read this: http://answall.com/help/mcve. We need to know where your problem is. We have to figure out the problem to then give the solution gets complicated. Is there a requirement to use pointer or have you decided to use it? I’ve seen some misconceptions as class
Cliente
have inside of herclientes
, which is a collection ofCliente
. In thesis could, but doesn’t it sound weird have clients own customers? When the thing is misconceived the implementation will also be.– Maniero
The question is the smallest way I found to show my problem, the first Clients.hpp and Clients.cpp codes have no problems and just to see how this my implementation and hid much of my code there is not even 1/5 of it. Right at the beginning I say I need to use pointers because it’s a job requirement. Well among the codes this my real problem is accessing the information that are in the other classes as to customers within the order class. My Client class has an array called clients where are the data of each of my customers.
– Fabricio Andrade
Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?
– Maniero