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
#ifndef BAG_H
#define BAG_H
#include <iostream>
#include <vector>
usingnamespace std;
constint 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
#include <iostream>
#include <vector>
#include <cctype>
#include <string>
usingnamespace 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
returnfalse;
}
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
returntrue;
}
}
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];
}
//------------------------------------------------------------------
// 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
usingnamespace 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
booloperator < (const bankAccount & left, const bankAccount & right);
booloperator == (const bankAccount & left, const bankAccount & right);
booloperator != (const bankAccount & left, const bankAccount & right);
booloperator <= (const bankAccount & left, const bankAccount & right);
booloperator > (const bankAccount & left, const bankAccount & right);
booloperator >= (const bankAccount & left, const bankAccount & right);
#endif // ifndef BACCOUNT_H