//定义一个多项式节点类Node,定义一个全局指针Node *head(指向多项式链表中的第一项节点),
//要求:Node的构造函数自动将构造的对象插入head链表中;
//class Node
//{
//private:
// int exp;//指数
// float coef;//系数
// Node *next;
//public:
// Node();//从键盘接收输入的系数,指数
// Node(float cf,int ep);//
//};
//Node *head=NULL;
//完成以下定义
//Node::Node()
//{
//}
//完成以下定义
//Node::Node(float cf,int ep)
//{
//}
//验证定义
//void main()
//{
//}
#include<iostream>
using namespace std;
class Node
{
private:
int exp;//指数
float coef;//系数
Node *next;
public:
Node (int a);
Node();//从键盘接收输入的系数,指数
Node(float cf,int ep);
void show();
};
Node *head=NULL;
//完成以下定义
Node::Node(int a)
{
a=0;
cout<<"Using construcor !!!";
}
Node::Node()
{
if(head==NULL)
{
head=this;
this->next =NULL;
}
else
{
this->next =head;
head=this;
}
cin>>this->coef >>this->exp ;
// cout<<"Using construcor!!"<<endl;
}
Node::Node(float cf,int ep)
{
if(head=NULL)
{
head=this;
this->next=NULL;
}
else
{
this->next=head;
head=this;
}
this->coef=cf;
this->exp=ep;
// cin>>this->coef;
// cin>>this->exp;
}
//完成以下定义
void Node::show () //链表的输出 //在类外时,其自动生成的this指针是不能移动的
{
Node *p=head;
while(p)
{
// cout<<this->coef<<" "<<this->exp<<endl; //在类外时,this指针是不能移动的
cout<<p->coef <<" "<<p->exp <<endl;
p=p->next;
}
}
//验证定义
void main()
{
Node A[3];
A[0].show();
Node A2(2.1,3);
A2.show ();
}
//要求:Node的构造函数自动将构造的对象插入head链表中;
//class Node
//{
//private:
// int exp;//指数
// float coef;//系数
// Node *next;
//public:
// Node();//从键盘接收输入的系数,指数
// Node(float cf,int ep);//
//};
//Node *head=NULL;
//完成以下定义
//Node::Node()
//{
//}
//完成以下定义
//Node::Node(float cf,int ep)
//{
//}
//验证定义
//void main()
//{
//}
#include<iostream>
using namespace std;
class Node
{
private:
int exp;//指数
float coef;//系数
Node *next;
public:
Node (int a);
Node();//从键盘接收输入的系数,指数
Node(float cf,int ep);
void show();
};
Node *head=NULL;
//完成以下定义
Node::Node(int a)
{
a=0;
cout<<"Using construcor !!!";
}
Node::Node()
{
if(head==NULL)
{
head=this;
this->next =NULL;
}
else
{
this->next =head;
head=this;
}
cin>>this->coef >>this->exp ;
// cout<<"Using construcor!!"<<endl;
}
Node::Node(float cf,int ep)
{
if(head=NULL)
{
head=this;
this->next=NULL;
}
else
{
this->next=head;
head=this;
}
this->coef=cf;
this->exp=ep;
// cin>>this->coef;
// cin>>this->exp;
}
//完成以下定义
void Node::show () //链表的输出 //在类外时,其自动生成的this指针是不能移动的
{
Node *p=head;
while(p)
{
// cout<<this->coef<<" "<<this->exp<<endl; //在类外时,this指针是不能移动的
cout<<p->coef <<" "<<p->exp <<endl;
p=p->next;
}
}
//验证定义
void main()
{
Node A[3];
A[0].show();
Node A2(2.1,3);
A2.show ();
}