Read data from user by object and constructor

Hi everyone,I am trying to finish this assignment. I have a question about car1. How can i assign value from user to car1?
car1 which uses the values read from the user. Use the same values used to test assignment C1.
car2 which is copied from car1.
car3 which is created with the default constructor.

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
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

class Car
{
    string reportingMark;
    int Carnumber=0;
    string kind="other";
    bool loaded=0;
    string destination="NONE";
    int *ptr;
    //~Car(); //destructor


public:
    Car(){setUp();}
    Car(string , int , string , bool , string ){setUp();}
    void setUp ();
    void outPut();


}mycar;

void input (string &reportingMark, int &Carnumber, string &kind, bool &loaded, string &destination);

int main(int argc, const char * argv[])
{

    string reportingMark;
    int Carnumber;
    string kind;
    bool loaded;
    string destination="NONE";
    //Car car;
    Car car1,car2,car3;
    car2=car1;
    car3=Car();
    input(reportingMark,Carnumber,kind,loaded,destination);
    car1.outPut();
    car2.outPut();
    car3.outPut();

    return 0;
}
void input (string &reportingMark, int &Carnumber, string &kind, bool &loaded, string &destination)
{
    cout << "What is your reportingMark: "<< endl;
    cin >> reportingMark;
    cout << "What is your carNumber"<< endl;
    cin >> Carnumber;
    cout << "What is your kind of your car?"<<endl;
    while (kind != "business")
    {
        cin >> kind;

        if (kind != "business" && kind != "maintenance" && kind!= "other")
        {
            cout << "Your input is invalid. Please type again "<<endl;
        }
        else
            break;
    }

    cout << "Is your car loaded: "<<endl;
    cout << "If you say yes please type 1. Otherwise please type 0"<<endl;
    cin >>loaded;
    if (loaded == true)

    {
        cout << "What is your destination: "<<endl;
        cin >> destination;
    }
    else if (loaded == false)
    {
        cout << "What is your destination: "<<endl;
        cin >>destination;
            if(destination == "no")
            {
                cout <<"Thank you"<<endl;
            }
    }
}


void Car::setUp()
{
    mycar.reportingMark=reportingMark;
    mycar.Carnumber=Carnumber;
    mycar.kind=kind;
    mycar.loaded=loaded;
    mycar.destination=destination;

}

void Car::outPut()
{
    cout <<mycar.reportingMark<<endl;
    cout <<mycar.Carnumber<<endl;
    cout <<mycar.kind<<endl;
    cout<<boolalpha<<mycar.loaded<<endl;
    cout <<mycar.destination<<endl;
}

/*Car::~Car()
{}
*/
line 24: mycar is global. Globals should be avoided.

Line 37: You instantiate 3 cars with default constructors which calls setup().

Line 89-93: You're modifying members of the global, not the instance of Car which called setup(). In fact, you're setting the global to the uninitialized values of the instance of Car.

Lines 99-103: You're outputting the members of the global mycar, not the members of the instance which called outPut().

Last edited on
0
other
false
NONE

0
other
false
NONE

0
other
false
NONE

Can you tell me specifically how to fixit I tried for couple hours but i am stuck with those.

Here is my newest code
http://pastebin.com/3Pbmiu5R
Topic archived. No new replies allowed.