unresolved external errors-in bag::sort program

I am to write out a bag.h and bag.cpp and test if it is working correctly. I did this with two other testers and it compiled perfectly however when I try this one I get these errors;(I hope I posted correctly , this is my first time)
Error	1	error LNK2019: unresolved external symbol "public: class bankAccount __thiscall bag::currentItem(void)const " (?currentItem@bag@@QBE?AVbankAccount@@XZ) referenced in function _main	C:\Users\bigmamma\Documents\Visual Studio 2010\Projects\C++ HW\11C bag sort\11C bag sort\test11c.obj	11C bag sort
Error	2	error LNK2019: unresolved external symbol "public: void __thiscall bag::add(class bankAccount)" (?add@bag@@QAEXVbankAccount@@@Z) referenced in function _main	C:\Users\bigmamma\Documents\Visual Studio 2010\Projects\C++ HW\11C bag sort\11C bag sort\test11c.obj	11C bag sort


my bag.h file
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
#ifndef BAG_H
#define BAG_H
#include <iostream>
#include <vector>

using namespace std;

const int DEFAULT_INITIAL_BAG_CAPACITY = 16;

class bag {
public:
	//--constructors
	bag();
	// post: Size of this bag is 0. 
	// Initial capacity == DEFAULT_INITIAL_BAG_CAPACITY 

	bag(int initCapacity);
	// pre:  initCapacity >= 1
	// post: size of this bag is bag to 0 with the capacity 
	//       to store initCapacity BAG_ELEMENT_TYPE objects 

	//--modifiers
	void add(BAG_ELEMENT_TYPE newElement); 
	// post: Add newElement to this bag and increase 
	//       the size of this bag object increased by +1.
	//       Note: If capacity < size, the bag doubles it capacity

	bool remove(BAG_ELEMENT_TYPE removalCandidate);
	// post: If found, removalCandidate is removed from this bag.

	int occurrencesOf(BAG_ELEMENT_TYPE matchValue);

	void sort();

	//--accessors

	int capacity() const;
	// post: return the maximum number of elements that could be stored in this bag

	int size() const;
	// post: return the number of elements that are currently in this bag
	//       the number of objects added but not removed.

	bool isEmpty () const;
	// post: Returns true if there are zero items in the bag.
	//       Returns false if there is one more added elements

	//--iterator functions
	void first()const;
	// post: my_index points to the first item

	// Cast away const so this appears to not modify the object
	// This is the only situation this trick should be used to subvert the meaning of const
	//((bag*)this)->my_index = 0;

	void next()const;
	// post: my_index points to the next item

	// Cast away const so this appears to not modify the object
	// This is the only situation this trick should be used to subvert the meaning of const
	// ((bag*)this)->my_index++;

	bool isDone() const;
	// post: Returns true if the collection has been traversed 

	BAG_ELEMENT_TYPE currentItem() const;
	// pre:  ! isDone && my_size > 0
	// post: Returns the item pointed to by the my_index

private:
	vector <BAG_ELEMENT_TYPE> my_element;
	int my_size; 
	int my_capacity;
	int my_index;   // an internal cursor for iterating over all elements
	int occurrencesOf(BAG_ELEMENT_TYPE) const;
};
#endif  // #ifndef BAG_H 



my bag.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <iostream>
#include <vector>
#include <cctype>
#include <string>
using namespace std;

typedef string BAG_ELEMENT_TYPE;
#include "bag.h"

bag::bag()
{ // Default is an empty bag with capacity 16
  my_size = 0; my_index = 0;
  my_capacity = DEFAULT_INITIAL_BAG_CAPACITY;
  my_element.resize(my_capacity);
}
bag::bag(int initCapacity)
{ // Create an empty bag of any capacity desired
  my_size = 0; my_index = 0; 
  my_capacity = initCapacity;
  my_element.resize(my_capacity);
}
void bag::add(BAG_ELEMENT_TYPE newElement)
{// First, increase the bag capacity if necessary
  if (my_size = my_element.capacity())
  {
    my_element.resize(2 * my_element.capacity());
  }
  // Store argument into vector of BAG_ELEMENT_TYPEs...
  my_element[my_size] = newElement;
  // ...and make sure my_size is always increased by +1:
  my_size++;
}

void bag::sort()
{
	BAG_ELEMENT_TYPE temp;
  for(int top = 0; top < my_size-1; top++)
  {
    for(int j = top+1; j < my_size; j++)
    {
     if(my_element[j] < my_element[top])
     {
      temp = my_element[top];
      my_element[top] = my_element[j];
      my_element[j] = temp;
     }
    }
  } 
}

bool bag::remove(BAG_ELEMENT_TYPE removalCandidate)
{
  int subscript = 0;
  // Sequentially search for removalCandidate
  while((subscript < my_size) && (my_element[subscript] != removalCandidate))
  {
     subscript++;
  }
 if(subscript == my_size)
	 {// removalCandidate not found
    return false;
	 }
  else 
  { // move last element to removalCandidate's spot
    for(int j = subscript+1; j < my_size; j++)
    {
    my_element[j-1] = my_element[j];
    }
    my_size--;
    // report success to the message sender
    return true;
  }
}
int bag::occurrencesOf(BAG_ELEMENT_TYPE matchValue)
{
  int results = 0;
  for (first(); !isDone(); next())
  {
     if (matchValue == currentItem())
     {
            results++;
     }
  }
   return results;         
}
int bag::capacity() const
{ // Return how many elements could be stored
  return my_element.capacity(); 
}

int bag::size() const
{ // Return how many elements are in the bag
  return my_size;
}

bool bag::isEmpty() const
{ // Return true if there are 0 elements in the bag
  return my_size == 0; 
}
void bag::first() const
{ // Set internal index to reference the 1st element
	if(my_size >= 0)
	((bag*)this)->my_index = 0; // This is the idea, see header file
}                               // for correct syntax

bool bag::isDone() const
{ // Return true if previous next was the last element
  return my_index >= my_size;
}

void bag::next()const
{ // Set internal index to reference the next element
  // or to allow isDone to return true
	((bag*)this)->my_index++; // This is the idea, see header file
}             // for correct syntax    

BAG_ELEMENT_TYPE bag::currentItem() const
{ // Set internal index to reference the 1st element
  return my_element[my_index];
}


my test11c.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
#include <iostream>
#include "compfun.h" // For decimals
#include "baccount.h" // Must include baccount before the typedef

typedef bankAccount BAG_ELEMENT_TYPE;
#include "bag.h" // For the bag class

using namespace std;

int main()
{
  bag account;

  account.add( bankAccount("Mellisa", 400) );
  account.add( bankAccount("Miguel", 200) );
  account.add( bankAccount("Bob", 300) );
  decimals(cout, 2);
  account.sort();
  bankAccount anAcct;
  for( account.first(); ! account.isDone(); account.next() )
  {
    anAcct = account.currentItem();       // Output:
    cout.width(8);                        // 300.00 Bob
    cout << anAcct.balance();             // 400.00 Mellisa
    cout << " " << anAcct.name() << endl; // 200.00 Miguel
  }

  system ("pause");
  return 0;
}

you have the l inker error of bank account . so we need to see class bankaccount code .
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
84
85
//--------------------------------------------------------------------
// IMPLEMENTATION FILE: baccount.cpp
//
// Implements 1. class bankAccount member functions
//            2. the six relational operators 
//
//--------------------------------------------------------------------
  // allows for separate compilation if you want
#include <iostream>    // for ostream << and istream >>
#include <string>      // for class string
#include "baccount.h"

using namespace std;
//--constructors
bankAccount::bankAccount()
{
  my_name = "?name?";
  my_balance = 0.0;
}

bankAccount::bankAccount(string initName, double initBalance)
{
  my_name = initName;
  my_balance = initBalance;
}

//--modifiers

void bankAccount::deposit(double depositAmount)
{
  my_balance = my_balance + depositAmount;
}

void bankAccount::withdraw(double withdrawalAmount)
{
  my_balance = my_balance - withdrawalAmount;
}

//--accessors

double bankAccount::balance() const
{
  return my_balance;
}

string bankAccount::name() const
{
  return my_name;
}

//--auxilliary functions
 
//  These non-member functions may be required by standard C++ 
//  container classes such as list. Without all six defined, you will 
//  likely get many cryptic compiletime error messages.

bool operator < (const bankAccount & left, const bankAccount & right)
{
  return left.name() < right.name();
}

bool operator == (const bankAccount & left, const bankAccount & right)
{
  return left.name() == right.name();
}

bool operator != (const bankAccount & left, const bankAccount & right)
{
  return left.name() != right.name();
}

bool operator > (const bankAccount & left, const bankAccount & right)
{
  return left.name() > right.name();
}

bool operator >= (const bankAccount & left, const bankAccount & right)
{
  return left.name() >= right.name();
}

bool operator <= (const bankAccount & left, const bankAccount & right)
{
  return left.name() <= right.name();
}


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
//------------------------------------------------------------------
// INTERFACE FILE: baccount.h
//
// Defines class bankAccount
// Declares the relational operators so bankAccount objects 
//   can be stored in standard containers such as list
//
//-------------------------------------------------------------------
// SAFEGUARDS AND INCLUDES
#ifndef BACCOUNT_H   // Avoid redeclaring class bankAccount.
#define BACCOUNT_H   // This code is compiled only once
#include <string>    // for class string
using namespace std; // avoid having to write std:: as in std::string

///////////////////////////////////////////
/////// class bankAccount defintion ///////
///////////////////////////////////////////

class bankAccount {
public:  // class member functions

//--constructors
  bankAccount();

  bankAccount(string initName, double initBalance);
	// post: A bankAccount with two arguments when called like this:
	//       bankAccount anAcct("Hall", 100.00);

//--modifiers

	void deposit(double depositAmount);
	// post: depositAmount is credited to this object's balance

	void withdraw(double withdrawalAmount);
	// post: withdrawalAmount is debited from this object's balance

//--accessors
	
  double balance() const;
	// post: return this account's current balance

	string name() const;
   // post return the account name

private: 
	string my_name;    // Uniquely identify an object
	double my_balance; // Store the current balance (non-persistent)
};

//--Auxilliary functions

// With these two functions, bankAccount objects can be
// sorted and searched by the standard algorithms
bool operator <  (const bankAccount & left, const bankAccount & right);
bool operator == (const bankAccount & left, const bankAccount & right);
bool operator != (const bankAccount & left, const bankAccount & right);
bool operator <= (const bankAccount & left, const bankAccount & right);
bool operator >  (const bankAccount & left, const bankAccount & right);
bool operator >= (const bankAccount & left, const bankAccount & right);

#endif   // ifndef BACCOUNT_H 
Topic archived. No new replies allowed.