Okay here is the bool code that I have so far. It doesn't return any errors and executes. Is this syntax correct? Like will it still work like I think it would?
Can I suggest you forget for a moment the actual code and write down some pseudocode . But only do that after you know what the question is you are trying to answer by sending data to the Artwork object.
Just going back for a second, the scenario might be:
1. I have an Artwork for sale, say picasso. (created in main)
2. I have just received a bid (in main) $201.50 say, from bidderID 2047 for arguments sake. (in main)
3. I want to know if this is the highest bid and if so I need to record who the bidder was.
4. so I send a message from main to picasso as follows,
4a bool answer = picasso.make_bid(201.50, 2047);
4b while at it if the bid is the highest so far, then update both records for picasso and report back (answer = true) that it was the highest bid so far
4c if it's not then report back that (answer = false) (ie not the highest)
5. So, back at main I know answer = true or false whether the bids are rising and a whether a low bid needs to be ignored
Long-winded but I hope that helps. See also above revision listing. (it's equivalent to a sequence diagram IIRC)
Okay so I got the cpp file and the header file figured out. I'm having an issue with using the show function to display information. The information is supposed to be derived from this:
A client submits a work to be auctioned. The company assigns the new item the code 3398. The owner id is 2758. The artist is Andrew Miller. The title is Snowy Day. The minimum bid the client will accept is $75,000 (The second constructor). Use the show member function to display the object.
#include <iostream>
#include "project2_Artwork.h"
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
artwork Art1(9979, 2252);
Art1.show();
cout << "\n" << endl;
artwork Art2(3398, 2758, "Andrew Miller", "Snowy Day", 75,000)
Art2.show();
return 0;
}
You need to give a bit more detail on what the trouble is with the show method.
The one I have, and you don't have to copy it, takes the current Artist (your artist) and prepares a string based on that objects properties and returns that string.
The issue is I don't think I'm using the syntax correctly to show the 2nd artwork input.
The syntax is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include <iostream>
#include "project2_Artwork.h"
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
artwork Art1(9979, 2252);
Art1.show();
cout << "\n" << endl;
artwork Art2(3398, 2758, "Andrew", "Miller", 75000);
Art2.show();
return 0;
}
My concern is what is inside the () of Art2. All this code is do to is take the input inside () and assign it to the variables in the class. Do I need to post all of my code?
void artwork::show()
{
cout << "The artwork ID is: " << artworkID << endl;
cout << "The owner ID is:" << ownerID << endl;
cout << "The artist name is: " << artist_fname + ' ' + artist_lname << endl;
cout << "The Title is:" << title << endl;
cout << "The miminum bid is:" << minBid << endl;
cout << "The current high bid is:" << currentHighBid << endl;
cout << "The bidder ID is:" << bidderID << endl;
}
If you look at the constructor in your OP header file you have artwork(int, int, string, string, string, double) but you haven't got a corresponding definition in the cpp file. Maybe you have in your latest, I don't know. Same for other configurations you may or may not have for the constructor. If you don't have one specifically for the one you have on line 14 immediately above then that may be where it's going wrong or it's not clear to you.
You must have a constructor that follows that prototype and sets the attributes or set them with set methods and that's the hard way and probably going to lose you marks. (unless you have defaults but put that aspect to one side for another time :) )
Your show() method you just posted won't cout the attributes unless you have the appropriate constructor as I mentioned or if you set them with the appropriate set method.
#include "project2_Artwork.h"
#include <string>
#include <iostream>
usingnamespace std;
void artwork::set_artist (string fname, string lname)
{
artist_fname = fname;
artist_lname = lname;
}
void artwork::set_title (string T)
{
title = T;
}
void artwork::set_minBid(double mBid)
{
minBid = mBid;
}
int artwork::get_artworkID()
{
return artworkID;
}
int artwork::get_ownerID()
{
return ownerID;
}
string artwork::get_artist()
{
return artist_fname + ' ' + artist_lname;
}
string artwork::get_title()
{
return title;
}
double artwork::get_minBid()
{
return minBid;
}
void artwork::show()
{
cout << "The artwork ID is: " << artworkID << endl;
cout << "The owner ID is:" << ownerID << endl;
cout << "The artist name is: " << artist_fname + ' ' + artist_lname << endl;
cout << "The Title is:" << title << endl;
cout << "The miminum bid is:" << minBid << endl;
cout << "The current high bid is:" << currentHighBid << endl;
cout << "The bidder ID is:" << bidderID << endl;
}
bool artwork::make_bid(double aBid, int bidID)
{
bool found = true;
if(aBid >= minBid && aBid > currentHighBid)
{
currentHighBid = aBid;
bidderID = bidID;
found = true;
return found;
}
else
{
found = false;
return found;
}
}
artwork::artwork(int aw, int oi)
{
artworkID = aw;
ownerID = oi;
artist_fname = "";
artist_lname = "";
title = "";
minBid = 0.0;
currentHighBid = 0.0;
bidderID = 0;
}
artwork::artwork(int aw, int oi, string z, string x, string u, double b)
{
artworkID = aw;
ownerID = oi;
artist_fname = z;
artist_lname = x;
title = u;
minBid = b;
currentHighBid = 0.0;
bidderID = 0;
}
Project2_main.coo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include "project2_Artwork.h"
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
artwork Art1(9979, 2252);
Art1.show();
artwork Art2(3398, 2758, "Andrew", "Miller", 75000);
Art2.show();
return 0;
}
@kemort thanks for pointing that out. It works like a charm now. Now I'm having an issue with another portion of the code
Here is what is supposed to happen:
• A bid has been made on artwork 9979. Use the make_bid member function to bid $60,000. Display a message indicating whether or not the bid was successful. If the bid is successful, show the updated object reflecting the updated current bid.
I'm having a moment and can't remember how to use the make_bid member function to do this.
Here is my code for this portion
1 2
artwork Art4(0, 9979, "", "", "", 0)
Here is the make_bid code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
bool artwork::make_bid(double aBid, int bidID)
{
bool found = true;
if(aBid >= minBid && aBid > currentHighBid)
{
currentHighBid = aBid;
bidderID = bidID;
found = true;
return found;
}
else
{
found = false;
return found;
}
}
I understand what you are saying @kemort. However our instructor just wants us to get the syntax down. I don't agree with how this course is laid out. I'm just out to understand the material. I know we are supposed to name stuff more meaningful and easy to remember. However, it's the way the instructor has it laid out unfortunately. Also, thank you for the suggestion earlier. I will adapt that to my code and update you tomorrow. :)