第三次C++实验

//第三次实验题目:
//1.定义一个多项式节点类CNode:
//class CNode
//{
//private:
//       int exp;//指数
//       float coef;//系数
//       CNode *next;
// CNode *prev;
//public:
// CNode(float cf,int ep);//cf为系数,ep为指数
// ~CNode();//实现节点脱离链表功能

//};
//CNode *head=NULL;
//完成以下定义
//CNode::CNode(float cf,int ep)
//{
//}
//定义一个全局指针CNode *head(指向多项式双向链表中的第一项节点),
//要求:
//1、CNode的构造函数自动将构造的对象插入head链表中(按指数从大到校排列),在输入指数相同的项时需要进行合并;
//2、main函数时依次释放(delete q)链表中的的节点。
//验证定义
//void main()
//{
//}


#include<iostream>
using namespace std;
class CNode
{
private:
        int exp;//指数
        float coef;//系数
        CNode *next;
CNode *prev;
public:
CNode(float cf,int ep);//cf为系数,ep为指数
~CNode();//实现节点脱离链表功能
void show();
void cycle();

};
CNode *head=NULL;
//完成以下定义
CNode::~CNode ()
{ cout<<"this is a disconstruct!!!!"; }
CNode::CNode(float cf,int ep)
{
CNode *p1;
p1=this;
this->coef =cf;
this->exp =ep;
this->next =NULL;
if(head==NULL)
head=p1;
else
p1->next =this;
}
void CNode::cycle ()
{
float i;
int j;
cout<<"please input under data:"<<endl;
while(this->exp !=0)
{
cin>>i>>j;
CNode *p2;
p2= new CNode(i,j);
}
}
void CNode::show ()
{
CNode *q;
q=head;
while (q)
{
cout<<"this list is blow:"<<endl;
cout<<coef<<" "<<exp<<endl;
q=q->next ;
}
}
int main()
{

CNode A;
A.cycle ();
A.show ();
return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值