C++课程设计类作业2
2017-06-10 23:30
513 查看
不要问我一个晚上在干啥,就写写这种烦到极点的类,啰嗦!
#include <bits/stdc++.h> using namespace std; class complexed { public: complexed(); complexed(double real); complexed(double real,double imag); void display(); void set(double r,double i); private: double real,imag; }; complexed::complexed() { set(0.0,0.0); cout<<"default constructor.\n"; } complexed::complexed(double real) { set(real,0.0); cout<<"construct called.\n"; } complexed::complexed(double real,double imag) { set(real,imag); cout<<"constructor :real="<<real<<",imag="<<imag<<endl; } void complexed::display() { if(imag<0) cout<<real<<imag<<'i'<<endl; else cout<<real<<'+'<<imag<<'i'<<endl; } void complexed::set(double r,double i) { real=r; imag=i; } int main() { complexed c1; complexed c2(6.8); complexed c3(5.6,7.9); c1.display(); c2.display(); c3.display(); c1=complexed(1.2,3.4); c2=5; c3=complexed(); c1.display(); c2.display(); c3.display(); }
相关文章推荐
- C++课程设计(作业)
- C++课程设计类作业3
- C++课程设计作业,第八题
- 代写编程的作业、笔试题、课程设计,包括但不限于C/C++/Python
- C++课程设计类作业4
- c++课程设计
- c++课程设计 对日期的基本运算 使用重载
- C++面向对象课程设计 通信录
- C++课程设计 面积运算
- 课程设计C++
- [设计] C++课程设计-ATM (纪念大一)
- 课程设计大作业参考题目
- C++课程设计指导书
- c++课程设计
- C++课程设计( 南阳康佳公司的设备管理系统 )
- c++ 课程设计 ——公司设备管理系统
- c++课程设计 对日期及时间的基本运算(时间类和日期类) 使用重载
- Linux下写的一个C++课程设计
- c++ 数据结构课程设计 魔王语言解释
- C/C++语言课程设计任务书