高新企业净资产增长率:谁能帮我把那程序写出来?用c++程序写的

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/05 19:15:25
题目是这样的:
设计一个具有交,并等功能的的类,要用数组和链分别做一个,就是输入两个数组,求他们的交并集,输出也是两个数组!!输出的两个数组一个是交的情况,另一个是并的!输出的时候最好像菜单一样!
就是像下面
请输入一个数组:
请输入另一个数组:
做的好的另外加100,要能直接运行的,最好输入数组的字数个数不限,要输几个就几个,能不能直接在一个文件里面把所有的程序都包括了!

/******************************************
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 <iostream.h>
#include <stdio.h>
#include <vector>
#include <string>
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 T>

class Array{
struct node{
T data;
struct node *next;
};
node *head;
vector<T> Arraydata;
int nLength;
public :
Array();
~Array();
void input(T element);
void Output(void);
int getLength();
T getElement(int pos);
int IsHave(T element);
Array<T> intersection(Array other);
Array<T> combination(Array other);
};

/**********************************
implement of the member function
*************************************/
template<class T> Array<T>::Array()
{
nLength = 0;
}
template<class T> Array<T>::~Array()
{
node *p = head;
node *q;
/* for(int i = 0;i<nLength-2;i++){
q = p->next;
delete p;
p = q->next;
}
head = NULL;
*/
Arraydata.clear();
}

template<class T> int Array<T>::getLength()
{
return nLength;
}

template<class T> void Array<T>::input(T element)
{
nLength++;
if(Arraydata.size()<nLength)
Arraydata.resize(MAX+nLength);
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<nLength-2;i++)
p = p->next;
p->next = thisdata;
}

template<class T> void Array<T>::Output()
{
int i = 0;
cout<<"the vector members:\n";
vector<T>::iterator it = Arraydata.begin();
for(i = 0;i<nLength;i++)
cout<<Arraydata[i]<<'\t';
cout<<'\n';
cout<<"the List members:\n";
node *p = head;
for(i = 0;i<nLength;i++){
cout<<p->data<<'\t';
p = p->next;
}
cout<<endl;
}
template<class T>
T Array<T>::getElement(int pos)
{
return Arraydata[pos];
}

template<class T>
int Array<T>::IsHave(T element)
{
int i = 0;
for( i = 0;i< nLength;i++)
{
if(Arraydata[i]==element)
return 1;
}
return 0;
}
template<class T>
Array<T> Array<T>::intersection(Array<T> other)
{
int i = 0;
Array<T> intersect;
for( i = 0;i<other.getLength();i++)
if(IsHave(other.getElement(i)))
intersect.input(other.getElement(i));
return intersect;
}
template<class T>
Array<T> Array<T>::combination(Array<T> other)
{
Array<T> combina;
int i =0;
for( i = 0;i<nLength;i++)
combina.input(getElement(i));
for( i = 0;i<other.getLength();i++)
if(!IsHave(other.getElement(i)))
combina.input(other.getElement(i));
return combina;
}

void main()
{
char ch=' ';
double dTemp;
Array<double> array1;
Array<double> array2;
Array<double> interarray;
Array<double> combiarray;
cout<<"input the first array:"<<endl;
while(ch!=';')
{
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:"<<endl;
ch = ' ';
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++好不好学啊

楼上是查户口的