It turns out that I want to make batteries with fixes, and I want to run the push and print, but I print it with errors.
What corrections can I make? if possible, pop also want to do it, but I have no idea how to do it.
Code:
Pilas.h#pragma once
#define LongitudMaxima 6
class Pilas
{
private:
int nValor,Tope, nPila[LongitudMaxima];
public:
Pilas();
~Pilas();
bool EstaVacia();
bool EstaLlena();
bool push(int nValor);
void imprimir();
};
Pilas.ccp
#include "stdafx.h"
#include "Pilas.h"
Pilas::Pilas()
{
Tope = -1;
for (int nIndex = 0; nIndex < 6; nIndex++)
{
nPila[nIndex] = 0;
}
}
Pilas::~Pilas()
{
}
bool Pilas::EstaVacia()
{
return Tope == -1;
}
bool Pilas::EstaLlena()
{
return Tope = nPila[LongitudMaxima];
}
bool Pilas::push(int nValor)
{
bool bAllOk = false;
if (!EstaLlena())
{
if (EstaVacia())
{
return true;
Tope = 0;
nPila[0] = nValor;
}
else
{
for (int nIndex = 1; nIndex < LongitudMaxima; nIndex++)
{
cout << "LA PILA ESTA LLENA..." << endl;
}
}
}
}
void Pilas::imprimir()
{
cout << "LA PILA es: " << push(nValor)<< endl;
}
main.cpp: defines the entry point of the console application.
#include "stdafx.h"
int main()
{
Pilas A;
A.imprimir();
system("pause");
return 0;
}