/******************************************
this class aimed to build an array can store T type elements\
and no matter how large the array will be!
However, for simple ,i only take the exmples of double ,but in fact
this array class can deal with string,int,char,and any other types
you defined yourself!
how to use?(input the elements separate with',' and ended with ';'
Examples:
input the first array:
12,13,14,15;
input the second array:
14,15,16,17,18;
the first array is :
the vector members:
12 13 14 15
the List members:
12 13 14 15
the second array is :
the vector members:
14 15 16 17 18
the List members:
14 15 16 17 18
the intersection of these two arrays:
the vector members:
14 15
the List members:
14 15
the combination of these two arrays:
the vector members:
12 13 14 15 16 17 18
the List members:
12 13 14 15 16 17 18
*****************************************/
#include
#include
#include
#include
using namespace std;
#define MAX 100 // no matter how small it is
// i will change my length in my program
/****************************
the Class of this question
**************************/
template
class Array{
struct node{
T data;
struct node *next;
};
node *head;
vector
int nLength;
public :
Array();
~Array();
void input(T element);
void Output(void);
int getLength();
T getElement(int pos);
int IsHave(T element);
Array
Array
};
/**********************************
implement of the member function
*************************************/
template
{
nLength = 0;
}
template
{
node *p = head;
node *q;
/* for(int i = 0;i
delete p;
p = q->next;
}
head = NULL;
*/
Arraydata.clear();
}
template
{
return nLength;
}
template
{
nLength++;
if(Arraydata.size()
Arraydata[nLength-1] = element;
node *thisdata = new node;
thisdata->data = element;
thisdata->next = NULL;
node *p;
int i = 0;
p = head;
if(nLength==1){
head = thisdata;
return;
}
for(i = 0;i
p->next = thisdata;
}
template
{
int i = 0;
cout<<"the vector members:\n";
vector
for(i = 0;i
cout<<"the List members:\n";
node *p = head;
for(i = 0;i
p = p->next;
}
cout<
template
T Array
{
return Arraydata[pos];
}
template
int Array
{
int i = 0;
for( i = 0;i< nLength;i++)
{
if(Arraydata[i]==element)
return 1;
}
return 0;
}
template
Array
{
int i = 0;
Array
for( i = 0;i
intersect.input(other.getElement(i));
return intersect;
}
template
Array
{
Array
int i =0;
for( i = 0;i
for( i = 0;i
combina.input(other.getElement(i));
return combina;
}
void main()
{
char ch=' ';
double dTemp;
Array
Array
Array
Array
cout<<"input the first array:"<
{
cin>>ch;
if(ch==','||ch==';')
{
array1.input(dTemp);
//continue;
//cin>>ch;
}
if(isdigit(ch)||ch=='.'){
cin.putback(ch);
cin>>dTemp;
//cin>>ch;
}
}
cout<<"input the second array:"<
while(ch!=';')
{
cin>>ch;
if(ch==','||ch==';')
{
array2.input(dTemp);
//continue;
//cin>>ch;
}
if(isdigit(ch)||ch=='.'){
cin.putback(ch);
cin>>dTemp;
//cin>>ch;
}
}
cout<<"the first array is :\n";
array1.Output();
cout<<"the second array is :\n";
array2.Output();
interarray = array1.intersection(array2);
combiarray = array1.combination(array2);
cout<<"the intersection of these two arrays:\n";
interarray.Output();
cout<<"the combination of these two arrays:\n";
combiarray.Output();
getchar();
}
// 编译环境:visual C++6.0
谁说C++不好用啊??我觉得很好用啊!!
永远支持C++,虽然我用的不好,我会一直学下去的。
有件事问下 计算机语言里有多少是提示语
(因为本人系绝对国际盲所以想跳过警告提示
跟对话\友好\成功 等信息)
不知道可不可以这样硬来?
搞的好想大家都是学编程的~~~~~
呵呵,鬼兄,强!我看了看题,打退堂鼓了。
鬼兄你做什么工作的?多大年纪?
-----
突然发现buaa_sheng也是个挺有意思的人,数、理、化、编程都比较强,buaa_sheng,你是哪儿人啊?多大年纪?做什么的啊?
鬼兄啊,小弟佩服,不知这c++好不好学啊
楼上是查户口的