用VC如何写一个运算符重载综合练习。高手进 分不够再开帖

denglin 2005-12-19 10:14:30

越详细越好,最好写上算法描述

要求:
1 复数
建立和复数相对应的数据结构
重载运算符函数实现复数的+ — * /运算
对复数的内容进行输出
2、
建立和字符串相对应的数据结构
实现字符串的初始化(构造函数)
(1)常量初始化(如空字符串,字符串常量)
(2)使用其他字符串对象初始化(避免出现指针悬挂)
实现字符串的如下操作
1。输出字符串的内容
2。清空,判空操作
3。求字符串的长度
4。获取字符串中的单个字符
5。改变字符串中某个位置的值
6。重载赋值运算符“=” 实现字符串间的赋值(避免出现指针悬挂)
7。重载“+”,“—”实现字符串的与
8。字符串比较函数(区分大小写和不区分大小写)
9。获取子串
10。转变字符串的大小写
11。去除空格的函数
12。对运算符“==”,“!=”,“>”,"<", ">=", "<="进行重载
13。将字符串翻转的函数
...全文
143 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
useresu 2005-12-23
  • 打赏
  • 举报
回复
C++PRIMER第一章和第6章全有。呵呵
////////////////////////
C++ primer 第6章可是没有字符串的实现

The C++ programming language中老bs倒是有个简单的string实现

虽然他说简单,

但是偶认为值的推敲.
zcz0918 2005-12-23
  • 打赏
  • 举报
回复
写个好的string类还不一定是容易的
fiftymetre 2005-12-22
  • 打赏
  • 举报
回复
C++PRIMER第一章和第6章全有。呵呵
useresu 2005-12-21
  • 打赏
  • 举报
回复
楼上敏锐的洞察力
goodluckyxl 2005-12-21
  • 打赏
  • 举报
回复
受不了
iamcaicainiao 2005-12-21
  • 打赏
  • 举报
回复
同意,呵呵
Seben 2005-12-20
  • 打赏
  • 举报
回复
感觉楼主象需要交作业又不想做的样子...
ma100 2005-12-19
  • 打赏
  • 举报
回复
class Complex
{
public:
Complex(){real=imag=0;}
Complex(double r,double i)
{
real=r;imag=i;
}
Complex operator +(const Complex &c);
Complex operator -(const Complex &c);
Complex operator *(const Complex &c);
Complex operator /(const Complex &c);
Complex operator -();


double real,imag;
};

inline Complex Complex::operator +(const Complex &c)
{
return Complex(real+c.real,imag+c.imag);
}
inline Complex Complex::operator -(const Complex &c)
{
return Complex(real-c.real,imag-c.imag);
}
inline Complex Complex::operator *(const Complex &c)
{
return Complex(real*c.real-imag*c.imag,real*c.imag+imag*c.real);
}
inline Complex Complex::operator /(const Complex &c)
{
return Complex(
(real*c.real+imag*c.imag)/(c.real*c.real+c.imag*c.imag),
(imag*c.real-real*c.imag)/(c.real*c.real+c.imag*c.imag)
);
}
inline Complex Complex::operator -()
{
return Complex ( -real , -imag );
}

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧