C++的一个简单的编程问题

来源:百度知道 编辑:UC知道 时间:2024/06/24 11:29:49
利用链表和指针实现多项式的加法或乘法运算,用文件实现输入和输出。
呵呵,综合题目!!
下面那个程序错了啊!!!

以后在慢慢做好了!!

虽然说不难,但是也是相当复杂的,5分的话,可以给点提示:用链表较复杂,如果用栈的话,会方便很多。

if....else要long int定义。
记住这点就行了。

做这种题,种舍得分啊!

多给点分,不好吗?
#include <string.h>
#include <assert.h>
#include "my_string.h"
my_string::my_string(char * pstr)
{
if(pstr == NULL)
{
p = new char[1];
*p = 0;
}
else
{
p = new char[strlen(pstr)+1];
strcpy(p, pstr);
}
}
my_string::my_string(my_string & str)
{
p = new char[strlen(str.p)+1];
strcpy(p, str.p);
}
my_string::~my_string()
{
delete [] p;
}
my_string my_string::operator+(my_string& str)
{
my_string temp;
delete [] temp.p;
temp.p = new char[strlen(this->p)+strlen(str.p)+1];
strcpy(temp.p, this->p);
strcat(temp.p, str.p);
return temp;
}
my_string& my_string::operator=(my_string str)
{
delete [] this->p;
p = new