!!请教一道C++的题目!!急!!!

来源:百度知道 编辑:UC知道 时间:2024/05/19 06:19:43
编写一个实现向量的各种操作的类,功能包括:
1 构造函数实现N元向量的初始化构造,n可变
2 析构函数实现向量动态内存的释放
3 拷贝构造函数实现向量的拷贝构造
4重载赋值运算符“=”实现两个向量之间赋值
5 编写成员函数分别求两个向量的内积、外积、和、差
6 编写成员函数判断两个向量之间的线性相关性
7 编写一个主函数测试多项式类的上述功能

class polynomial : public std::vector<double>
{
public:
double inner_product(const polynomial &other)
{
if(size() != other.size())
{
//处理维数不同的情况
}
else
{
//求和
}
WhatData? exterior_product(const polynomial &other)
{
……
}
bool is_linear_dependent(const polynomial &other)
{
……
}
}

polynomial operator+(const polynomial &first, const polynomial &second)
{
……
}

polynomial operator-(const polynomial &first, const polynomial &second)
{
……
}

思路大概如上,通过继承std::vector<double>,前4步都省了。后面那几个操作,不一定都要写成成员函数。是定义为成员函数还是定义为全局函数,需要斟酌。

ft
5分。。。