1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(12) : warning C4101: 'znak' : unreferenced local variable
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(25) : warning C4700: uninitialized local variable 'ulazniznak' used
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(30) : warning C4700: uninitialized local variable 'prosloSekundi' used
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(32) : warning C4700: uninitialized local variable 'trenutnostanje' used
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(40) : warning C4700: uninitialized local variable 'ukupnoAuta' used
1>c:\documents and settings\marko\my documents\visual studio 2008\projects\testna\testna\testna.cpp(62) : warning C4700: uninitialized local variable 'ukupnoPjesaka' used

What initial values should I put here?

It debugs, but it says: The variable "ulazniznak" is being used without being initialized.

I made this small C++ program, and it won't compile. Please if someone can help me to fix these 2 errors:

error C2059: syntax error : ';'
error C2059: syntax error : '}'

The text is not in english, but it doesn't metter, just these 2 syntax errors so it can be compiled. Thank you.

#include <iostream>

using namespace std;

int main (){
    int trenutnoStanje;
    int trenutnostanje;
    float prosloSekundi;
    int ukupnoPjesaka;
    int ukupnoAuta;
    char ulazniznak;
    char znak;

    float n=0;
    {

    trenutnoStanje = 2;

    cout<<"\nPocetno trenutno stanje!";
    cout<<"\nautosem: CRVENO";
    cout<<"\npjessem: CRVENO";

     {

        cout<<"\nUčitaj ulazni znak: "<< ulazniznak <<;

        switch (ulazniznak)
        {
            case 'S':
                prosloSekundi++;

                if (trenutnostanje == 0 && prosloSekundi == 3) { 
                    cout<<"\nNovo stanje!";
                    cout<<"\nautosem: CRVENO";
                    cout<<"\npjessem: ZELENO";
                     trenutnostanje=1; 
                    prosloSekundi=0;
                    ukupnoPjesaka = 0;
               }
                else if (trenutnostanje == 1 && ( prosloSekundi == 10 || ( prosloSekundi >=5 && ukupnoAuta>=5 ) ) ) { 
                    cout<<"\nNovo stanje!";
                    cout<<"\nautosem: CRVENO";
                    cout<<"\npjessem: CRVENO";
                    trenutnostanje = 2; 
                    prosloSekundi = 0;
                }
                else if (trenutnostanje == 2 && prosloSekundi == 3) { 
                    cout<<"\nNovo stanje!";
                    cout<<"\nautosem: CRVENO+ZUTO";
                    cout<<"\npjessem: ZELENO";
                    trenutnostanje = 3; 
                    prosloSekundi = 0;
                }
                else if (trenutnostanje == 3 && prosloSekundi == 2) { 
                    cout<<"\nNovo stanje!";
                    cout<<"\nautosem: ZELENO";
                    cout<<"\npjessem: CRVENO";
                    trenutnostanje = 4; 
                    prosloSekundi = 0;
                    ukupnoAuta = 0;
                }
                else if (trenutnostanje == 4 && (prosloSekundi == 30 || (prosloSekundi >= 5 && ukupnoPjesaka >= 5)))
                {
                    trenutnostanje = 5;
                    prosloSekundi = 0;
                    cout<<"\nNovo stanje!";
                    cout<<"\nautosem: ZUTO";
                    cout<<"\npjessem: CRVENO";
                }
                else if (trenutnostanje == 5 && prosloSekundi == 2) { 
                    trenutnostanje = 0; ...

Ok. Thank you. I'll see what can I do with this home assignement.

The above code is what I begin to do. I did it with switch / case, but I don' to really know how to implement this waiting (2 sec for yellow light and the other one). And I reall y don't know am I on the right way.

#include <iostream>

using namespace std;

int main (){
    int selection;
    float pedestriansnmb;
    float carnmb;

    do{
       cout << "\n\nTRAFFIC LIGHT";
       cout<<"\n***********************************************************";
       cout << "\n1. Pedestrian number";
       cout << "\n2. Number of cars)";

       cout << "\n6. Exit";
       cout<<"\n***********************************************************";
       cout << "\nSelect: ";
       cin >> selection;
       cout << endl;

       switch(selection){

                  case 1:
                            pedestriansnmb=0;
                            cout<<"\nPedestrian number is 0. It is green light for cars, and red for pedestrians.";
                            do{
                                cout<<"\n-----------------------------------------------------------";
                                cout<<"\nInsert number of arriving pedestrians.";
                                cout<<"\n-----------------------------------------------------------\n";
                                cin>>n;
                                if (n>4) 
                                {
                                pedestriansnmb=pedestriansnmb+n;

                                cout<<"\nNumber of pedestrians on traffic light is "<< pedestriansnmb <<". It is yellow traffic light for cars, and red for pedestrians. ";
                                }
                                else 
                                {
                                    cout<<"\n\n-----------------------------------------------------------";
                                    cout<<"\n Traffic light state is not changed.";
                                    cout<<"\n-----------------------------------------------------------";
                                }

I'm really a beginner in C++ programming, and the above problem is just a part of c++ excercise. Can somebody give me a tip how to implement this in C++?
The biggest problem for me is to implement and write this:
• red+yellow light on cat traffic light is 2 sec duration
• yellow light on car traffic light is 2 sec duration
• the red on car trafffic light and red on pedestrian traffic light (the simultanuous red light) is 3 sec

How to put wait. The programme just need to write on above probem on the screen.

How can I do this?.. Please if someone can give me example or tip or write a few lines of c++ code, any help would be appreciated.

Thanks.

Traffic light table:

Car traffic light state Pedestrian traffic light state
red green
red red
red+yellow red
green red
yellow red
red red

Traffic lights work like this:
• green light on car traffic light is min. 5 secunds duration, and max Tc=30 sec.
• green light on pedestria traffic light is min. 5 secunds duration , and max. Tp=10 sec
• if there are more then 5 pedestrians on pedestrian traffic light before Tc (30 sec duration for car) the light on traffic light is changing so pedestrians can pass.
• If there are more then 5 cars on car traffic lights before Tp (min. 10 sec. For pedestrians) the light on traffic light is changing so cars may pass
• red+yellow ...

Thank you.

Thank you on your answer. I will mark it as solved.

I've got these 3 questions, I didn't work so far in C++, and this is preparation for my C++ class, These questions are a little tricky and unknown to me, I tried to find the answers in Wikipedia, but I didn't manage, if anyone can answer me, please.

1.1 Can a destructor, defined in a base class, be inherited by a derived class?

1.2 Can a base class destructor be overridden in a derived class?

1.3 Does an abstract class need a contructor?

Thank you very much, I would appreciate all help, and if someone has links with examples where I can see how it works.

What is needed for a C++ member function of a class to behave polymorphic?

Please can anyone answer me to this, and if you can give me some example. Thanks.

Can anybody give me some tip or help me with some part of this problem, thank you.

Write a program which creates N new threads (N is the command line argument). Every thread in the single of M seconds (M is also command line argument) generates random prime number which writes also.

           ./a.out 3 6

thread tid=4, number=22973
thread tid=5, number=10477
thread tid=6, number=25763
thread tid=4, number=7297
thread tid=5, number=15461
thread tid=6, number=28163
thread tid=5, number=28771
thread tid=6, number=15803
thread tid=4, number=11149
thread tid=6, number=19379

Let Wallet be a class that represents the amount of coins and bills in a purse. The class has
got a data element amount of type long. The binary operator += shall be overloaded as an
inline method. Identify the error in the following definition.

Wallet& operator+=(Wallet& w)
{ // add the amount contained in another purse
Wallet this;
this->amount += w.amount;
w.amount = 0L;
return
this;
}

Can somebody explain me this?

OK, thanks.

Let
class Customer
{
private:
long id;
string name;
public:
...
};
be part of a class definition.
What is wrong with the following constructors ?
Customer () { id(0); name(''X''); }
Customer () ( long n, const string& s) : id(s), name(n) { }

Does anyone know this?

Does anyone now answer to this:

Suppose class X includes a data elements common declared as public. How can it be
accessed by all functions in the same name space ?

I understand what are you saying to me, but I cannot make so much effort to solve this by tomorrow, and to completely understand it and to present it, that's why I need someon's help.

I've never programed in C++, and I have just started to learn C++, but I already get a little bit to complicated homeassignement. Is there anyone willing to help me - let's say solve me this excercise. I would appreciate any help with this and if there is anyone willing to solve the whole program, the point is in understanding it for me, so can it be explained, please.

These are 2 connected problems:

  1. Define a class MobilePhone for representing a mobile phone that is given by its device
    name, e.g., Motorola RAZR V3, the owner's name, and the telephone number. To that end,
    please declare three data elements of type string. Furthermore define the following inline
    methods:

– a constructor that initialises each data element,
(please use default values for the owner's name and the telephone number)
– an access method for each data element,
– a method display() that outputs the data elements.
Methods that access an object by reading shall be declared read-only.

  1. Two objects of type MobilePhone are passed to a global function
    exchangeMobilePhone() as arguments. The function exchanges the names of the owners
    and the telephone numbers.

OK. I'll try to solve this. If anyone else can help me it would be great. But, can you explains me this under 6. 6. Suppose class X includes a data elements common declared as public. How can it be
accessed by all functions in the same name space ?

I would appreciate if you or anyone else would have a good will and explain me several more questions. We actually don't need to write programs just to explain some things in c++ (classes)
this question for example

  1. Suppose class X includes a data elements common declared as public. How can it be
    accessed by all functions in the same name space ?

and these first 2 ones ..

  1. Consider the following declarations
    bool func1 (double, double&, double&);
    bool func2 (double, double, double);
    double x = 9.7, y = 0.0, z = 0.0;
    bool res;
    Call each function with arguments x, y, and z. The return value shall be assigned to the
    variable res.

  2. Please write and test a function strReverse() that reverses the order of characters in a given
    string. The string is passed to the function as a read-only reference. The function returns a
    read-only reference to the result.

I will need to present so all help would be appreciated.

I'm not a C++ programmer. I'm a student and I got this question for home assignement and we just started to learn C++ and I couldn't find the answer anywhere. Thanks.

Please can anyone tell me in few words What is wrong with the following class definition? whait's missing, etc.
[code]
Class Numeric
{
private:
long x;
public
...
void set (long n) const { x = n; }
long get () { return x; } const
}
[/code]