#8
#include
struct node
{
int data;
node *next;
};
class Vector
{
public:
node * list;
int n;
public:
void init();
void show();
void ch(Vector v1,Vector v2);
// ~Vector();
};
void Vector::init()
{
node *p1, *p2, *head;
int a;
head=0;
cout<
for(int i=0;i
{
cin>>a;
p1=new node;
p1->data=a;
if(head==0)
{
head=p1;
p2=p1;
}
else
{
p2->next=p1;
p2=p1;
}
}
list=head;
}
void Vector::ch(Vector v1,Vector v2)
{
node *p1,*p2,*head;
node *vp1=v1.list;
node *vp2=v2.list;
head=0;
int m=0;
for(int k=0;k
{
int ji=0;
for(int j=0;j
{
ji+=(vp1->data)*(vp2->data);
if(j
{
vp1=vp1->next;
for(int l=0;lnext;
}
else break;
}
p1=new node;
p1->data=ji;
if(head==0)
{
head=p1;
p2=p1;
}
else
{
p2->next=p1;
p2=p1;
}//将节点加入到链表中
m++;
vp1=v1.list;
vp2=v2.list;
for(j=0;j
for(int e=0;enext;
for(j=0;jnext;
}
this->list=head;
}
void Vector::show()
{
node *p1;
int b;
int c=0;
p1=this->list;
for(int i=0;i
{
b=p1->data;
p1=p1->next;
cout<
c++;
if(c%n==0)cout<
}
cout<
}
void main()
{
Vector A,B,C,AB,BC,D,E;
int jie;
cout<
cin>>jie;
A.n=B.n=C.n=D.n=E.n=AB.n=BC.n=jie;
A.init();
cout<
A.show();
B.init();
cout<
B.show();
C.init();
cout<
C.show();
AB.ch(A,B);
cout<
AB.show();
BC.ch(B,C);
cout<
BC.show();
D.ch(A,BC);
cout<
D.show();
E.ch(AB,C);
cout<
E.show();
}
你运气好!最近一个大二的要做一个C++的课程设计要我帮忙,题目和这差不多。正好给你!