Using classes

Pages: 123
closed account (48T7M4Gy)
Yeah do what the instructor says. Play the game because I don't dish out the marks and anyway it's better if it's your own work.

Cheers :)
Hey Kemort,

When I tried modifying the code to make it work with my files I get a compiler error. The error says:

26 9 F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Project_Artwork\Project2_main.cpp [Error] expected unqualified-id before '.' token

Here is my code:

1
2
3
4
5
6
7
8
9
10
11
12
13

	artwork Art4(0, 9979, "", "", "", 0);
	
	double amount = 60000;
	artwork.make_bid(amount, 0);
	cout << artwork.getbidderID	() << " has bid $" << amount << endl;
	
	if (artwork.make_bid(201.50, 2047) )
		cout << "Bingo " << artwork.getbidderID() << " you're now the highest bidder\n" << endl;
	else
		cout << "Sorry " << artwork.getbidderID() << " your bid is invalid\n" << endl;

closed account (48T7M4Gy)
What was the line number and which line number does that line no. correspond to here?
Lines 23-32. Sorry about that. artwork Art4() starts at Line 23.
closed account (48T7M4Gy)
yeah, I'm still unclear which specific line number it refers to so I'll guess that it is reading a double instead of an integer so the parameters don't match
It's probably this line: artwork.make_bid(amount, 0);

artwork is a type not an instance of a type.
closed account (48T7M4Gy)
it should be Art4. make_bid not artwork.make_bid and the same elswhere in calling other methods here
Last edited on
Okay so I tried changing the code to the suggested and it still throws errors.

Error:

Line 23 Column 14 F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Project_Artwork\Project2_main.cpp [Error] expected initializer before '.' token

Here is my code for that line.

1
2

	artwork Art4.make_bid(0, 9979, "", "", "", 0);


Here it is in the entire context

1
2
3
4
5
6
7
8
9
10
11
12

	artwork Art4.make_bid(0, 9979, "", "", "", 0);
	
	double amount = 60000;
	Art4.make_bid(amount, 0);
	cout << artwork.getbidderID	() << " has bid $" << amount << endl;
	
	if (Art4.make_bid(201.50, 2047) )
		cout << "Bingo " << artwork.getbidderID() << " you're now the highest bidder\n" << endl;
	else
		cout << "Sorry " << artwork.getbidderID() << " your bid is invalid\n" << endl;
You need to change all the places where you used artwork instead of Art4 not just that one location.

closed account (48T7M4Gy)
hey, there's jlb even. Did u ever work out where you made that blooper over your sample data?
closed account (48T7M4Gy)
But back to the job in hand underoathed

your line 2 above - delete artwork

lines 6, 9 and 11 artwork should be Art4 . Can you see why?
Is it because we are already calling the class so I don't put the classname.Art4? Also, I corrected the code but it still give me an error

Error:

23 14 F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Project_Artwork\Project2_main.cpp [Error] expected initializer before '.' token

26 2 F:\Class stuff\Programming\Object-Oriented Programming\Homework\Project 2\Project_Artwork\Project2_main.cpp [Error] 'Art4' was not declared in this scope

1
2
3
4
5
6
7
8
9
10
11

	Art4.make_bid(0, 9979, "", "", "", 0);
	
	double amount = 60000;
	Art4.make_bid(amount, 0);
	cout << Art4.getbidderID	() << " has bid $" << amount << endl;
	
	if (Art4.make_bid(201.50, 2047) )
		cout << "Bingo " << Art4.getbidderID() << " you're now the highest bidder\n" << endl;
	else
		cout << "Sorry " << Art4.getbidderID() << " your bid is invalid\n" << endl;
closed account (48T7M4Gy)
line 2 should be artwork Art4( blah blah the same );

1
2
3
4
5
6
7
8
9
10
artwork Art4(0, 9979, "", "", "", 0);                       // create an artwork object called Art4
   
   double amount = 60000;
   Art4.make_bid(amount, 0);                                           // a bid is made for Art4
   cout << Art4.getbidderID() << " has bid $" << amount << endl;         // Art4's latest bidder ID

   if (Art4.make_bid(201.50, 2047) )                            // new bid made, is it a good one
      cout << "Bingo " << Art4.getbidderID() << " you're now the highest bidder\n" << endl;
   else
      cout << "Sorry " << Art4.getbidderID() << " your bid is invalid\n" << endl;
Last edited on
So line 2 should be artwork Art4(0, 9979, "", "", "", 0); correct? What aobut lines 5, 6, 8, 9, and 11? Should they read artwork.make_bid()?

Are these syntax correct?

Line 2 code:
 
artwork Art4(0, 9979, "", "", "", 0);


Line 5-11 code:
1
2
3
4
5
6
7
8
double amount = 60000;
	make_bid(amount, 0);
	cout << artwork.getbidderID	() << " has bid $" << amount << endl;
	
	if (artwork.make_bid(201.50, 2047) )
		cout << "Bingo " << artwork.getbidderID() << " you're now the highest bidder\n" << endl;
	else
		cout << "Sorry " << artwork.getbidderID() << " your bid is invalid\n" << endl;
Last edited on
closed account (48T7M4Gy)
Best way to check is run the program but it looks OK to me. A bit frustrating but you'll get there soon.

Should they read artwork.make_bid()?

No. This has been part of the problem. Only objects can make_bd(), classes can't. The class tells its objects how to make_bid() but don't actually do it.
Topic archived. No new replies allowed.
Pages: 123