Using classes

Pages: 123
Hello C++ forum users. I am having an issue with my code. I have a project and I am having trouble with a few syntax errors. My code is pasted below. Can you guys please assist with the syntax errors? Basically the program is supposed to take input for bidding on artwork and determine the current high bid from the bids made. The code is in three parts. I will list each part in separate code syntax

project2_Artwork.h
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
  #ifndef PROJECT2_ARTWORK_H
#define PROJECT2_ARTWORK_H
#include <string>
#include <iostream>

using namespace std;


class artwork
{
	private:
		int artworkID;
		int ownerID;
		string artist_fname;
		string artist_lname;
		string title;
		double minBid;
		double currentHighBid;
		int bidderID;
	public:
		void set_artist(string, string);
		void set_title(string);
		void set_minBid(double);
		int get_artworkID();
		int get_ownerID();
		string get_artist();
		string get_title();
		double get_minBid();
		void show();
		bool make_bid (double, int);
		artwork(int); 
		artwork(int, int, string, string, string, double);
		
};
#endif 


project2_Artwork.cpp
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
#include "project2_Artwork.h"
#include <string>
#include <iostream>

using namespace std;

void artwork::set_artist (string artist_fname, string artist_lname)
{
	cout << artist_fname << " " << artist_lname;
}

void artwork::set_title (string title)
{
	getline(cin, title);
}

void artwork::set_minBid(double)
{

}

int artwork::get_artworkID(int artworkID)
{
	getline(cin, get_artworkID);
}

int artwork::get_ownerID(int ownerID)
{
	getline(cin, ownerID);
}

string artwork::get_artist()
{
	getline(cin, artist);
}

string artwork::get_title()
{
	getline(cin, title);
}

double artwork::get_minBid()
{
	getline(cin, minBid);
}
void artwork::show()
{
	getline(cin, artworkID);
	getline(cin, ownerID);
	getline(cin, artist);
	getline(cin, title);
	getline(cin, minBid);
	getline(cin, currentHighBid);
	getline(cin, bidderID);
}

bool artwork::make_bid (double, int)
{
	if (make_bid < currentHighBid)
		currentHighBid = currentHighBid;
	else
		make_bid = currentHighBid;
}


project2_main.cpp

This has no syntax yet. I'm focusing on the Artwork.cpp which is where the errors are. This is part of a Project file
I'm focusing on the Artwork.cpp which is where the errors are.

Please post the complete error messages.
closed account (48T7M4Gy)
line 57: bool artwork::make_bid (double ???, int ???) and no returning bool value.

BTW The error messages are still required
Last edited on
The error messages are extremely long. It won't let me post them. :( I have them in a text file. Can I post link to dropbox or something like that here?
Last edited on
Here is the dropbox link. The first number is the line, the second is the column in the text file.

https://www.dropbox.com/s/soes2tc7f7kra2a/errors.txt?dl=0
I realize not all the syntax is here. I know that I will have to pass something into the bool. I'm more worried about the other syntax errors.
closed account (48T7M4Gy)
All you need to do is post the first couple of lines. Usually, and I have run your class on VS2015, the first couple of errors can generate up to thousands of follow-up errors that collapse when the first one in particular is fixed.

A couple of observations so far though aside from the one I posted separately above:

1. 'Artist' is better as a class name than 'artist' - it's clearer and conventional.

2. artist_fname is a redundant way of naming that attribute. fName or fname is better because you already know it refers to an Artist.

3. does the bidderID refer to the lowest or highest, maybe you need two?

4. Classes are better if more general and follow good practice if they don't have cin's and cout's etc because the class becomes tied to a particular system eg the console. It renders it unuseable without modification if you were using it for windows.

For instance ...
Good, works anywhere
1
2
3
4
void Artwork::set_minBid(double aMinBid)
{
   minBid = aMinBid;
}


Not so good, works for console but not for GUI applications
1
2
3
4
void Artwork::set_minBid(double aMinBid)
{
   getLine(cin, minBid);
}


None of these are hard to fix even though it might sound a bit daunting first time around. :)
Last edited on
I have fixed the code so that it only generates 5 lines of errors. Here they are:


In member function 'void artwork::show()':
Line 50 Column 30 F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Project_Artwork\project2_Artwork.cpp [Error] 'artist' was not declared in this scope
F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Project_Artwork\project2_Artwork.cpp In member function 'bool artwork::make_bid(double, int)':
Line 59 Column 17 F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Project_Artwork\project2_Artwork.cpp [Error] invalid use of member function (did you forget the '()' ?)
Line 62 Column 15 F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Project_Artwork\project2_Artwork.cpp [Error] invalid use of member function (did you forget the '()' ?)
31 F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Makefile.win recipe for target 'Project_Artwork/project2_Artwork.o' failed
closed account (48T7M4Gy)
Line 50 Column 30 F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Project_Artwork\project2_Artwork.cpp [Error] 'artist' was not declared in this scope

line 50 is getline(cin, artist);

variable 'artist' doesn't exist

Maybe you meant artist_fname or artist_lname?

Ignore the rest, fix that, recompile and see what errors you get.
Last edited on
The error I get is:

F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Project_Artwork\project2_Artwork.cpp In member function 'bool artwork::make_bid(double, int)':
58 17 F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Project_Artwork\project2_Artwork.cpp [Error] invalid use of member function (did you forget the '()' ?)
61 12 F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Project_Artwork\project2_Artwork.cpp [Error] invalid use of member function (did you forget the '()' ?)
31 F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Makefile.win recipe for target 'Project_Artwork/project2_Artwork.o' failed


I know it is the line below:'

if (make_bid < currentHighBid)
closed account (48T7M4Gy)
F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Project_Artwork\project2_Artwork.cpp In member function 'bool artwork::make_bid(double, int)':


1
2
3
4
bool artwork::make_bid(double, int)';
{
// your function as written by you doesn't return anything!
}


Maybe it should be something like this?
1
2
3
4
5
6
7
8
9
10
bool Artwork::make_bid(double aBid)
{
	if (aBid < currentHighBid)
		return false;
	else
	{
		currentHighBid = aBid;
		return true;
	}
}
Last edited on
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
132
133
134
135
136
137
138
139
140
141
#ifndef PROJECT2_ARTWORK_H
#define PROJECT2_ARTWORK_H

#include <iostream>
#include <string>

using std::string;
using std::cout;
using std::cin;
using std::endl;
using std::to_string;

class Artwork
{
private:
	int artworkID;
	int ownerID;
	string firstName;
	string lastName;
	string title;
	int minBid;
	double currentHighBid;
	int bidderID;
public:
	Artwork(int);
	Artwork(int, int, string, string);
	~Artwork() {};

	void set_artist(string, string);
	void set_title(string);
	void set_minBid(double);

	int get_artworkID();
	int get_ownerID();
	string get_artist();
	string get_title();
	double get_minBid();
	int getBidderID();

	string show();
	bool make_bid(double, int);
};
#endif

Artwork::Artwork(int anID)
{
	artworkID = anID;
}

Artwork::Artwork(int anID, int anOwnerID, string fName, string lName)
{
	artworkID = anID;
	ownerID = anOwnerID;
	firstName = fName;
	lastName = lName;
}

void Artwork::set_artist(string aFname, string aLname)
{
	firstName = aFname;
	lastName = aLname;
}

void Artwork::set_title(string aTitle)
{
	title = aTitle;
}

void Artwork::set_minBid(double aMinBid)
{
	minBid = aMinBid;
}

int Artwork::get_artworkID()
{
	return artworkID;
}

int Artwork::get_ownerID()
{
	return ownerID;
}

string Artwork::get_artist()
{
	return firstName + " " + lastName;
}

string Artwork::get_title()
{
	return title;
}

double Artwork::get_minBid()
{
	return minBid;
}

int Artwork::getBidderID()
{
	return bidderID;
}

string Artwork::show()
{
	string output = "**" + firstName + " ";
	output += lastName + " ";
	output += "Art No.: " + to_string(artworkID) + " ";
	output += "Own No.: " + to_string(ownerID) + " ";
	return output;
}

bool Artwork::make_bid(double aBid, int aBidderID)
{
	if (aBid < currentHighBid)
		return false;
	else
	{
		currentHighBid = aBid;
		bidderID = aBidderID;
		return true;
	}
}

int main()
{
	Artwork picasso(2, 207, "Bob", "Smith");
	cout << picasso.show() << endl;

	double amount = 109.80;
	
	picasso.make_bid(amount, 1234);
	cout << picasso.getBidderID() << " has bid $" << amount << endl;

	if (picasso.make_bid(201.50, 2047) )
		cout << "Bingo " << picasso.getBidderID() << " you're now the highest bidder\n";
	else
		cout << "Sorry " << picasso.getBidderID() << " you bid is invalid\n";

	return 0;
}
**Bob Smith Art No.: 2 Own No.: 207 
1234 has bid $109.8
Bingo 2047 you're now the highest bidder
 
Exit code: 0 (normal program termination)
Last edited on
This is what the bool is supposed to do.


• The class should have a member function called make_bid(…) that sends a bid to the object. This is value returning function and returns a boolean value.
make_bid should accept two parameters: a bid (double) and a bidder id (int).
If the bid is equal to or higher than the minimum bid and the bid is higher than the current high bid, store the bid to current high bid and the bidder's id to bidder id.
If the bid is accepted, the member function should return true. If the bid is not higher than the current high bid, the function should return false.
closed account (48T7M4Gy)
Excellent. I think I understood that was what you were trying to do and it's good to have confirmation.

So rather than me doing it, you can probably see the way to modify what I wrote at my line 107 onwards. There needs to be a second parameter (which is what you have) for the bidder ID which can be set at the same time as seeing whether the current bid is the highest. It's just one extra line in that method
:)
Okay so I can basically just remodify your code to fit what I need it to do? Would that be something like the below correct? Sorry I'm trying to understand this. I don't want answers syntax wise, just hints for a very very beginner programmer.


bool artwork::make_bid(double, int)
{
if (make_bid < currentHighBid)
return bidderID;
return make_bid;
}
kemort wrote:
1. 'Artist' is better as a class name than 'artist' - it's clearer and conventional.

2. artist_fname is a redundant way of naming that attribute. fName or fname is better because you already know it refers to an Artist.


Actually, the class is Artwork not Artist, so I'd add the artist_ prefix back to firstName and lastName as they're attributes of the associated artist and not the work of art itself. (This is in parallel with ownerID.)

Even better, make an Artist class (which has firstName and lastName members) to associate with the Artwork.

But get_ownerID() would be OK as just get_ID(), as it's the ID of the work of art. And get_artist() would be better as get_artistName() -- I'd expect get_artist() to return me a reference or pointer to an Artist object, rather than a name, or ID for that matter. Etc.

Andy

PS From an OO point of view, it would be better to make the Bid a separate class, as you make a bid on a work of art, which suggests there should be a set of Bid class instances that are associated with a single work of art.
Last edited on
closed account (48T7M4Gy)
Andy, yeah, OK it's Artwork, my bad even though my version didn't make that blooper. Thanks for the proof-read, I'm eternally grateful.

Interestingly your later comments combined with that show how ambiguity creeps in and the power of planning and the object approach and its planning analysis help to remove it. I'm loathe to mention UML ...

An Artist and Bid class is a good idea, Buyer, and Painting too if you want to really get amongst it.

Here's a thought, why not Auction, Auctioneer, Sale classes?
I would do that, but we are only to have 1 class. This is for a course. Please keep that in mind. I have been communicating with my instructor but the language barrier is preventing me from learning correctly.
Artwork (or WorkOfArt) is OK as a class name, as the work of art could be a painting, a sculpture, mixed media, "found object art", a music manuscript, etc. But the class as presented is very blurred; a full model would need most if not all of the classes you suggest (or similar.)

But it seems from underoathed's quote about what the make_bid() member function should do that the object model to use for this exercise is being provided by the professor. A pity it's a bit fuzzy from the OO point of view.

Andy
closed account (48T7M4Gy)
Yep, we are only providing advice and there is absolutely no obligation to take it and no harm done if it isn't, I say.

Keeping in mind that the object model, however complex or simple only needs to be fit for purpose, no more. A single class can quite often. if not always be easily extended if future requirements change. One example is my earlier comments on cin's and cout's in class methods and the way to get around it.

:)
Pages: 123