Class Distance project

Ok, i have been able to figure out some stuff with a lot of fustration but now i am getting some really retarted errors things like error, the code exists bullshit.
any ideas?

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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/********************************************************
 *
 *  Project :  <Name of project|assignment>
 *  File    :  <Name of source code file>
 *  Name    :  <Name of programmer>
 *  Date    :  <Date created (project due date)>
 *
 *  Description : (Narrative desciption, not code)
 *
 *    1) What is the purpose of the code; what problem does the code solve.
 *
 *    2) What data-structures are used.
 *
 *    3) What algorithms, techniques, etc. are used in implementing the data structures.
 *
 *    4) What methods are implemented (optional).
 *
 *  Changes :  <Description|date of modifications>
 *
 ********************************************************/

#include <iostream>
#include <string>


using namespace std;

class Distance {
    friend ostream& operator<<(ostream& out, Distance& dist);
    friend istream& operator>>(istream& in, Distance& dist);

private:
    double inches;
    int feet;

public:
    Distance();
    Distance(int ft, double in);
    void setInches(double in);
    double getInches();
    void setFeet(int ft);
    int getFeet();
    bool operator==(Distance& dist);
    Distance operator+(Distance& dist);
    Distance operator-(Distance& dist);
    Distance operator*(Distance& dist);
    void qualifyValues();
    string showDistance();
    double getTotalInches();
};

ostream& operator<<(ostream& out, const Distance& dist)
{
    //cout << *dist.feet << '\'' << *dist.inches << '\"' << endl;
    cout << '\'' <<  '\"' << endl;
    return out;
}

istream& operator>>(istream& in, Distance& dist)
{
    
    return in;
}

Distance::Distance()
{
    feet = 4;
    inches = 5;
    qualifyValues();
}

Distance::Distance(int ft=3, double in=6)
{
    feet = ft;
    inches = in;
    qualifyValues();
    
}

void Distance::setInches(double in)
{
    inches = in;
   
}

double Distance::getInches()
{
    return inches;
}

void Distance::setFeet(int ft)
{
    feet = ft;
}

int Distance::getFeet()
{
    return feet;
}

bool Distance::operator==(Distance& dist)
{
    if (dist.feet == feet && dist.inches == inches)
        return true;
    else
        return false;
}

Distance Distance::operator+(Distance& dist)
{
    int ft = feet + dist.feet;
    double in = inches + dist.inches;

    return Distance(ft, in);
}

Distance Distance::operator-(Distance& dist)
{

    int ft = feet - dist.feet;
    double in = inches - dist.inches;
    while (in < 0)
    {
        if (ft < 0)
        {
            //cout << "ERROR: Negative Distance!" << endl;
        }
        ft = ft - 1;
        in = in + 12;
    }

    return Distance(ft, in);
}

Distance Distance::operator*(Distance& dist)
{
    double in;
    in = this->getTotalInches();
    in = in * dist.getTotalInches();
    return Distance(0, in);
}

void Distance::qualifyValues()
{
    if (feet == 0 && inches == 0)
    {
        cout << "Invalid Distance Parameters, Enter valid values: " << endl;
    //cin >> this;
    }
    while (inches >= 12)
    {
        feet++;
        inches -= 12;
    }
}

string Distance::showDistance()
{
    string a;
    return a;
}

double Distance::getTotalInches()
{
    double in;
    in = feet * 12;
    in += inches;
    return in;
}



with errors:

/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:57: multiple definition of `Distance::Distance(int, double)'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:72: first defined here
build/Debug/GNU-Linux-x86/main.o: In function `Distance::qualifyValues()':
/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:157: multiple definition of `Distance::qualifyValues()'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:144: first defined here
build/Debug/GNU-Linux-x86/main.o: In function `Distance::Distance(int, double)':
/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:57: multiple definition of `Distance::Distance(int, double)'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:72: first defined here
build/Debug/GNU-Linux-x86/main.o: In function `Distance::setInches(double)':
/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:66: multiple definition of `Distance::setInches(double)'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:81: first defined here
build/Debug/GNU-Linux-x86/main.o: In function `Distance::getInches()':
/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:72: multiple definition of `Distance::getInches()'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:87: first defined here
build/Debug/GNU-Linux-x86/main.o: In function `Distance::setFeet(int)':
/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:77: multiple definition of `Distance::setFeet(int)'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:92: first defined here
build/Debug/GNU-Linux-x86/main.o: In function `Distance::getFeet()':
/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:82: multiple definition of `Distance::getFeet()'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:97: first defined here
build/Debug/GNU-Linux-x86/main.o: In function `Distance::operator==(Distance&)':
/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:87: multiple definition of `Distance::operator==(Distance&)'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:102: first defined here
build/Debug/GNU-Linux-x86/main.o: In function `Distance::operator+(Distance&)':
/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:95: multiple definition of `Distance::operator+(Distance&)'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:110: first defined here
build/Debug/GNU-Linux-x86/main.o: In function `Distance::operator-(Distance&)':
/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:103: multiple definition of `Distance::operator-(Distance&)'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:118: first defined here
build/Debug/GNU-Linux-x86/main.o: In function `Distance::operator*(Distance&)':
/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:121: multiple definition of `Distance::operator*(Distance&)'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:136: first defined here
build/Debug/GNU-Linux-x86/main.o: In function `Distance::getTotalInches()':
/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:149: multiple definition of `Distance::getTotalInches()'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:164: first defined here
build/Debug/GNU-Linux-x86/main.o: In function `operator<<(std::ostream&, Distance const&)':
/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:129: multiple definition of `operator<<(std::ostream&, Distance const&)'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:53: first defined here
build/Debug/GNU-Linux-x86/main.o: In function `operator>>(std::istream&, Distance&)':
/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:136: multiple definition of `operator>>(std::istream&, Distance&)'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:60: first defined here
build/Debug/GNU-Linux-x86/main.o: In function `Distance::showDistance()':
/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:143: multiple definition of `Distance::showDistance()'
build/Debug/GNU-Linux-x86/Distance.o:/home/sparx/Projects/C++/Assignment16 attempt 7/Distance.cpp:158: first defined here
Last edited on
Well, thanks everyone for the help. i am now one step closer to failing. have a great weekend
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#include <iostream>
#include <string>

using namespace std;

class Distance {
    // your << and >> operator should have public access
private:
    double inches;
    int feet;

public:
    Distance();
    Distance( int ft = 3 , double in = 6 ); // default parameter values should
	                                        // only exist on the function/constructor
											// definition / prototype
    void setInches(double in);
    double getInches();
    void setFeet(int ft);
    int getFeet();
	//-------
	friend ostream& operator<<(ostream& out, const Distance& dist);
    friend istream& operator>>(istream& in, const Distance& dist);
	//-------
    bool operator==(Distance& dist);
    Distance operator+(Distance& dist);
    Distance operator-(Distance& dist);
    Distance operator*(Distance& dist);
    void qualifyValues();
    string showDistance();
    double getTotalInches();
};

ostream& operator<<(ostream& out, const Distance& dist)
{
    cout << dist.feet << '\'' << dist.inches << '\"' << endl;
    cout << '\'' <<  '\"' << endl;
    return out;
}

istream& operator>>(istream& in, Distance& dist)
{
    return in;
}

Distance::Distance()
{
    feet = 4;
    inches = 5;
    qualifyValues();
}

Distance::Distance(int ft, double in)
{
    feet = ft;
    inches = in;
    qualifyValues();
    
}

void Distance::setInches(double in)
{
    inches = in;
   
}

double Distance::getInches()
{
    return inches;
}

void Distance::setFeet(int ft)
{
    feet = ft;
}

int Distance::getFeet()
{
    return feet;
}

bool Distance::operator==(Distance& dist)
{
    if (dist.feet == feet && dist.inches == inches)
        return true;
    else
        return false;
}

Distance Distance::operator+(Distance& dist)
{
    int ft = feet + dist.feet;
    double in = inches + dist.inches;

    return Distance(ft, in);
}

Distance Distance::operator-(Distance& dist)
{

    int ft = feet - dist.feet;
    double in = inches - dist.inches;
    while (in < 0)
    {
        if (ft < 0)
        {
            //cout << "ERROR: Negative Distance!" << endl;
        }
        ft = ft - 1;
        in = in + 12;
    }

    return Distance(ft, in);
}

Distance Distance::operator*(Distance& dist)
{
    double in;
    in = this->getTotalInches();
    in = in * dist.getTotalInches();
    return Distance(0, in);
}

void Distance::qualifyValues()
{
    if (feet == 0 && inches == 0)
    {
        cout << "Invalid Distance Parameters, Enter valid values: " << endl;
    //cin >> this;
    // this is a pointer, use cin >> feet; and cin >> inches instead
    }
    while (inches >= 12)
    {
        feet++;
        inches -= 12;
    }
}

string Distance::showDistance()
{	/* what are you trying to do here ?
    string a;
    return a;
	*/
	
}

double Distance::getTotalInches()
{
    double in;
    in = feet * 12;
    in += inches;
    return in;
}


Well, thanks everyone for the help. i am now one step closer to failing. have a great weekend


Lol don't feel bad,

the code exists bullshit.


LOL hahaha
Last edited on
Topic archived. No new replies allowed.