c课程设计报告--小型特殊计算器(编辑修改稿)内容摘要:
******/ /* 函数名称: operator == 功能描述:重载运算符 == 修改记录: */ bool operator ==(rational num1,rational num2) { if( == amp。 amp。 == ) return true。 else return false。 } /*****************************************************************************/ /* 函数名称: print 功能描述:声明转换函数 ,将有理数对象转换为实数 修改记录: */ double real(rational x) { return(double( ))/(double( ))。 } /*****************************************************************************/ // : implementation of the matrix class. include include include matrix::matrix() { } matrix::~matrix() { } /*****************************************************************************/ /* 函数名称: matrix::operator ()(short row, short col) 功能描述: 重载运算符成员函数 修改记录: */ int matrix::operator ()(short row, short col) { if(row=1 amp。 amp。 row=rows amp。 amp。 col=1 amp。 amp。 col=cols) return elems[(row1)*cols + (col1)]。 else return 0。 } /*****************************************************************************/ /* 函数名称: matrix::SetElem(short row, short col,int val) 功能描述: 将元素 (row,col)设置为 val 修改记录: */ void matrix::SetElem(short row, short col,int val) { if(row=1 amp。 amp。 row=rows amp。 amp。 col=1 amp。 amp。 col=cols) elems[(row1)*cols+(col1)]= val。 } /*****************************************************************************/ /* 函数名称: matrix::Disp() 功能描述: 显示矩阵元素 修改记录: */ void matrix::Disp() { for(int row=1。 row=rows。 row++) { for(int col=1。 col=cols。 col++) coutsetw(2)(*this)(row,col)。 coutendl。 } } /*****************************************************************************/ /* 函数名称: operator +(matrix p,matrix q) 功能描述: 重载运算符+ 修改记录: */ matrix operator +(matrix p,matrix q) { matrix m(,)。 if(!= || !=) return m。 for(int r=1。 r=。 r++) for(int c=1。 c=。 c++) (r,c,p(r,c)+q(r,c))。 return m。 } /*****************************************************************************/ /* 函数名称: operator (matrix p,matrix q) 功能描述: 重载运算符 修改记录: */ matrix operator (matrix p,matrix q) { matrix m(,)。 if(!= || !=) return m。 for(int r=1。 r=。 r++) for(int c=1。 c=。 c++) (r,c,p(r,c)q(r,c))。 return m。 } /*****************************************************************************/ /* 函数名称: operator *(matrix p,matrix q) 功能描述: 重载运算符 * 修改记录: */ matrix operator *(matrix p,matrix q) { matrix m(,)。 if(!=) return m。 for(int r=1。 r=。 r++) for(int c=1。 c=。 c++) { int s=0。 for(int i=1。 i=。 i++) s+=p(r,i)*q(i,c)。 (r,c,s)。 } return m。 } /*****************************************************************************/ // : implementation of the set class. include set::~set() { } /*****************************************************************************/ /* 函数名称: print 功能描述:显示复数 修改记录: */ void set::print() { cout{。 for(int i=0。 icard1。 i++) coutelems[i],。 if(card0) coutelems[card1]}\n。 } /*****************************************************************************/ /* 函数名称: additem 功能描述:增加集合元素 修改记录: */ errcode set::additem(int elem) { for(int i=0。 icard。 i++) if(elems[i]==elem) return noerr。 if(card16) { elems[card++]=elem。 return noerr。 } else return overflow。 } /*****************************************************************************/ /* 函数名称: operator amp。 功能描述:声明重载运算符 amp。 ,判断某一整数是否属于某一集合 修改记录: */ bool operator amp。 (int elem,set set1) { for(int i=0。 i。 ++i) if([i]==elem) return true。 return false。 } /*****************************************************************************/ /* 函数名称: operator == 功能描述:声明重载运算符 ==,判断两个集合是否相等 修改记录: */ bool operator ==(set set1,set set2) { if( != ) //两个集合个数不等,必不相等 return false。 for(int i=0。 i。 i++) if(!( [i]amp。 set2)) //调用 amp。 定义 return false。 return true。 } /*****************************************************************************/ /* 函数名称: operator != 功能描述:声明重载运算符 !=,判断两个集合是否不等 修改记录: */ bool operator !=(set set1,set set2) { if(set1== set2) return false。 else return true。 } /*****************************************************************************/ /* 函数 名称: operator * 功能描述:声明重载运算符 *,求两个集合的交 修改记录: */ set operator *(set set1,set set2) { set res。 for(int i=0。 i。 i++) for(int j=0。 j。 j++) if( [i]== [j]) { [ ++]= [i]。 break。 } //取 set1 中的每一个元素判断是否属于 set2,若属于则加入到 res 中 return res。 } /*****************************************************************************/ /* 函数名称: operator + 功能描述:声明重载运算符 +,求两个集合的并 修改。c课程设计报告--小型特殊计算器(编辑修改稿)
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。
用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。