LNK2019 Error. Using classes and arrays to create a cash register database DUE IN A FEW HOURS :(

I have an assignment to create a data base for a cash register. We are eventually supposed to use two classes but I was doing one at a time. I am just trying to have my main program initialize the database with little information. The InentoryItem.h and .cpp are both provided by the instructor. I can not figure out why I keep getting errors on my code. The errors are listed below but they all talk of an unresolved external error. Could someone please provide a bit of guidance to me?

//InentoryItem.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
36
37
38
39
40
41
42
43
44
  #ifndef INVENTORYITEM_H
#define INVENTORYITEM_H
#include <cstring>   // Needed for strlen and strcpy

// Constant for the description's default size
const int DEFAULT_SIZE = 51;

class InventoryItem
{
private:
   const char *description;  // The item description
   double cost;        // The item cost
   int units;          // Number of units on hand
   
   // Private member function.
   void createDescription(int size, char *value);


public:
   // Constructor #1
   InventoryItem();

   // Constructor #2
   InventoryItem(const char *desc);
 
   // Constructor #3
   InventoryItem(const char *desc, double c, int u);
        
   // Destructor
   ~InventoryItem();

   // Mutator functions
   void setDescription(const char *d);
   void setCost(double c);
   void setUnits(int u);

   // Accessor functions
   const char *getDescription() const; 
   double getCost() const;
   int getUnits() const;

};

#endif 




//InventoryItem.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
  #include "InventoryItem.h"

// Private member function.
void InventoryItem::createDescription(int size, char *value)
{ 
    // Allocate the default amount of memory for description.
    description = new char [size];

    // Store a value in the memory.
    strcpy(description, value); 
}

// Constructor #1
InventoryItem::InventoryItem()
{ 
    // Store an empty string in the description
    // attribute.
    createDescription(DEFAULT_SIZE, "");

    // Initialize cost and units.
    cost = 0.0;
    units = 0; 
}

// Constructor #2
InventoryItem::InventoryItem(const char *desc)
{ 
    // Allocate memory and store the description.
    createDescription(strlen(desc), desc); 

    // Initialize cost and units.
    cost = 0.0;
    units = 0;
}

// Constructor #3
InventoryItem::InventoryItem(const char *desc, double c, int u)
{ 
    // Allocate memory and store the description.
    createDescription(strlen(desc), desc); 

    // Assign values to cost and units.
    cost = c;
    units = u; 
}      

// Destructor
InventoryItem::~InventoryItem()
{
    delete [] description; 
}

// Mutator functions
void InventoryItem::setDescription(const char *d) 
{
    strcpy(description, d); 
}

void InventoryItem::setCost(double c)
{
    cost = c; 
}

void InventoryItem::setUnits(int u)
{
    units = u; 
}

// Accessor functions
const char *InventoryItem::getDescription() const
{
    return description; 
}

double InventoryItem::getCost() const
{
    return cost; 
}

int InventoryItem::getUnits() const
{
    return units; 
}



//Main.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
  #include"CashRegister.h"
#include "InventoryItem.h"

void main()
{
//use the inventory item class to create a database
	//use array to store the name, units on hand and cost
	//adjustable wrench, screwdriver, pliers, rachet, socket wrench (5 total)
	const int AMT = 5;
	InventoryItem tools[AMT] =
	{
		InventoryItem(),									//using default constructor
		InventoryItem("Screwdriver"),						//using constructor 2
		InventoryItem("Pliers", 3.75, 35),
		InventoryItem("Rachet", 5.40, 10),
		InventoryItem("Socket Wrench", 5.00, 7)
	};

	char toolA[DEFAULT_SIZE] = "Adjustable Wrench";			//using default constructor
	tools[0].setDescription(toolA);
	tools[0].setCost(4.75);
	tools[0].setUnits(10);

	tools[1].setCost(2.20);									//usinf constructor 2
	tools[1].setUnits(20);


//DISPLAY MENU
	cout << left << "#" << setw(5) << "Item" << setw(20) << "qty on Hand" << endl;
	cout << "----------------------------------------------------------------------";

	system("pause");
}


//ERROR CODES
1
2
3
4
5
6
7
8
9
10
11
12
  1
1>Main.cpp
1>c:\users\jbrin\desktop\ciss-242\week 7 assignment 2 (cash register)\week 7 assignment 2 (cash register)\main.cpp(19): warning C4326: return type of 'main' should be 'int' instead of 'void'
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall InventoryItem::InventoryItem(void)" (??0InventoryItem@@QAE@XZ) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall InventoryItem::InventoryItem(char const *)" (??0InventoryItem@@QAE@PBD@Z) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall InventoryItem::InventoryItem(char const *,double,int)" (??0InventoryItem@@QAE@PBDNH@Z) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "public: __thiscall InventoryItem::~InventoryItem(void)" (??1InventoryItem@@QAE@XZ) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "public: void __thiscall InventoryItem::setDescription(char const *)" (?setDescription@InventoryItem@@QAEXPBD@Z) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "public: void __thiscall InventoryItem::setCost(double)" (?setCost@InventoryItem@@QAEXN@Z) referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol "public: void __thiscall InventoryItem::setUnits(int)" (?setUnits@InventoryItem@@QAEXH@Z) referenced in function _main
1>C:\Users\Jbrin\Desktop\CISS-242\Week 7 Assignment 2 (Cash Register)\Debug\Week 7 Assignment 2 (Cash Register).exe : fatal error LNK1120: 7 unresolved externals
1>Done building project "Week 7 Assignment 2 (Cash Register).vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Last edited on
Seems you didn't include InventoryItem.cpp in your project, so the linker can't find the functions.
Also change void main() to int main()
It looks like InventoryItem.cpp isn't propperly or at all added to your project.
Topic archived. No new replies allowed.