-2
#include<iostream>
#include<string>
using namespace std;

class customerNode{
    public:
        int c_id;
        int quantity;
        string c_name;
        string type;
        customerNode* next_node;
};
class Queue{
    public:
    customerNode* front=NULL;
    customerNode* rear=NULL;
    int getc_id();
    string getc_name();
    int getquantity();
    int setc_id(int c_id);
    string setc_name(string c_name);
    int setquantity(int quantity);
    void display();
    void enqueue(int c_id,int quantity,string c_name);
    void dequeue();
    int nor_queue,exp_queue;
};
int Queue::getc_id(){
    int c_id;
    cout<<"enter customer id:"<<endl;
    cin>>c_id;
    return c_id;
    
}
int Queue::getquantity(){
    int quantity;
    cout<<"enter quantity customer purchased:"<<endl;
    cin>>quantity;
    return quantity;
} 
string Queue::getc_name(){
    string c_name;
    cout<<"enter customer name:"<<endl;
    cin>>c_name;
    return c_name;
}
int Queue::setc_id(int c_id){
    return c_id;
    
}
    int Queue::setquantity(int quantity){
        return quantity;
    }
    string Queue::setc_name(string c_name){
        return c_name;
    }
    void Queue:: enqueue(int c_id,int quantity,string c_name){
        int exp_queue,nor_queue;
        cout<<"enter customer information"<<endl;
        customerNode* new_node=new customerNode;
        new_node->c_id=c_id;
        new_node->c_name=c_name;
        new_node->quantity=quantity;
        new_node->next_node=NULL;
        if(front==NULL){
            rear=front;
            rear=new_node;
            rear->next_node=NULL;
        }
        else{
            while(rear->next_node!=NULL)
            rear=rear->next_node;}
            rear->next_node=new_node;
            rear=new_node;
            if(new_node->quantity<=5)
{
                new_node->type="express";
                exp_queue++;
                cout<<"customer entered in express queue"<<endl;
                cout<<"total customer in express queue="<<exp_queue<<endl;
            }
            else{
                new_node->type="normal";
                nor_queue++;
                cout<<"customer entered in normal queue"<<endl;
                cout<<"total customer in normal queue="<<nor_queue<<endl;
            }
        
            }
                void Queue::display(){
                    customerNode* ptr=front;
                    cout<<"normal queue customer information"<<endl;
                        while(ptr!=NULL)
                        {
                            if(ptr->type=="normal"){
                                cout<<"customer name:"<<setc_name(ptr->c_name)<<endl;
                                cout<<"customer id:"<<setc_id(ptr->c_id)<<endl;
                                cout<<"item puchased by customer :"<<setquantity(ptr->quantity)<<endl;
                                nor_queue--;
                                cout<<"total customer in normal queue:"<<nor_queue<<endl;
                            
                        }
                        ptr=ptr->next_node;
                        }
                        
                        cout<<"express queue customer information"<<endl;
                        while(ptr!=NULL)
                        {
                            if(ptr->type=="normal"){
                                cout<<"customer name:"<<setc_name(ptr->c_name)<<endl;
                                cout<<"customer id:"<<setc_id(ptr->c_id)<<endl;
                                cout<<"item purchased by customer :"<<setquantity(ptr->quantity)<<endl;
                                nor_queue--;
                                cout<<"total customer in normal queue:"<<exp_queue<<endl;
                        
            }
        }
        }
        
 main(){
        Queue q;
        char i;
        do{
        q.enqueue(c_id,quantity,c_name );
        cout<<"do you want to enter another customer?input y or Y for yes and n or N for no:";
        cin>>i;
    }
        while(i=='y'||i=='Y');
        q.display();
        return(0);
    
        };`

in mian fuction i m getting error c_id,quantity,c_name is not declare before,when i use int c_id,int quantity,string c_name than it shows expected primary expression befor int and strinng..i dont know which expression is missing or how to resolve the error, please help me to solve this i hve to submit assing as soon as possible.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
khushi
  • 5
  • 1
  • 5
    It seems like you have skipped a few chapters in your beginners book. If you don't have any books to read, then [here's a list of bood ones](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). Please invest in some, and read from the veryu beginning without skipping anything. – Some programmer dude May 31 '21 at 14:19
  • Totally agree with @Someprogrammerdude. Indeed the error message in this case is quite clear: you're using something that is not defined yet..Variable definition and declaration is explained in, I guess, the first 10 pages of any programmer book, so pick youyr favourite one and you'll find easily the solution – Mauro Dorni May 31 '21 at 14:46

1 Answers1

0

A much simpler example with similar error is:

#include <iostream>
struct foo {
    int x = 0;
    int y = 0;
    void assign(int a, int b){
        x = a;
        y = b;
    }
};

int main()
{
    foo f;
    f.assign(x,y);
}

The error is:

<source>: In function 'int main()':
<source>:14:14: error: 'x' was not declared in this scope
   14 |     f.assign(x,y);
      |              ^
<source>:14:16: error: 'y' was not declared in this scope
   14 |     f.assign(x,y);
      |                ^

x and y are declared in the scope of the class. Instances of foo have members of that name. To access those members you would write f.x or f.y.

c_id,quantity, and c_name are not declared in your main. I am not eniterly sure what you want to do and it is too much code to adress all its issues. Though, if you want to declare variables of that name in main then you need to do that:

int main(){    // main must return int
    Queue q;
    char i;
    int c_id = 42;
    int quantity = 0;
    string c_name{"some fancy name"};
    q.enqueue(c_id,quantity,c_name );
    // ...
}

It is a little surprising that you write code with advanced stuff like pointers, classes and what not, but don't know about scope. Try to search for "scope" and read about it.

There are more issues in your code. For example int Queue::setquantity(int quantity){ return quantity;} does not set anything. Though, as I wrote before, this is just way too much code to adress all of them. I can only advise you to start with less code and only write more when you know the code you have already does compile and passes your tests. And thats not just an advise for a beginner, but anybody is making mistakes and you rather want to fix one problem then many at the same time.

463035818_is_not_an_ai
  • 109,796
  • 11
  • 89
  • 185