Help!

1
2
3
4
5
6
7
8
9
10
11
12
13
class MathProcess
{
public:
       
       double GetLogValue(double, double);
       double GetSineValue(double);
       int MultiSumFunc(int,int,int);
private:
        int base,value;
        double x;
        int start,step,upperbound;
        
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <cstdlib>
#include <iostream>
#include <cmath>
#include "MathProcess.h"
using namespace std;

double MathProcess::GetLogValue(double base,double value)
{
       cout<<log10(value)/log10(base)<<endl;
}
double MathProcess::GetSineValue(double x)
{
       cout<<sin(x)<<endl;
       }
int MathProcess::MultiSumFunc(int start,int step,int upperbound)
{
    int k;
    int SumValue=0;
    for(k=start;k<=upperbound;k+=step)
    SumValue+=k;
    cout<<SumValue<<endl;
}


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <cstdlib>
#include <iostream>
#include <cmath>
#include "MathProcess.h"

int main(int argc, char *argv[])
{
    MathProcess m;
    m.GetLogValue(3,8);
    m.GetSineValue(78);
    m.MultiSumFunc(5,3,30);
        
    system("PAUSE");
    return EXIT_SUCCESS;
}


Hello.I have these codes. How can I add multiplications of two complex numbers in this programme? (create Complex.h class)But they all will be in main.cpp.
for example; (3+4i)*(2+i)=2+11i
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
 #include <iostream>
#include <string>
using namespace std;

class Complex
{
      friend ostream &operator<<( ostream &,  Complex& );
      friend istream &operator>>( istream &,  Complex& );
      public:
      Complex(double re,double im):real(re),imag(im)
      {}
      Complex operator+(const Complex& c1)
      {
             double rpart=c1.real+real;
             double ipart=c1.imag+imag;
             return Complex(rpart,ipart);
      }    
      Complex operator-(const Complex& c1)
      {
             double rpart=c1.real-real;
             double ipart=c1.imag-imag;
             return Complex(rpart,ipart);
      }     
      Complex operator*(const Complex& c1)
      {
             double rpart=real*c1.real-imag*c1.imag;
             double ipart=real*c1.imag+imag*c1.real;
             return Complex(rpart,ipart);
      }     
     
     
int real,imaginary,a;
      double showReal()
      {
             return real;
      }  
      double showImag()
      {
             return imag;
      }       
      private:
              double real;
              double imag;      
};



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
 #include <cstdlib>
#include <iostream>
#include "Complex.h"
using namespace std;

ostream &operator<<( ostream &out, Complex &c ){
    out<<"RealPart: "<<c.real<<"+("<<c.imag<<").i"<<endl;    
    return out;
}

istream &operator>>( istream &in, Complex &c ){
    cout<<"Enter Real Part: "<<endl;
    in>>c.real;   
    cout<<"Enter Imaginer Part: "<<endl;
    in>>c.imag;    
    return in;
}

int main(int argc, char *argv[])
{
    Complex a(0,0),b(0,0);
    cin>>a>>b;
    Complex c=a*b;
   
    cout<<c;
    
    
   // Complex a(1,2),b(2,-3);    
    //Complex c= a*b;
   
    
    system("PAUSE");
    return EXIT_SUCCESS;
}


 


These are codes of multiplications of two complex numbers, but I don't know where I must put these codes in this project? Is there anybody who can help me?
Last edited on
Well, that depends- where do you want them? I assume under the class Mathprocess?
It is not enough for me to understand it. When I write them in the programme, it is constantly wrong
Could you post the full program please? I need to be able to see where you want the complex multiplication function- whether you want it under the mathprocess class or perhaps a child class. However, I believe the issue you may be having is the inclusion of the main() proc when you add it to your other code- be sure to get rid of main() {...} from the complex multiplication proc before you add it to your other program, or else it will not work.
I want it under the mathprocess class.
In that case, make the class Complex a child class of MathProcess. The second snippet of code that you put for the class Complex is unnecessary- that's just the code to run it. The first part of the code is the class itself, which is what you want to put into MathProcess.
How can I make a child class ? Could you use codes in order to I can understand it. I'm new learning C++ and it is very hard to me.
Why should complex be derived from MathProcess? Which of the inherited functions or variables from MathProcess is useful for the complex class?

You already have the code for the * operator in the complex class - why do you need to do any thing differently?

You could just have a class for each type of math process, then create an object of a particular type as required. Then call which ever function is needed.

You might not need a MathProcess class at all.

Hope all goes well.
Topic archived. No new replies allowed.