Thread: need help with classes, stacks

  1. #1
    Registered User
    Join Date
    Oct 2003
    Posts
    27

    need help with classes, stacks

    program isn't working....I have been working on it and reading. Am I even close?
    The program has two classes, one for the data, one for the stack. The program is supposed to get a number from the user and convert the number to binary, octal and hex. With binary push each remainder on the stack and then pop them off traversed. I am just trying to get it to work with binary right now



    syntax error : missing ';' before 'namespace'
    syntax error : missing ';' before 'namespace'
    stack:op' : looks like a function definition, but there is no formal parameter list; skipping apparent body
    '{' : missing function header (old-style formal list?)
    'bool stack:ush(int)' : overloaded member function not found in 'stack'





    Code:
    //number.h
    
    #pragma once
    
    class number
    {
    public:
    	int remainder;
    	number* data;
    
    	number* next;
    
    	number(void);
    	~number(void);
    	
    
    };
    
    class stack
    {
    private:
    	int count;
    	stack* top;
    	
    public:
    	stack() {count = 0; next = NULL;}
    	~stack();
    	int is_empty();
    	void getnum(int);
    	bool pop();
    	bool push();
    }
    
    //number.cpp
    #include "number.h"
    #include <iostream>
    
    using namespace::std;
    
    
    number::number()
    {
    	remainder = 0;
    	next = NULL;
    }
    
    number::~number()
    {
    }
    
    stack::stack()
    {
    	count = 0;
    	top = NULL;
    }
    
    stack::~stack()
    {
    }
    
    bool stack::pop{}
    {
    	number* dltptr;
    	bool success;
    
    	if (count == 0)
    	{
    		success = false;
    	}
    	else
    	{
    		dltptr = top;
    		dataout = top->
    
    	
    	}
    	
    }
    
    bool stack::push(int rem)
    {
    	bool success;
    	int n;
    	number* nptr;
    	
    	if (n == 0)
    	{
    		success = false;
    	}
    	else
    	{
    		nptr = 0;
    		nptr->remainder = top;
    		top = nptr;
    		count++;
    		success = true;
    	}
    	return success;
    }
    
    program.cpp
    
    #include "number.h"		//class
    #include <iostream>		//headers
    using namespace::std;
    
    void binary(int);
    
    stack intstack;
    
    int main()
    {
    	int numb;
    
    	binary (numb);
    
    	
    }
    
    void binary (int numb)
    {
    int n;
    int nu;				
    
    n = nu % 2;			
    	
    //push n on stack			
    
    
    if (nu == 0)			
    {
    	return ;
    }
    else 
    {
    	return binary(nu / 2);	 
    }
    }
    Last edited by student2005; 03-12-2004 at 01:11 PM.

  2. #2
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    >>syntax error : missing ';' before 'namespace'
    >>syntax error : missing ';' before 'namespace'
    Code:
    using namespace::std;  should be
    using namespace std;
    >>stack:pop' : looks like a function definition, but there is no formal parameter list; skipping apparent body
    '{' : missing function header (old-style formal list?)
    Code:
    //bool stack:pop{}
    bool stack::pop()
    {
        number* dltptr
       .....
    >>bool stack:push(int)' : overloaded member function not found in 'stack'
    Code:
    // number.h
    bool push();
    
    //number.cpp
    bool stack::push(int rem)
    {
    ...
    unmatching parameter
    Last edited by alphaoide; 03-12-2004 at 01:24 PM.
    source: compsci textbooks, cboard.cprogramming.com, world wide web, common sense

  3. #3
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    sorry I don't have time to look at your stack implementation right now, but here is the problem with the namespace

    #include "number.h" //class
    #include <iostream> //headers
    using namespace::std;

    should be,

    #include <iostream> //headers
    using namespace std;
    #include "number.h" //class

    I believe that should fix it.

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  4. #4
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,817
    Code:
    class stack
    {
    private:
    	int count;
    	stack* top;
    	
    public:
    	stack() {count = 0; next = NULL;}
    	~stack();
    	int is_empty();
    	void getnum(int);
    	bool pop();
    	bool push();
    }; // Missing semicolon?
    "Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
    -Christopher Hitchens

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can you Initialize all classes once with New?
    By peacerosetx in forum C++ Programming
    Replies: 12
    Last Post: 07-02-2008, 10:47 AM
  2. Multiple Inheritance - Size of Classes?
    By Zeusbwr in forum C++ Programming
    Replies: 10
    Last Post: 11-26-2004, 09:04 AM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Exporting VC++ classes for use with VB
    By Helix in forum Windows Programming
    Replies: 2
    Last Post: 12-29-2003, 05:38 PM
  5. Stacks, classes, HTML tags, and parsing.
    By Shinobi-wan in forum C++ Programming
    Replies: 5
    Last Post: 10-01-2003, 05:50 PM