| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 464 人关注过本帖
标题:输入符号后结束不了程序,怎么办
只看楼主 加入收藏
APTX
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2015-3-29
结帖率:50%
收藏
已结贴  问题点数:20 回复次数:1 
输入符号后结束不了程序,怎么办
#include<iostream>
#include<cstdlib>
using namespace std;
class imaginary
{ double x,y;
  public:
      imaginary(double a=0,double b=0):x(a),y(b){};
      friend imaginary add(imaginary c,imaginary d);
      friend imaginary sub(imaginary e,imaginary f);
      friend imaginary mul(imaginary g,imaginary h);
      friend imaginary div(imaginary m,imaginary n);
      friend ostream & operator<<(ostream &output,imaginary &v);
      void show(imaginary p,imaginary q,int w);
};
imaginary add(imaginary c,imaginary d)
{ imaginary ad;
  ad.x=c.x+d.x;
  ad.y=c.y+d.y;
  return ad;
}
imaginary sub(imaginary e,imaginary f)
{ imaginary su;
  su.x=e.x-f.x;
  su.y=e.y-f.y;
  return su;
}
imaginary mul(imaginary g,imaginary h)
{ imaginary mu;
  mu.x=(g.x*h.x)-(g.y*h.y);
  mu.y=(g.x*h.y)+(g.y*h.x);
  return mu;
}
imaginary div(imaginary m,imaginary n)
{ imaginary di;
  di.x=(m.x*n.x+m.y*n.y)/(n.x*n.x+n.y*n.y);
  di.y=(m.y*n.x-m.x*n.y)/(n.x*n.x+n.y*n.y);
  return di;
}
ostream & operator<<(ostream & output,imaginary &v)
{ output<<v.x<<"+"<<v.y<<"i";
  return output;
}
void imaginary::show(imaginary p,imaginary q,int w)
{ switch(w)
  { case 0:cout<<"("<<p.x<<"+"<<p.y<<"i"<<")"<<"+"<<"("<<q.x<<"+"<<q.y<<"i"<<")"<<"="<<add(p,q)<<endl;break;
    case 1:cout<<"("<<p.x<<"+"<<p.y<<"i"<<")"<<"-"<<"("<<q.x<<"+"<<q.y<<"i"<<")"<<"="<<sub(p,q)<<endl;break;
    case 2:cout<<"("<<p.x<<"+"<<p.y<<"i"<<")"<<"*"<<"("<<q.x<<"+"<<q.y<<"i"<<")"<<"="<<mul(p,q)<<endl;break;
    case 3:cout<<"("<<p.x<<"+"<<p.y<<"i"<<")"<<"/"<<"("<<q.x<<"+"<<q.y<<"i"<<")"<<"="<<div(p,q)<<endl;
  }
}
void main()
{ imaginary im;
  imaginary j(1,2),i(3,4);
  char a={0};
  int r,flag;
  cout<<"i=3+4i,j=1+2i."<<'\n'<<"Please input i and j 's operation symbol:";
  while(cin>>a)
  { flag=1;
    if(a=='+') r=0;
       else if(a=='-') r=1;
          else if(a=='*') r=2;
             else if(a=='/') r=3;
                else { flag=0;cout<<"Wrong symbol!"<<endl;}
    if(flag)
    { im.show(i,j,r);
    }
  }
  system("pause");
}
如题,输入符号显示输出后仍留在输入界面,要加些什么代码才可结束程序?
搜索更多相关主题的帖子: include public double friend 
2015-04-05 12:03
诸葛欧阳
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:流年
等 级:贵宾
威 望:82
帖 子:2790
专家分:14619
注 册:2014-10-16
收藏
得分:20 
搞错版块了吧

一片落叶掉进了回忆的流年。
2015-04-05 12:09
快速回复:输入符号后结束不了程序,怎么办
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025078 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved