Hi guys, need some help in writing a progrom to test my code. Currently, what i have written for the header file is this

#ifndef _VENDMACHINE_H_
#define _VENDMACHINE_H_

#include <string>
class VendMachine
{
private:
string item;
int numberOfItems;
int cost;

public:
VendMachine(string s, int = 50, int = 50);
void setItem(string);
string getItem();
void setNumberOfItems(int);
int getNumberOfItems();
void setCost(int);
int getCost();
void makeSale(int=1);

};

#endif

my methods and declaration

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

#include "vendMachine.h"	

VendMachine::VendMachine(string s, int n, int c) {
item = s;
numberOfItems = n;
cost = c;
}

void VendMachine::setItem(string s){
item = s;
}

string VendMachine::getItem(){
return item;
}

void VendMachine::setNumberOfItems(int n){
numberOfItems = n;
}

int VendMachine::getNumberOfItems(){
return numberOfItems;
}

void VendMachine::setCost(int c){
cost = c;
}

int VendMachine::getCost(){
return cost;
}

void VendMachine::makeSale(int i){
numberOfItems = numberOfItems -i;

}

currently i'm given a function prototype sellProduct

void sellProduct(vendMachine& product);

and this

#include <iostream>
#include "vendMachine.h"
using namespace std;
void sellProduct(vendMachine& product);
int main()
{
vendMachine coke("coke", 2, 50);
vendMachine pesi("pesi", 20, 65);
vendMachine gum("snack", 50, 45);
vendMachine chips("chips", 50, 85);
cout << "user name Program Output: " << endl;
cout << "============================" << endl;
while (true)
{
sellProduct(coke);
sellProduct(pesi);
sellProduct(gum);
sellProduct(chips);
}
cin.ignore();cin.ignore();
return 0;
}

and i keep getting this
error LNK2019: unresolved external symbol "void __cdecl sellProduct(class VendMachine &)" (?sellProduct@@YAXAAVVendMachine@@@Z) referenced in function _main
when i run the program..anyone can help?
Thanks in advance

Recommended Answers

All 7 Replies

oh sorry and i miss out that i'm supposed to write the code for sellProduct to balance number of items as well

Add VendMachine.cpp to your project. What compiler are you using?

Add VendMachine.cpp to your project. What compiler are you using?

using microsoft c++ express. i already had one vendMachine.h under the header file and one vendMachine.cpp and one vendMachineTest.cpp under the source file.

anyone can help? i have no idea how to start off the sellProduct code also..thanks in advance

I think the problem may be the way you're abstracting the code.

Why are vending machines named after specific products? Why not have a Vending machine that CONTAINS products (and a certain amount of them), and when a sale is made the product amount for that particular product is deducted and the ProfitChange amount increases by the amount the product is sold for.

I think the problem may be the way you're abstracting the code.

Why are vending machines named after specific products? Why not have a Vending machine that CONTAINS products (and a certain amount of them), and when a sale is made the product amount for that particular product is deducted and the ProfitChange amount increases by the amount the product is sold for.

Thanks for the reply. But the code and the function prototype was given to me to test the codes i have written. Seem like i need to write a code for sellProduct but i have no idea what that mean. Sorry for being so noob, i've just started learn c++. Thanks

Okay, in the real world what happens when a vending machine makes a sale (under ideal conditions)?

-The amount of money the machine has stored goes up (but I do not think your implementation has this feature so it can be ignored?)
-The amount of the product in the machine goes down
-(and if someone steals from the machine, it grows arms and legs and whirls around screaming "DANGER! DANGER Will Robinson!"... okay forget this part)

All you have to do every time you make a sale is check to see if there is at least 1 product left in the machine per transaction and if there is, deduct the amount of that machine by 1.

You should write a function for your class (if you're allowed) that shows the remaining amount of the product in the machine each time you sell a product.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.