#include "stdafx.h" #include "Seque.h" int main(int argc, char* argv[]) { printf("Hello World!\n"); int n,number,position1,insert1,position2; Seque<int> seque; cout<<"Input the number of numbers you want to enter!"<<endl; cin>>n; seque.Input(n); seque.Output(); cout<<"Input the number you want to search!"<<endl; cin>>number; seque.SearchItem(number); cout<<"Input the position and number you want to insert!"<<endl; cin>>position1; cin>>insert1; seque.InsertItem(position1,insert1); seque.Output(); cout<<"Input the position you want to delete!"<<endl; cin>>position2; seque.DeleteItem(position2); seque.Output(); return 0; }
<pre lang="xml">#include "stdafx.h" #include "Seque.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// template<class T> Seque<T>::Seque(int sz) { listsize=sz; lenth=-1; elem= new T[listsize]; if (elem==NULL) { cerr<<"error"<<endl; exit(1); } } template<class T> void Seque<T>::SearchItem(T& x) { for (int i=0;i<listsize;i++) { if (elem[i]==x) { cout<<"The number you search is at "<<i<<"th location"<<endl; } else cout<<"Not Found!"<<endl; } } template<class T> void Seque<T>::InsertItem(int i, T& x) { if (lenth==listsize-1) { cout<<"full"<<endl; } for (int j=lenth;j>i;j--) { elem[j+1]=elem[j]; } elem[i]=x; lenth++; } template<class T> void Seque<T>::DeleteItem(int i) { int x; if (i>lenth) { cout<<"Exceed!"<<endl; } x=elem[i]; for (int j=i;j<=lenth;j++) { elem[j]=elem[j+1]; } lenth--; cout<<"The number at where you point is "<<x<<endl; } template<class T> void Seque<T>::Input(int i) { if (i>listsize) { cout<<"Error!"<<endl; break; } lenth=i; cout<<"Input the elements!"<<endl; for (int j=0;j<i;j++) { cout<<"Number"<<j+1<<endl; cin>>elem[j]; } } template<class T> void Seque<T>::Output() { for (int i=0;i<lenth;i++) { cout<<"Number "<<i+1<<":"<<endl; cout<<elem[i]<<endl; } }
<pre lang="xml">#if !defined(AFX_SEQUE_H__78600571_2F0D_49E2_B387_EA39796A31A6__INCLUDED_) #define AFX_SEQUE_H__78600571_2F0D_49E2_B387_EA39796A31A6__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include <iostream.h> #include <stdlib.h> #define Defaultsize 100 template <class T> class Seque { private: T *elem; int lenth; int listsize; protected: public: Seque(int sz=Defaultsize); ~Seque(){delete[] elem;} void InsertItem(int i, T& x); void DeleteItem(int i); void SearchItem(T& x); void Input(int i); void Output(); }; #endif // !defined(AFX_SEQUE_H__78600571_2F0D_49E2_B387_EA39796A31A6__INCLUDED_)
Linking... 3 Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Seque<int>::DeleteItem(int)" (?DeleteItem@?$Seque@H@@QAEXH@Z) 3 Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Seque<int>::InsertItem(int,int &)" (?InsertItem@?$Seque@H@@QAEXHAAH@Z) 3 Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Seque<int>::SearchItem(int &)" (?SearchItem@?$Seque@H@@QAEXAAH@Z) 3 Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Seque<int>::Output(void)" (?Output@?$Seque@H@@QAEXXZ) 3 Main.obj : error LNK2001: unresolved external symbol "public: void __thiscall Seque<int>::Input(int)" (?Input@?$Seque@H@@QAEXH@Z) 3 Main.obj : error LNK2001: unresolved external symbol "public: __thiscall Seque<int>::Seque<int>(int)" (??0?$Seque@H@@QAE@H@Z) Debug/3 Main.exe : fatal error LNK1120: 6 unresolved externals Error executing link.exe.
template <class T> class Seque { private: T *elem; int lenth; int listsize; protected: public: void InsertItem(int i, T& x) { //... } void DeleteItem(int i) { //... } //... };
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)