Queue numbering system

I am still getting errors with this code. Could you help me solve it.
#include <iostream>
#include <queue>
#include <ctime>
#include <iomanip>

using namespace std;

class Data{
public:
queue <int> q;
time_t currentTime;
int time (&currentTime);
int queueNo;

int getNo()
{
return queueNo;
}

string getTime()
{
return time;
}
void toString()
{
cout.fill("0");
cout << setw(4) << queueNo<<" "<< time;
}
};




void main()
{
queue<Data>d;
char time2[10];
string time3;
int count = 1000;
char serve;
char exit;

int selection = 0;
int flag = 0;

while (flag == 0)
{
cout << "\t\t\t\tQueue Number System" << endl;
cout << "\t\t\t\t1)Generate Queue" << endl;
cout << "\t\t\t\t2)Get total waiting customers" << endl;
cout << "\t\t\t\t3)Display all waiting customers" << endl;
cout << "\t\t\t\t4)Serve customer" << endl;
cout << "\t\t\t\t5)Exit" << endl;
cout << "Enter Your Selection :";
cin >> selection;

if(selection == 1)
{
cout << endl;
cout << endl;
count++;
_strtime(time2);
time3 = time2;
cout.fill("0");
cout << "The queue number is " << setw(4) << count << " at time " << time3 << endl;
cout << endl;
cout << endl;
d.push(Data(count, time3));

}
else if (selection == 2)
{
cout << endl;
cout << endl;
cout << "The number of waiting customer is " << d.size() << endl;
cout << endl;
cout << endl;
}
else if (selection == 3)
{
cout << endl;
cout << endl;
cout << "Name Time" << endl;
for (int i = 0; i < d.size(); i++)
{
d.front().toString();
cout << endl;
d.push(d.front());
d.pop;
}
}
else if (selection == 4)
{
cout << endl;
cout << endl;
cout.fill("0");
cout << "Customer " << setw(4) << d.front().getNo();
cout << " is served? Yes or No? (Y/N)" << endl;
cin >> serve;

if (toupper(serve) == 'Y')
{
d.pop();
}
cout << endl;
cout << endl;
}
else if (selection == 5)
{
cout << endl;
cout << endl;
if (!d.empty())
{
cout << "Warning list is not empty. Proceeding will cause list to be deleted" << endl;
cout << "Proceed? Yes or No (Y/N)" << endl;
cin >> exit;
if (toupper(exit) == 'Y')
flag = 1;
else
flag - 0;
}
}
}
}
I am still getting errors with this code.

Thankyou for not telling us what those errors are. This is so much more fun when we have to play guessing games.
Sorry for the inconvenience. It is my first post. Here are the errors

prog.cpp:11:13: warning: in-class initialization of non-static data member is a C++11 extension [-Wc++11-extensions]
time_t now = time(0);
^
prog.cpp:12:13: error: C++ requires a type specifier for all declarations
int time (&currentTime);
^
prog.cpp:34:1: error: 'main' must return 'int'
void main()
^~~~
int
prog.cpp:62:4: error: use of undeclared identifier '_strtime'
_strtime(time2);
^
prog.cpp:67:11: error: no matching constructor for initialization of 'Data'
d.push(Data(count, time3));
^ ~~~~~~~~~~~~
prog.cpp:8:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
class Data{
^
prog.cpp:8:7: note: candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 2 were provided
prog.cpp:88:7: error: reference to non-static member function must be called; did you mean to call it with no arguments?
d.pop;
~~^~~
()
prog.cpp:95:9: error: no matching member function for call to 'fill'
cout.fill("0");
~~~~~^~~~
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/basic_ios.h:384:7: note: candidate function not viable: no known conversion from 'const char [2]' to 'char_type' (aka 'char') for 1st argument
fill(char_type __ch)
^
/usr/bin/../lib/gcc/i586-linux-gnu/4.9/../../../../include/c++/4.9/bits/basic_ios.h:364:7: note: candidate function not viable: requires 0 arguments, but 1 was provided
fill() const
^
prog.cpp:119:11: warning: expression result unused [-Wunused-value]
flag - 0;
~~~~ ^ ~
2 warnings and 6 errors generated.
stdout
Those error messages don't seem to relate to the code you've posted. For example, I don't see

time_t now = time(0);

anywhere in your code, but it's there in your first error message.

In any case, some of those error messages are self-explanatory. For example, the first one is telling you that there are compiler options you need to use, if you want to use the C++11 features. The third one is telling you that you haven't correctly defined your main function. Etc, etc...

EDIT: Your code would be much easier for us to read, if you used code tags:

http://www.cplusplus.com/articles/z13hAqkS/
Last edited on
ok this is the error list shows when i run this code.Help pls

Error 1 error C2059: syntax error : '&' g:\system\system\number system.cpp

Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int g:\system\system\number system.cpp

Error 4 error C2065: 'queueNo' : undeclared identifier g:\system\system\number system.cpp

Error 5 error C3867: 'Data::time': function call missing argument list; use '&Data::time' to create a pointer to member g:\system\system\number system.cpp

Error 6 error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(const std::basic_string<_Elem,_Traits,_Ax> &)' : cannot convert parameter 1 from 'int (__thiscall Data::* )(void)' to 'const std::basic_string<_Elem,_Traits,_Ax> &' g:\system\system\number system.cpp

Error 7 error C2664: 'char std::basic_ios<_Elem,_Traits>::fill(_Elem)' : cannot convert parameter 1 from 'const char [2]' to 'char' g:\system\system\number system.cpp

Error 8 error C2065: 'queueNo' : undeclared identifier g:\system\system\number system.cpp

Error 9 error C2664: 'char std::basic_ios<_Elem,_Traits>::fill(_Elem)' : cannot convert parameter 1 from 'const char [2]' to 'char' g:\system\system\number system.cpp

Error 10 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) g:\system\system\number system.cpp

Error 11 error C2661: 'Data::Data' : no overloaded function takes 2 arguments g:\system\system\number system.cpp

Error 13 error C3867: 'std::queue<_Ty>::pop': function call missing argument list; use '&std::queue<_Ty>::pop' to create a pointer to member g:\system\system\number system.cpp

Error 14 error C2664: 'char std::basic_ios<_Elem,_Traits>::fill(_Elem)' : cannot convert parameter 1 from 'const char [2]' to 'char' g:\system\system\number system.cpp

16 IntelliSense: explicit type is missing ('int' assumed) g:\system\system\number system.cpp

17 IntelliSense: expected a type specifier g:\system\system\number system.cpp

18 IntelliSense: identifier "queueNo" is undefined g:\system\system\number system.cpp

19 IntelliSense: no suitable constructor exists to convert from "int (<error-type>)" to "std::basic_string<char, std::char_traits<char>, std::allocator<char>>" g:\system\system\number system.cpp

20 IntelliSense: no instance of overloaded function "std::basic_ostream<_Elem, _Traits>::fill [with _Elem=char, _Traits=std::char_traits<char>]" matches the argument list g:\system\system\number system.cpp

21 IntelliSense: identifier "queueNo" is undefined g:\system\system\number system.cpp

22 IntelliSense: no instance of overloaded function "std::basic_ostream<_Elem, _Traits>::fill [with _Elem=char, _Traits=std::char_traits<char>]" matches the argument list g:\system\system\number system.cpp

23 IntelliSense: no operator "<<" matches these operands g:\system\system\number system.cpp

24 IntelliSense: no instance of constructor "Data::Data" matches the argument list g:\system\system\number system.cpp

25 IntelliSense: a pointer to a bound function may only be used to call the function g:\system\system\number system.cpp

26 IntelliSense: no instance of overloaded function "std::basic_ostream<_Elem, _Traits>::fill [with _Elem=char, _Traits=std::char_traits<char>]" matches the argument list g:\system\system\number system.cpp
Without line numbers (in either your error message, or your posted code - which we'd have if you edited your original post to use code tags), I'm having to guess which lines the messages relate to.

It looks as though the first two are about the line:

int time (&currentTime);

That's not a valid declaration of a method, because you haven't specified the type of the argument.

It's a feature of C++ compilers that, often, a single syntax error can invalidate large parts of the rest of the file, and cause a whole load of errors to be reported. If you fix that first error, and recompile, you might find a lot of other errors disappear, too.

Sorry...i have insert the lines.

Error 1 error C2059: syntax error : '&' g:\system\system\number system.cpp line 12


Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int g:\system\system\number system.cpp line 12

Error 4 error C2065: 'queueNo' : undeclared identifier g:\system\system\number system.cpp line 16

Error 5 error C3867: 'Data::time': function call missing argument list; use '&Data::time' to create a pointer to member g:\system\system\number system.cpp line 21

Error 6 error C2664: 'std::basic_string<_Elem,_Traits,_Ax>::basic_string(const std::basic_string<_Elem,_Traits,_Ax> &)' : cannot convert parameter 1 from 'int (__thiscall Data::* )(void)' to 'const std::basic_string<_Elem,_Traits,_Ax> &' g:\system\system\number system.cpp line 21

Error 7 error C2664: 'char std::basic_ios<_Elem,_Traits>::fill(_Elem)' : cannot convert parameter 1 from 'const char [2]' to 'char' g:\system\system\number system.cpp line 25

Error 8 error C2065: 'queueNo' : undeclared identifier g:\system\system\number system.cpp line 26

Error 9 error C2664: 'char std::basic_ios<_Elem,_Traits>::fill(_Elem)' : cannot convert parameter 1 from 'const char [2]' to 'char' g:\system\system\number system.cpp line 63

Error 10 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion) g:\system\system\number system.cpp line 64

Error 11 error C2661: 'Data::Data' : no overloaded function takes 2 arguments g:\system\system\number system.cpp line 67

Error 13 error C3867: 'std::queue<_Ty>::pop': function call missing argument list; use '&std::queue<_Ty>::pop' to create a pointer to member g:\system\system\number system.cpp line 88

Error 14 error C2664: 'char std::basic_ios<_Elem,_Traits>::fill(_Elem)' : cannot convert parameter 1 from 'const char [2]' to 'char' g:\system\system\number system.cpp line 95

16 IntelliSense: explicit type is missing ('int' assumed) g:\system\system\number system.cpp line 12

17 IntelliSense: expected a type specifier g:\system\system\number system.cpp line 12

18 IntelliSense: identifier "queueNo" is undefined g:\system\system\number system.cpp line 16

19 IntelliSense: no suitable constructor exists to convert from "int (<error-type>)" to "std::basic_string<char, std::char_traits<char>, std::allocator<char>>" g:\system\system\number system.cpp line 21

20 IntelliSense: no instance of overloaded function "std::basic_ostream<_Elem, _Traits>::fill [with _Elem=char, _Traits=std::char_traits<char>]" matches the argument list g:\system\system\number system.cpp line 25

21 IntelliSense: identifier "queueNo" is undefined g:\system\system\number system.cpp line 26

22 IntelliSense: no instance of overloaded function "std::basic_ostream<_Elem, _Traits>::fill [with _Elem=char, _Traits=std::char_traits<char>]" matches the argument list g:\system\system\number system.cpp line 63

23 IntelliSense: no operator "<<" matches these operands g:\system\system\number system.cpp line 64

24 IntelliSense: no instance of constructor "Data::Data" matches the argument list g:\system\system\number system.cpp line 67

25 IntelliSense: a pointer to a bound function may only be used to call the function g:\system\system\number system.cpp line 88

26 IntelliSense: no instance of overloaded function "std::basic_ostream<_Elem, _Traits>::fill [with _Elem=char, _Traits=std::char_traits<char>]" matches the argument list g:\system\system\number system.cpp line 95
Line 12: What are you trying to do with this line? It looks like a function prototype with a missing argument type, or that you're trying to initialize the variable in the class declaration, which you can't do.

Line 22: You've declared time as an int. The return type of your function is string. You can't return an int when the return type is a string.

Line 26,64,96: fill expects a char, not quoted string. i.e. Use '0', not "0".

Line 65: You're trying to do a cout of a string, but you did not include the <string> header.

Line 68: You're trying to invoke a constructor for Data that takes two arguments, but you have no constructors in you class declaration.

Line 89: pop is missing the ().

Line 120: Statement has no effect. Assume you meant =, not -.

You have been asked to use code tags. PLEASE DO SO.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
It makes it easier to read and respond to your post.
Last edited on
I am sorry I don't understand the suggestion you have given about line 12. I have corrected some of the errors with your help. Thank you very much.

Error 1 error C2059: syntax error : '&' c:\users\sw095640\documents\visual studio 2008\projects\ir\ir\asa.cpp line 13

Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int c:\users\sw095640\documents\visual studio 2008\projects\ir\ir\asa.cpp line 13

Error 4 error C3867: 'Data::time': function call missing argument list; use '&Data::time' to create a pointer to member c:\users\sw095640\documents\visual studio 2008\projects\ir\ir\asa.cpp line 23

Error 5 error C2440: 'return' : cannot convert from 'int (__thiscall Data::* )(void)' to 'int' c:\users\sw095640\documents\visual studio 2008\projects\ir\ir\asa.cpp line 23

Error 6 error C3867: 'Data::time': function call missing argument list; use '&Data::time' to create a pointer to member c:\users\sw095640\documents\visual studio 2008\projects\ir\ir\asa.cpp line 28

Error 7 error C2661: 'Data::Data' : no overloaded function takes 2 arguments c:\users\sw095640\documents\visual studio 2008\projects\ir\ir\asa.cpp line 70

I am sorry I don't understand the suggestion you have given about line 12.


To repeat myself:

That's not a valid declaration of a method, because you haven't specified the type of the argument.
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#include <iostream>
#include <queue>
#include <ctime>
#include <iomanip>

using namespace std;

class Data{
public:
    Data( int count, string time)
    {
    }
    
    queue <int> q;
    time_t currentTime;
    int time (currentTime);
    int queueNo;
    
    int getNo()
    {
        return queueNo;
    }
    
    string getTime()
    {
        return time;
    }
    
    void toString()
    {
        cout.fill('0'); // <--
        cout << setw(4) << queueNo<<" "<< time;
    }
};




int main() // <-
{
    queue<Data>d;
    char time2[10];
    string time3;
    int count = 1000;
    char serve;
    char exit;
    
    int selection = 0;
    int flag = 0;
    
    while (flag == 0)
    {
        cout << "\t\t\t\tQueue Number System" << endl;
        cout << "\t\t\t\t1)Generate Queue" << endl;
        cout << "\t\t\t\t2)Get total waiting customers" << endl;
        cout << "\t\t\t\t3)Display all waiting customers" << endl;
        cout << "\t\t\t\t4)Serve customer" << endl;
        cout << "\t\t\t\t5)Exit" << endl;
        cout << "Enter Your Selection :";
        cin >> selection;
        
        if(selection == 1)
        {
            cout << endl;
            cout << endl;
            count++;
            strftime(time2);
            time3 = time2;
            cout.fill('0'); // <--
            cout << "The queue number is " << setw(4) << count << " at time " << time3 << endl;
            cout << endl;
            cout << endl;
            
            Data data(count, time3); // <--
            d.push(data);// <--
            
        }
        else if (selection == 2)
        {
            cout << endl;
            cout << endl;
            cout << "The number of waiting customer is " << d.size() << endl;
            cout << endl;
            cout << endl;
        }
        else if (selection == 3)
        {
            cout << endl;
            cout << endl;
            cout << "Name Time" << endl;
            for (int i = 0; i < d.size(); i++)
            {
                d.front().toString();
                cout << endl;
                d.push(d.front());
                d.pop(); // <--
            }
        }
        else if (selection == 4)
        {
            cout << endl;
            cout << endl;
            cout.fill('0');// <--
            cout << "Customer " << setw(4) << d.front().getNo();
            cout << " is served? Yes or No? (Y/N)" << endl;
            cin >> serve;
            
            if (toupper(serve) == 'Y')
            {
                d.pop();
            }
            cout << endl;
            cout << endl;
        }
        else if (selection == 5)
        {
            cout << endl;
            cout << endl;
            if (!d.empty())
            {
                cout << "Warning list is not empty. Proceeding will cause list to be deleted" << endl;
                cout << "Proceed? Yes or No (Y/N)" << endl;
                cin >> exit;
                if (toupper(exit) == 'Y')
                    flag = 1;
                else
                    flag = 0; // <--
            }
        }
    }
}


There are still a couple of errors lines 16 and 67, but they will be repairable if you explain what you are trying to do. You'll also need to sort out the Data constructor at line 10 also.
Last edited on
ok guys this is the question, i m really stuck at this code so can you help plss...

You are to write a Queue Number System for a One Man Operation (OMO) service counter (e.g registration counter, helpdesk etc.). General requirements are as follows:
1) When a customer comes in, the staff will generate queue number and give it to the customer (assume printing is available). Program will record the queue number and the time it is generated (i.e. in a suitable data structure).
2) Customers have to wait until their numbers are called.
3) Using the program, staff can:
a. Get the total number of waiting customers in queue
b. Display all customers in queue
c. Serve a customer – this will show the queue number to be served and update the queue list.
d. Exit – program will prompt user if the queue is not empty
i did the code nearly but somewhere i stucked and cant understand the it.
We're happy to help fix problems with code you've written, but we're not going to write your code for you. This is not a homework site.

Have you fixed the problems that have been explained to you?
closed account (48T7M4Gy)
Well, I can understand what you are saying about getting complicated and what I would suggest is you keep what you have but go through it and put comments (// ...) in and make it clear what the purpose is or what you are trying to do with the next few lines of code you are commenting on. It is better to write code with too many comments than none at all.

So, the first step is show us with your comments which parts of your code do 1) above. Then 2 etc.

Also your Data class doesn't need to contain the queue. Think about it but you need a queue filled with Data objects and the queue can be in main(). there only needs to be 1 queue, not one for every object. Each data object has the time and sequence number, that's all.

BTW use the <> tags to insert your code here. This is explained http://www.cplusplus.com/forum/articles/42672/


okok thank you i will makesure correct the error and try to solve it.. thank you again
closed account (48T7M4Gy)
It's late for me here. Good luck. I can look in about 8hrs.
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <ctime>
#include <queue>
#include <iostream>
#include <string>

class Data
{
    
public:
    Data(int pos, time_t tm)
    {
        position = pos;
        time = tm;
    }
    
    int getPosition()
    {
        return position;
    }
    
    time_t getTime()
    {
        return time;
    }
    
    std::string toString()
    {
        return "Position: " + std::to_string(position) + " Time: " + asctime(localtime(&time));
    }
    
private:
    int position;
    time_t time;
    
};

int main()
{
    // create queue
    std::queue<Data> dq;
    
    // create time structure
    time_t timer;
    
    // initialise position number
    int qPosition = 0;
    
    // create and test a Data object
    Data dat1 = Data( qPosition, time(&timer));
    std::cout << dat1.getPosition() << ' ' << dat1.getTime() << std::endl;
    
    // test data queue
    dq.push(dat1);
    
    for(int i = 0; i < 5; i++)
        dq.push( Data( ++qPosition, timer + i*1000 ) );
    
    std::cout << dq.size() << " people in the queue." << std::endl;
    
    //list all people in the queue (dequeue would be better)
    int limit = (int)dq.size();
    for ( int i = 0; i < limit; i++ )
    {
        std::cout << dq.front().toString();
        dq.push(dq.front());
        dq.pop();
    }
}
Topic archived. No new replies allowed.