前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++课程设计类作业2

C++课程设计类作业2

作者头像
Angel_Kitty
发布2018-04-09 10:58:50
6830
发布2018-04-09 10:58:50
举报

不要问我一个晚上在干啥,就写写这种烦到极点的类,啰嗦!

代码语言:javascript
复制
 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 class complexed
 4 {
 5 public:
 6     complexed();
 7     complexed(double real);
 8     complexed(double real,double imag);
 9     void display();
10     void set(double r,double i);
11 private:
12     double real,imag;
13 };
14 complexed::complexed()
15 {
16     set(0.0,0.0);
17     cout<<"default constructor.\n";
18 }
19 complexed::complexed(double real)
20 {
21     set(real,0.0);
22     cout<<"construct called.\n";
23 }
24 complexed::complexed(double real,double imag)
25 {
26     set(real,imag);
27     cout<<"constructor :real="<<real<<",imag="<<imag<<endl;
28 }
29 void complexed::display()
30 {
31     if(imag<0)
32         cout<<real<<imag<<'i'<<endl;
33     else
34         cout<<real<<'+'<<imag<<'i'<<endl;
35 }
36 void complexed::set(double r,double i)
37 {
38     real=r;
39     imag=i;
40 }
41 int main()
42 {
43     complexed c1;
44     complexed c2(6.8);
45     complexed c3(5.6,7.9);
46     c1.display();
47     c2.display();
48     c3.display();
49     c1=complexed(1.2,3.4);
50     c2=5;
51     c3=complexed();
52     c1.display();
53     c2.display();
54     c3.display();
55 }
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2017-06-10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档