I am writing this code for class, it is still in progress. I am trying to compile so I can test out the code I have so far. There is code that I temporarily turned into comments to try to fix my compile errors, but no luck. Here are the errors I come up with using Visual Studio.
main.obj : error LNK2028: unresolved token (0A00045A) "public: __thiscall Stack::Stack(void)" (??0Stack@@$$FQAE@XZ) referenced in function "public: void __thiscall Stack::listCommon(class Stack,class Stack)" (?listCommon@Stack@@$$FQAEXV1@0@Z)
1>main.obj : error LNK2028: unresolved token (0A00045B) "public: __thiscall Stack::~Stack(void)" (??1Stack@@$$FQAE@XZ) referenced in function "public: void __thiscall Stack::listDup(class Stack)" (?listDup@Stack@@$$FQAEXV1@@Z)
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Stack::~Stack(void)" (??1Stack@@$$FQAE@XZ) referenced in function "public: void __thiscall Stack::listDup(class Stack)" (?listDup@Stack@@$$FQAEXV1@@Z)
1>main.obj : error LNK2019: unresolved external symbol "public: __thiscall Stack::Stack(void)" (??0Stack@@$$FQAE@XZ) referenced in function "public: void __thiscall Stack::listCommon(class Stack,class Stack)" (?listCommon@Stack@@$$FQAEXV1@0@Z)
1>c:\users\mschmidt\documents\visual studio 2010\Projects\main\Debug\main.exe : fatal error LNK1120: 4 unresolved externals
Code:#include"stack.h" #include"collection.h" #include<iostream> usingnamespace std; int main() { Stack a, b; int choice, select, add; for( ; ;) { do{ cout << "Please choose from the following: " << endl; cout << "1. Add to stack" << endl; cout << "2. Find duplicates in stack" << endl; cout << "3. Find common elements between stacks A and B" << endl; cin >> choice; } while(choice < 1 || choice > 3 && choice != 4); if(choice == 4) break; switch(choice) { case 1: cout << "Which stack would you like to add to?" << endl; cout << "1. Stack A" << endl; cout << "2. Stack B" << endl; cin >> select; if(select == 1) { cout << "Please enter integer to add to stack A." << endl; cin >> add; //a.insert(add); } elseif(select == 2) { cout << "Please enter integer to add to stack B." << endl; cin >> add; //b.insert(add); } else cout << "Invalid choice"; break; case 2: select = 0; cout << "Which stack would you like to see the duplicates of?" << endl; cout << "1. Stack A" << endl; cout << "2. Stack B" << endl; cin >> select; if(select == 1) { a.listDup(a); } elseif(select == 2) { b.listDup(b); } else cout << "Invalid selection!" << endl; break; } } }Code:#ifndef STACK_H #define STACK_H #include<iostream> #include"collection.h" class Stack : public Collection { public: Stack(); //Stack insert(int i); //void remove(Stack ob1); void listDup(Stack ob1); void listCommon(Stack ob1, Stack ob2); ~Stack(); }; //Stack Stack::insert(int i) { // Stack newset; // if(length==MaxSize) { // cout << "Set is full." << endl; // return *this; // } // newset = *this; // newset.members[newset.length] = i; // newset.length++; // return newset; //} //void Stack::remove(Stack ob1) { // Stack newset; // ob1.length--; // for(int i = 0; i < ob1.length; i++) { // newset.members[newset.length] = ob1.members[i]; // } //} void Stack::listDup(Stack ob1) { std::cout << "Here are the duplicates in the stack: { "; for(int i = 0; i < ob1.length; i++) for(int j = i+1; j < ob1.length; j++) if(ob1.members[i] == ob1.members[j]) std::cout << ob1.members[i] << " }" << std::endl; } void Stack::listCommon(Stack ob1, Stack ob2) { Stack newset; int k = 0; for(int i=0; i<ob1.length; i++) { for(int j=0; j<ob2.length; j++) { if(ob1.members[i] == ob2.members[j]) { newset.members[k] = ob1.members[i]; k++; } } } d::cout << "The common elements of the stacks are: "; newset.colDisplay(); } #endifCode:#ifndef COLLECTION_H #define COLLECTION_H #include<iostream> constint MaxSize = 100; class Collection { protected: int length; int members[MaxSize]; int find(int value); public: Collection() {length = 0;} int getSize() {return length;} void incSize() {length++;} bool isMember(int i); void colDisplay(); ~Collection() { }; }; int Collection::find(int value) { for(int i=0; i<length; i++) if(members[i] == value) return i; return -1; } bool Collection::isMember(int i) { if(find(i) != -1) returntrue; returnfalse; } void Collection::colDisplay() { std::cout << "{ "; for(int i=0; i<length; i++) std::cout << members[i] << " "; std::cout << "}" << std::endl; } #endif



2Likes
LinkBack URL
About LinkBacks


