![]() |
| | #1 |
| Registered User Join Date: Oct 2003
Posts: 15
| error trying to compile stack program 24 C:\Dev-Cpp\stacks.cpp implicit declaration of function `int PrintStackUp(...)' 27 C:\Dev-Cpp\stacks.cpp implicit declaration of function `int system(...)' Code: // File: stackao.h Class, constant values, and type
// definitions for C++ static implementation of ADT stack
// This is the specification file for the class stack.
#ifndef STACKTYPE_H
#define STACKTYPE_H
// application dependent size of stack
const unsigned int MAX_NUM_ELS = 256;
typedef int el_t; // type varies with application
typedef int index_t;
class stack
{
public:
stack(); // stack constructor
~stack(); // stack deconstructor
bool StackIsEmpty(void); // Is stack empty?
bool StackIsFull(void); // Is stack full?
void Push(el_t); // push item
void Pop(el_t&); //pop top item
void PrintStack(stack& s); // prints all elements of stack
void Print2nd(stack& s); // prints 2nd element in stack
void PrintBottom(stack& s); // prints bottom element of stack
void Palindrome(stack& s ); // deterimes if characters from a palindrome
private:
void StackError(char*); //error handler
index_t top; //top index: -1 if empty
el_t el[MAX_NUM_ELS]; //container for elements
};
#endif
// File: stackao.cpp Contents: C++ source code for static
// implementation of ADT stack. This is the implementation file.
//
#include<iostream.h>
//#include<stdlib.h>
#include "stackType.h"
using namespace std;
//Default constructor
//Pre: None
//Post: The stack object is initialized to be empty
//
stack::stack(void)
{
top = -1;
}
//Stack destructor
//Pre: The stack has gone out of scope or an explicit call
// to ~stack has occurred.
//Post: The stack is empty.
stack::~stack()
{
top = -1;
}
//Boolean function that returns TRUE if the stack is empty
//Pre: The stack has been initialized.
//Post: The function returns TRUE if the stack is empty,
// FALSE otherwise.
bool stack::StackIsFull(void)
{
return (top == -1 ? true : false);
}
//Boolean function that returns TRUE if a stack is full
//Pre: The sack has been initialized.
//Post: The function has returned TRUE if the stack is full,
// FALSE otherwise.
bool stack::StackIsFull(void)
{
return (top ++ (MAX_NUM_ELS -1) ? true : false);
}
//Function to push an element onto a non_full stack
//Pre: e is a data element of typr el_t.
// The stack is not full.
//Post: If the stack was not full, e was placed on top of
// the stack; otherwise StackError was called.
void stack::Push(el_t e)
{
if ( StackIsFull())
StackError("Stack is fulle\n");
else
{
++top;
el[top] = e;
}
}
// Function to pop an element from a nonempty stack and
// store it in the refernced variable
// Pre: The stack is nonempty.
// Post: The top stack element has been removed and stored
// in e. If the stack was empty, StackError was called.
void stack::Pop(el_t& e)
{
if (StackIsEmpty())
StackError(" Stack is empty \n");
else
{
e = el[top];
--top;
}
}
// Function to print an error message and abort the program
//Pre: An unrecoverable error occurred.
// ErrorMessage is an error message.
//Post: ErrorMessage has been output and the program aborted.
void stack::StackError( char* ErrorMessage)
{
cerr<< ErrorMessage;
exit(1);
}
// Function to print all elements in a stack and leave stack unchanged
// after printing
//Pre: The stack is non empty
//Post:
void stack::PrintStack(stack& s)
{
el-t e;
stack temp;
While (!s.StackIsEmpty())
{
s.pop(e);
temp.push(e);
cout<<e;
}
While(!temp.StackIsEmpty())
{
temp.pop(e);
s.push(e);
}
}
void stack::Print2nd(stack& s)
{
el-t e1, e2;
While(!s.StackIsEmpty())
{
s.pop(e1);
s.pop(e2);
cout<<e2;
s.push(e2);
s.push(e1);
}
}
void stack::PrintBottom(stack& s )
{
el_t e;
stack temp;
While(!s.StackIsEmpty())
{
s.pop(e);
temp.push(e);
}
cout<<e;
While(!temp.StackIsEmpty())
{
temp.pop(e);
s.push(e);
}
}
void stack::Palindrome(stack& s )
{
stack u,u2;
el_t ch, ch1;
bool equal = true;
While(!s.StackIsEmpty())
{
s.pop(ch);
u.push(ch);
u2.push(ch);
}
While(!u.StackIsEmpty())
{
u.pop(ch);
s.push(ch);
}
While(!u2.StackIsEmpyt() && equal)
{
u2.pop(ch);
s.pop(ch1);
if (ch != ch1)
equal = false;
}
if (equal)
cout<<"Palindrome"<<endl;
else
cout<<"Not a Palindrome"<<endl;
} //end of Palindrome Function
// This is the user program.
#include <iostream>
//#include <stdlib.h>
#include "stackType.h"
int main()
{
int i;
char *subject = "Data Structures";
stack s;
cout<< "Characters as pushed onto the stack: ";
i = 0;
while (( subject[i] != '\0') && (!s.StackIsFull()))
{
cout<< subject[i];
s.Push(subject[i]);
++i;
}
cout<< "\nThe stack from the bottom to top: ";
PrintStackUp(s);
cout<<endl;
system("PAUSE");
return 0;
}
|
| KristTlove is offline | |
| | #2 |
| Master of the Universe! Join Date: Sep 2003
Posts: 219
| You are missing header files to be included. So the compiler thinks you are making a suggested declaration.
__________________ While you're breakin' down my back n' I been rackin' out my brain It don't matter how we make it 'Cause it always ends the same You can push it for more mileage But your flaps r' wearin' thin And I could sleep on it 'til mornin' But this nightmare never ends Don't forget to call my lawyers With ridiculous demands An you can take the pity so far But it's more than I can stand 'Cause this couchtrip's gettin' older Tell me how long has it been 'Cause 5 years is forever An you haven't grown up yet -- You Could Be Mine - Guns N' Roses |
| velius is offline | |
| | #3 |
| Registered User Join Date: Jul 2003
Posts: 1,088
| Did you copy and paste the code directly from your file? If you did, then you have a lot of typos that should be fixed to get rid of compiler errors. If not, then please ignore any of these suggestions that refer to a typo. Looking at your code, you have a couple functions inside your stack class - PrintStack, Print2nd, PrintBottom, and Palindrome that all take a stack as a parameter and work with that stack. I don't see any reason for those functions to be member functions with the way they are implemented. One solution is to keep them as member functions, but instead of having a parameter, just do the work on the "this" object. Another solution is to make those functions global or static. Your PrintStackUp error is because you don't have any functions called PrintStackUp. Did you change the name to PrintStack and forget to change it in the main code? Your system compile error is because you commented out the include of the header file that the system function can be found in. You should #include <cstdlib> to get rid of that error. Finally, you use some old and some new headers files in your program. You should be consistent, and you should consistently use the new headers. Everywhere you have <iostream.h>, change it to <iostream> and everywhere you have <stdlib.h>, change it to <cstdlib>. Good Luck. |
| jlou is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help newbie compile program! | candysandra88 | C Programming | 7 | 12-13-2008 11:27 PM |
| Fixing my program | Mcwaffle | C Programming | 5 | 11-05-2008 03:55 AM |
| BOOKKEEPING PROGRAM, need help! | yabud | C Programming | 3 | 11-16-2006 11:17 PM |
| C program compile but not doing the calculations | abs.emailverify | C Programming | 8 | 11-08-2006 08:43 AM |
| How To Embed Data In Program While Compile? | ooosawaddee3 | C++ Programming | 1 | 09-09-2002 10:14 AM |