i've being trying to fix the error in my code for quite some time but am unable to resolve one or two of the errors like expected primary-expression before 'public'
main.cpp:211:22: error: expected ';' before 'public'
main.cpp:216:23: error: expected '}' before 'else'
i am a beginner in programming

    # include<iostream>
    #include<fstream>
    #include<sstream>
    using namespace std;
    template <class A>
    class Array
    {

        int siz;
        public:
            A *a;
        void create_array(int cap)
        {
           if(cap>0)
           {
            a=new A[cap];
            siz=cap;
           }
           else
           {
               cout<<"the size is wrong";
           }
        }
        void store(A values,int index)
        {
            if(index<siz&&index>=0)
            a[index]=values;
            else
                cout<<"invalid index";
        }
        A retrieve(int index)
        {
            if(index<siz&&index>=0)
            return a[index];
            else
                cout<<"inavalid index";
        }

    };
    template <class S>
    class stacks
    {
        Array <S>obj;
        int top;
        int capacity;
        public:
            stacks()
            {
                top=0;
                capacity=0;
            }
       void create_stack(int s)
       {
            capacity=s;
            top=0;
            obj.create_array(s);
       }
       void push(S value)
       {
           if(!isFull())
           {
               obj.store(value,top);
               top+=1;
           }
           else
            cout<<"stack overflow";
       }
        S pop()
        {
            if(top!=0)
               {
                   top-=1;
                return obj.retrieve(top);
               }
            else
                cout<<"stack underflow";
        }
       bool isFull()
        {
            if(top==capacity)
                return true;
            else
                return false;
        }

        bool isEmpty()
        {
            if(top==0)
                return true;
            else
                return false;
        }
    };
    template<class Q>
    class queues
    {
        int cap;
        int head,tail;
        Array<Q>obj;
       void create_queue(int size)
       {
        if(size>0)
        {
            cap=size;
            obj.create_array(size);
            head=0;
            tail=0;
       }
       else
        cout<<"invalid size"<<endl;
       }
        bool isEmpty()
        {
            if(head==0&&tail==0)
                return true;
            return false;
        }
        bool isFull()
        {
            if(tail==cap)
                return true;
            return false;
        }
        void enqueue(Q value)
       {
           if(head==0&&!isFull())
           {
               obj.store(value,tail);
               tail+=1;
           }
           else if(!isFull())
           {
               int i;
               while(head!=0)
               {
                   for(i=head;i<tail;i++)
                    obj.a[i-1]=obj.a[i];
                   head-=1;
                   tail-=1;
               }
               obj.store(value,tail);
               tail+=1;
           }
           else
            cout<<"queue full"<<'\n';

       }
        Q dequeue()
        {
           if(!isEmpty())
            {
                Q val=obj.retrieve(head);
                head+=1;
                return val;
            }
            else
            {
                cout<<"queue empty"<<'\n';
            }
        }
    };
    //template<class T>
    class fileinp
    {
       public:
     void readme()
       {
           ifstream inf("input.txt");
       string strinput;
       string adt;
       int value;
       while(!inf.eof())
       {
           inf>>strinput;
           if(strinput.compare("stack")==0)
                   {
                    adt="stack";
                      inf>>strinput;
                   // public:
                      if(strinput.compare("int")==0)
                       {
                        stacks<int> obj1;
                       }
                      else
                        if(strinput.compare("float")==0)
                        {
                           stacks <float> obj1;
                        }
                      else
                        if(strinput.compare("double")==0)
                           {
                                stacks <double> obj1;
                           }
                        else
                          if(strinput.compare("char")==0)
                            {
                               stacks<char> obj1;
                            }
                        else
                           {
                             stacks<int> obj1;
                           }
                   }

           else
           {
               if(strinput.compare("queue")==0)
                   {
                      adt="queue";
                      inf>>strinput;
                     public:
                      if(strinput.compare("int")==0)
                       {
                         queues<int> obj1;
                       }
                      else if(strinput.compare("float")==0)
                        {
                           queues<float> obj1;
                        }
                      else if(strinput.compare("double")==0)
                       {
                           queues<double> obj1;
                       }
                        else if(strinput.compare("char")==0)
                        {
                         queues<char> obj1;
                        }
                        else
                           {
                               queues<int> obj1;
                           }
                   }
            }
        };
                    while(!inf.eof())
                   {
                           inf>>strinput;
                        if(adt.compare("stack")==0&&strinput.compare("push")==0)
                               {
                                  inf>>strinput;
                                 istringstream (strinput) >> value;
                                  obj1.push(value);
                               }
                       else if(adt.compare("stack")==0&&strinput.compare("pop")==0)
                               {
                                  cout<<"the value popped is"<<obj1.pop();
                               }
                        else if(adt.compare("queue")==0&&strinput.compare("enqueue")==0)
                                {
                                  inf>>strinput;
                                  istringstream(strinput) >> value;
                                  obj1.enqueue(value);
                                }
                        else if(adt.compare("queue")==0&&strinput.compare("dequeue")==0)
                                {
                                  cout<<"the value dequeued is"<<obj1.dequeue();
                                }
                         else
                                inf>>strinput;

                   }


       }
    };
    int main()
    {
        int s;
        stacks <int>obj2;
        cin>>s;
        cout<<"size is "<<s<<'\n';
        obj2.create_stack(s);
        obj2.push(10);
        obj2.push(5);
        int k=obj2.pop();
        cout<<k;
       fileinp obj;
       obj.readme();
    return 0;
    };

At line 211, you cannot have public: within a function body. This is only allowed (and meaningful) at the class scope. Remove it and it should solve the errors.

Also, you should learn to indent and space out your code better, it will be really helpful in the future to find bugs and for general clarity of the code. Consider this:

#include <iostream>
#include <fstream>
#include <sstream>

using namespace std;

template <class A>
class Array
{
    private:
        int siz;

    public:
        A *a;

        void create_array(int cap)
        {
           if( cap > 0 )
           {
               a = new A[cap];
               siz = cap;
           }
           else
           {
               cout << "the size is wrong";
           }
        }

        void store(A values,int index)
        {
            if( index < siz && index >= 0 )
                a[index] = values;
            else
                cout << "invalid index";
        }

        A retrieve(int index)
        {
            if( index < siz && index >= 0 )
                return a[index];
            else
                cout << "invalid index";
        }

};


template <class S>
class stacks
{
    private:
        Array <S>obj;
        int top;
        int capacity;

    public:

        stacks()
        {
            top = 0;
            capacity = 0;
        }

       void create_stack(int s)
       {
            capacity = s;
            top = 0;
            obj.create_array(s);
       }

       void push(S value)
       {
           if( !isFull() )
           {
               obj.store(value,top);
               top += 1;
           }
           else
               cout << "stack overflow";
       }

       S pop()
       {
           if( top != 0 )
           {
               top -= 1;
               return obj.retrieve(top);
           }
           else
               cout << "stack underflow";
       }

       bool isFull()
       {
           if( top == capacity )
               return true;
           else
               return false;
       }

       bool isEmpty()
       {
           if(top==0)
               return true;
           else
               return false;
       }
};


template<class Q>
class queues
{
    private:
        int cap;
        int head, tail;
        Array<Q> obj;

        void create_queue(int size)
        {
            if(size > 0)
            {
                cap = size;
                obj.create_array(size);
                head = 0;
                tail = 0;
            }
            else
                cout << "invalid size" << endl;
        }

        bool isEmpty()
        {
            if( head == 0 && tail == 0)
                return true;
            return false;
        }

        bool isFull()
        {
            if(tail == cap)
                return true;
            return false;
        }

        void enqueue(Q value)
        {
            if( head == 0 && !isFull() )
            {
                obj.store(value,tail);
                tail += 1;
            }
            else if( !isFull() )
            {
                int i;
                while(head!=0)
                {
                    for(i = head; i < tail; i++)
                        obj.a[i-1] = obj.a[i];
                    head -= 1;
                    tail -= 1;
                }
                obj.store(value,tail);
                tail += 1;
            }
            else
                cout << "queue full" << '\n';

        }

        Q dequeue()
        {
            if( !isEmpty() )
            {
                Q val = obj.retrieve(head);
                head += 1;
                return val;
            }
            else
            {
                cout << "queue empty" << '\n';
            }
        }
};


//template<class T>
class fileinp
{
    public:
        void readme()
        {
            ifstream inf("input.txt");
            string strinput;
            string adt;
            int value;

            while(!inf.eof())
            {
                inf >> strinput;
                if( strinput.compare("stack") == 0)
                {
                    adt = "stack";
                    inf >> strinput;
                    if( strinput.compare("int") == 0)
                    {
                        stacks<int> obj1;
                    }
                    else
                    if( strinput.compare("float") == 0)
                    {
                        stacks <float> obj1;
                    }
                    else
                    if( strinput.compare("double") == 0)
                    {
                        stacks <double> obj1;
                    }
                    else
                    if( strinput.compare("char") == 0)
                    {
                        stacks<char> obj1;
                    }
                    else
                    {
                        stacks<int> obj1;
                    }
                }
                else
                {
                    if( strinput.compare("queue") == 0)
                    {
                        adt = "queue";
                        inf >> strinput;

                        if( strinput.compare("int") == 0)
                        {
                            queues<int> obj1;
                        }
                        else if( strinput.compare("float") == 0)
                        {
                            queues<float> obj1;
                        }
                        else if( strinput.compare("double") == 0)
                        {
                            queues<double> obj1;
                        }
                        else if( strinput.compare("char") == 0)
                        {
                            queues<char> obj1;
                        }
                        else
                        {
                            queues<int> obj1;
                        }
                    }
                }
            };

            while( !inf.eof() )
            {
                inf >> strinput;
                if( adt.compare("stack") == 0 && strinput.compare("push") == 0)
                {
                    inf >> strinput;
                    istringstream (strinput) >> value;
                    obj1.push(value);
                }
                else if( adt.compare("stack") == 0 && strinput.compare("pop") == 0)
                {
                    cout << "the value popped is" << obj1.pop();
                }
                else if( adt.compare("queue") == 0 && strinput.compare("enqueue") == 0)
                {
                    inf >> strinput;
                    istringstream(strinput) >> value;
                    obj1.enqueue(value);
                }
                else if( adt.compare("queue") == 0 && strinput.compare("dequeue") == 0)
                {
                    cout << "the value dequeued is" << obj1.dequeue();
                }
                else
                    inf >> strinput;

            }
        }
};

int main()
{
    int s;
    stacks<int> obj2;
    cin >> s;
    cout << "size is " << s << '\n';
    obj2.create_stack(s);
    obj2.push(10);
    obj2.push(5);
    int k = obj2.pop();
    cout << k;
    fileinp obj;
    obj.readme();
    return 0;
};
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.