Question: In what areas can I optimize this C++ program? #include #include class complex { private: float real,img; public: void assign(float x,float y) { real=x; img=y;
In what areas can I optimize this C++ program?
#include
#include
class complex
{
private:
float real,img;
public:
void assign(float x,float y)
{
real=x;
img=y;
}
void print()
{ if(img>=0)
cout< else cout< getch(); } }; void add( float a,float b,float c, float d) { float e,f;complex g; e=a+c; f=b+d; g.assign(e,f); g.print(); } void sub( float a,float b,float c, float d) { float e,f;complex g; e=a-c; f=b-d; g.assign(e,f); g.print(); } void mul( float a,float b,float c, float d) { float e,f; complex g; e=a*c-b*d; f=b*c+a*d; g.assign(e,f); g.print(); } void main() { float a,b,c,d; complex x,y,z; clrscr(); cout<<" for complex 1:"; cout<<"real part:"; cin>>a; cout<<"imaginary part:"; cin>>b; cout<<" for complex 2:"; cout<<"real part:"; cin>>c; cout<<"imaginary part:"; cin>>d; x.assign(a,b); y.assign(c,d); cout<<"**************original data:************ "; cout<<"Complex 1: ";x.print(); cout<<" Complex 2: ";y.print(); cout<<" ************=================********** "; cout<<" Addition: ";add(a,b,c,d); cout<<" Subtraction: ";sub(a,b,c,d); cout<<" Multipication: ";mul(a,b,c,d); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
