0

Here is what I'm trying to do:
Create an Auction class that contains data members for an auction. store these as heap variables. instantiate an auction object on the heap Allow two people to have an auction using a console application once one of the bidders meets the reserve price end the auction and print the high bidders name to the screen. Include a destructor function that cleans up heap variables and prints "AUCTION CLOSED" once the reserve price is reached.

I was able to get rid of all of my errors but when I try to run it I get "Auction.exe has encountered a problem and needs to close. We are sorry for the inconvenience."

here is my code for the header file

#pragma once
#include <iostream>
#include <string>
using namespace std;
class Auction
{
public:
    Auction(void);
    void setauctionitem(string itemname);
    void setname1(string Name1);
    void setname2(string Name2);
    void setbid1(int Bid1);
    void setbid2(int Bid2);
    void setreserve(int reserve);
    int* iReserve;
    string* setitem;
    int* iBid1;
    int* iBid2;
    string* nName1;
    string* nName2;
    int reserve(void);
public:
    ~Auction(void);
};

and my code for the C++ file

#include "Auction.h"
#include <iostream>
#include <string>
using namespace std;
string Name1;
string Name2;
int Bid1;
int Bid2;
Auction::Auction(void)
{
    string* setitem = new string;
    int* iBid1 = new int;
    int* iBid2 = new int;
    string* nName1 = new string;
    string* nName2 = new string;
}
void Auction::setname1(string Name1)
{
    *nName1 = Name1;
}
void Auction::setname2(string Name2)
{
    *nName2 = Name2;
}
void Auction::setbid1(int Bid1)
{
    *iBid1 = Bid1;
}
void Auction::setbid2(int Bid2)
{
    *iBid2 = Bid2;
}
void Auction::setauctionitem(std::string itemname)
{
    *setitem = itemname;
}
void Auction::setreserve(int reserve)
{
    *iReserve = reserve;
}
int Auction::reserve()
{
    return *iReserve;
}

void main() {
    class Auction bid;
    string Name1;
    string Name2;
    int Bid1;
    int Bid2;
    int reserve = 5000;
    bid.setreserve(reserve);
    cout << "The item for sale is" << endl;
    cout << "Insert the first bidder's name: ";
    cin >> Name1;
    bid.setname1(Name1);
    cout << "Insert the second bidder's name: ";
    cin >> Name2;
    bid.setname2(Name2);
    cout << "Enter " << Name1 << "'s bid: ";
    cin >> Bid1;
    bid.setbid1(Bid1);
    cout << "Enter " << Name2 << "'s bid: ";
    cin >> Bid2;
    bid.setbid2(Bid2);
    do {
    cout << "Enter " << Name1 << "'s bid: ";
    cin >> Bid1;
    bid.setbid1(Bid1);
    cout << "Enter " << Name2 << "'s bid: ";
    cin >> Bid2;
    bid.setbid2(Bid2);
    }while(Bid1 < bid.reserve() || Bid2 < bid.reserve());
        if (Bid1 >= bid.reserve()) {
            cout << "The winner of the auction is " << bid.nName1 << endl;
            cout << "The loser of the auction is " << bid.nName2 << endl;
        }
        if (Bid2 >= bid.reserve()) {
            cout << "The winner of the auction is " << bid.nName2 << endl;
            cout << "The loser of the auction is " << bid.nName1 << endl;
        }
        cout << "AUCTION CLOSED" << endl;
}
Auction::~Auction(void)
{
    delete setitem;
    delete iBid1;
    delete iBid2;
    delete nName1;
    delete nName2;
    delete iReserve;
}

thanks for any help

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by ~s.o.s~
0

Make the member variables of the class as normal variables instead of pointers and you should be good to go. And btw, its not a good idea to make the member variables as private since it voilates the OO practices. Write getters and setters and make your data members as private.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.