Please help me doing my homework. this homework done with C++ Data Structure.

This is Questions:
http://img520.imageshack.us/img520/4417/qqqq1gvq5.gif

#include <iostream>
#include <stdio>
#include <assert>
#include <string>
#include "bt.h"

 class Calc
           {
           	public:
            	
           } ;

int main()
{
     bSearchTreeType<Calc> obj;
     string command;
     cout<<"I-Inputtheexpression"<<endl;
     cout<<"N-InorderTraversal"<<endl;
     cout<<"P-PreorderTraversal"<<endl;
     cout<<"O-PostorderTraversal"<<endl;
     cout<<"F-Numberofoperatorinthetree"<<endl;
     cout<<"E-Evaluatethetree"<<endl;
     cout<<"Q-Quit"<<endl;
     cin>>command;
     do
     {
     if(command=="I")
     {
     Calc expr;
     cout<<"your choice is "<<command<<endl;
     cout<<"Input the expression:";
     cin>>expr;
    obj.insert(expr);

     }
	  if(command=="F")
      {
        cout<<"your choice is "<<command<<endl;

        cout<<" operators are in the tree";
        }
      
       if(command=="O")
       {
         cout<<"your choice is "<<command<<endl;
         obj.postorderTraversal();
          cout<<endl;
       }
        if(command=="P")
       {
         cout<<"your choice is "<<command<<endl;
         obj.preorderTraversal();
          cout<<endl;
       }
         if(command=="N")
       {
         cout<<"your choice is "<<command<<endl;
         obj.inorderTraversal();
          cout<<endl;
       }
       if(command=="E")
       {
         cout<<"your choice is "<<command<<endl;

         cout<<"Result is";
       }
         cout<<"I-Input the expression"<<endl;
     cout<<"N-InorderTraversal"<<endl;
     cout<<"P-PreorderTraversal"<<endl;
     cout<<"O-PostorderTraversal"<<endl;
     cout<<"F-Number of operator in the tree"<<endl;
     cout<<"E-Evaluate the tree"<<endl;
     cout<<"Q-Quit"<<endl;
     cin>>command;
    
     }while(command!="Q");
      system("pause");

}

this is header file: this is also lots of mistake and correction.

#include <iostream>
template<class T>
struct node
{
	T info;
   node<T> *llink;
   node<T> *rlink;
   };
   template <class T>
   class Binarytree
   {
   	public:
      const Binarytree<T> & operator=(const Binarytree<T> &);
      bool isempty();
      void inordertraversal();
      void preordertraversal();
      void postordertraversal();
      int treeheight();
      int treenodecount();
      int treeleavescount();
      void destroytree();
      Binarytree(const Binarytree<T> & othertree);
      Binarytree();
      ~Binarytree(){destroy(root);}
    protected:
      node<T> *root;
    private:
      void copytree(node<T>* &copiedtreeroot,node<T> *othertreeroot);
      void destroy(node<T>* &p);
      void inorder(node<T> *p);
      void preorder(node<T> *p);
      void postorder(node<T> *p);
      int height(node<T> *p);
      int max(int x,int y);
      int nodecount(node<T> *p);
      int leavescount(node<T> *p);
      };
      template <class T>
      bool Binarytree<T>::isempty()
      {
			return(root==NULL);
         }
        template <class T>
       Binarytree<T>::Binarytree()
       {
       root=NULL;
       }
        template<class T>
	void Binarytree<T>::inordertraversal()
      {
      	inorder(root);
       }
        template <class T>
   	void Binarytree<T>::preordertraversal()
      {
      	preorder(root);
      }
       template <class T>
		void Binarytree<T>::postordertraversal()
      {
      	postorder(root);
      }
      template <class T>
      int Binarytree<T>::treeheight()
      {
      	return height(root);
      }
	   template <class T>
      int Binarytree<T>::treeleavescount()
      {
      	return leavescount(root);
      }
          template <class T>
          void Binarytree<T>::inorder(node<T> *p)
          {
          	if(p!=NULL)
            {
            	inorder(p->llink);
               cout<<p->info<<" ";
               inorder(p->rlink);
             }
          }
              template <class T>
              void Binarytree<T>::preorder(node<T> *p)
              {
           		if(p!=NULL)
           		{
           		cout<<p->info<<" ";
            	preorder(p->llink);
           		preorder(p->rlink);
               }
              }
                template <class T>
                void Binarytree<T>::postorder(node<T> *p)
                {
                	if(p!=NULL)
                  {
                  	postorder(p->llink);
                     postorder(p->rlink);
                     cout<<p->info<<" ";
                  }
                  }
                      template <class T>
                    int Binarytree<T>::height(node<T> *p)
                    {
                    		if(p==NULL)
                        	return 0;
                         else
                         	return 1+max(height(p->llink),height(p->rlink));
                   }
                       template <class T>
                    int Binarytree<T>::max(int x,int y)
                    {
                       if(x>=y)
                       	return x;
                       else
                       	return y;
                   }
                       template <class T>
                     void Binarytree<T>::destroy(node<T> * &p)
                     {
                     	if(p!=NULL)
                        {
                        	destroy(p->llink);
                           destroy(p->rlink);
                           delete p;
                           p=NULL;
                        }
                    }

          template <class elemType>
  void  bSearchTreeType<elemType>::insert(const elemType& item)
           {
               node<T> *p, *q, *r;
               r = newnode<elemType>;
               r.info = item;
               r.llink = rlink =NULL;
               if(root==NULL)
                   root=r;
               else
                   p=root;
               while(p!=NULL){
                   q = p;
                   if(p.info == item)
                   {
                       cerr<<"Dublicates are not allowed";
                       return ;
                   }
                   if(item<p.info)
                       p=p.llink;
                   else
                       p=p.rlink;
               }
               if(item < q.info)
                   q.llink=r;
               else
                   q.rlink = r;
               }

So that's it?

You just dump your code and without any other effort (say what you've tried, which compiler, what the errors are), you just expect someone to fix it?

#include <get_real.h>

So that's it?

You just dump your code and without any other effort (say what you've tried, which compiler, what the errors are), you just expect someone to fix it?

#include <get_real.h>

in code lots of things missing. i want to help the correct code. i complier borland.

in code lots of things missing. i want to help the correct code. i complier borland.

You're missing the point. You need to describe what you've done, what problems you're getting, what the exact errors are along with the exact line those errors are on, what you're stuck on, what attempts you've made to fix them, etc. A nice well-written paragraph explaining the problem and a specific question will get you much more help.

You're missing the point. You need to describe what you've done, what problems you're getting, what the exact errors are along with the exact line those errors are on, what you're stuck on, what attempts you've made to fix them, etc. A nice well-written paragraph explaining the problem and a specific question will get you much more help.

my real problem is : when the user enter I(nsert) program how to insert the expressinon in binary tree.

You're trying to use the input stream operator '>>' on your Calc object, yet you haven't overloaded the operator to accept a Calc object.

#include <iostream>
#include <stdio>
#include <assert>
#include <string>
#include "bt.h"

 class Calc
           {
           	public:
            	
           } ;

int main()
{
     bSearchTreeType<Calc> obj;
     string command;
     cout<<"I-Inputtheexpression"<<endl;
     cout<<"N-InorderTraversal"<<endl;
     cout<<"P-PreorderTraversal"<<endl;
     cout<<"O-PostorderTraversal"<<endl;
     cout<<"F-Numberofoperatorinthetree"<<endl;
     cout<<"E-Evaluatethetree"<<endl;
     cout<<"Q-Quit"<<endl;
     cin>>command;
     do
     {
     if(command=="I")
     {
     Calc expr;
     cout<<"your choice is "<<command<<endl;
     cout<<"Input the expression:";
     cin>>expr; // error!
    obj.insert(expr);

And also even if you do overload the operator for your class, you'll have to provide data types for storing the data obtained from the input given by the user.

You're trying to use the input stream operator '>>' on your Calc object, yet you haven't overloaded the operator to accept a Calc object.

#include <iostream>
#include <stdio>
#include <assert>
#include <string>
#include "bt.h"

 class Calc
           {
           	public:
            	
           } ;

int main()
{
     bSearchTreeType<Calc> obj;
     string command;
     cout<<"I-Inputtheexpression"<<endl;
     cout<<"N-InorderTraversal"<<endl;
     cout<<"P-PreorderTraversal"<<endl;
     cout<<"O-PostorderTraversal"<<endl;
     cout<<"F-Numberofoperatorinthetree"<<endl;
     cout<<"E-Evaluatethetree"<<endl;
     cout<<"Q-Quit"<<endl;
     cin>>command;
     do
     {
     if(command=="I")
     {
     Calc expr;
     cout<<"your choice is "<<command<<endl;
     cout<<"Input the expression:";
     cin>>expr; // error!
    obj.insert(expr);

And also even if you do overload the operator for your class, you'll have to provide data types for storing the data obtained from the input given by the user.

i know this is error. how i can insert the binary tree, input expression ?

i know this is error. how i can insert the binary tree, input expression ?

There's nothing to insert. You can't insert expr into a binary tree if there's nothing in expr. You need to solve that first before worrying about how to insert it somewhere. Also, is this the class? You're trying to insert something of type Calc into a tree?

class Calc
           {
           	public:
            	
           } ;

What's the point? Even if you do write a >> operator, it has no data members to store anything. How can you make a tree out of this?

There's nothing to insert. You can't insert expr into a binary tree if there's nothing in expr. You need to solve that first before worrying about how to insert it somewhere. Also, is this the class? You're trying to insert something of type Calc into a tree?

class Calc
           {
           	public:
            	
           } ;

What's the point? Even if you do write a >> operator, it has no data members to store anything. How can you make a tree out of this?

firstly i think write class then i saw it is not nessary.but i can not solve and write insert in binary tree expression.

firstly i think write class then i saw it is not nessary.but i can not solve and write insert in binary tree expression.

How is it not necessary? You need to at least have some data members at minimum. Maybe you don't need to write all of the class functions, but you certainly need to write some of them. If this is a binary search tree, you need some type of data and you need some way to compare two Calc objects using that data. Otherwise, one, how do you know whether to go right or left when searching/inserting, and two, how do you know if you've found something?

How is it not necessary? You need to at least have some data members at minimum. Maybe you don't need to write all of the class functions, but you certainly need to write some of them. If this is a binary search tree, you need some type of data and you need some way to compare two Calc objects using that data. Otherwise, one, how do you know whether to go right or left when searching/inserting, and two, how do you know if you've found something?

i can not do that. please write this part.

Comments
Lazy

i can not do that. please write this part.

Ha ha ha. No chance in hell am I writing this for you. Did you even write the code that you posted?

dude you should take the time to comment your code, its really quick and goes a long way in speeding up the debug process, what class is this for, intro to C++ or an advanced one or what??? What year of college you in too

This article has been dead for over six months. Start a new discussion instead.