Lost with this exercise...

I have no idea if I'm on the right track or not, anyone that can help, I would greatly appreciate it.
Link to assignment http://www.scribd.com/doc/128408790/Exercise-4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
//call_complx.cpp
#include "complx.h"
int main()
{
        int i=0;
          complx c1, c2(3,5),in[5];
          cout<< "Please input a complex number in the format of (a,b) - " << endl;
         while ((cin  >> in[i])&& (i<4)){
              cout << in[i] << endl;
              i++;
        }      
        if (c1 == in[0] )        
          cout << c1 << " equals to " << in[0] << endl;
        else
           cout << c1 << " not equal to " << in[0]<< endl;
 
        if (in[1] == in[2] )          
          cout << in[1] << " equals to " << in[2] << endl;
        else
           cout << in[1] << " not equal to " << in[2]<< endl;        
       
        char c; cin >> c;
          return 0;   //successful termination
}

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
// Complx.cpp
#include "complx.h"
complx::~complx()
{
...........LOST HERE :(
}
extern ostream &operator<< ( ostream &out_file, complx &number ){
        out_file << number.Real() << " i" << number.imaginary() << endl;
        return out_file
}
 
 
extern ifstream &operator >> ( ifstream &in_file, complx &number ){
     double re, is;
     char ch;
     if (in_file >> ch && ch == '('&& in_file >> re >> ch && ch == ','
          && in_file >> is >> ch && ch == ')')
              number.Set(re,is);
     else cerr << "Finish the input"<<endl;
     return in_file;
}
 
extern istream &operator >> ( istream &in_file, complx &number ){
       in_file>> &number.real >> &number.imag;
       return in_file;
}
 
// define constructor
complx::complx( double r, double i ){
      real = r; imag = i;
}
 
int operator== (const complx& a, const complx& b){
    if( a.real == b.real && a.imag==b.imag)
    return 1;
    else
    return 0;
}

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
// Complx.h
#include <iostream>
#include <fstream>
using namespace std;

class complx
{
      double real,
             imag;
public:
      complx( double real = 0., double imag = 0.); // constructor
      ~complx();                      // destrucutor
      friend int operator== (const complx&, const complx&);
 
       //Sets private data members.
 
     void Set(double new_real, double new_imaginary) {
     real = new_real;
     imag = new_imaginary;
     }
 
     //Returns the real part of the complex number.
          double Real() {
          return real;
     }
 
     //Returns the imaginary part of the complex number.
     double imaginary() {
     return imag;
     }
};
 
extern ifstream &operator >> ( ifstream &in_file, complx &number );
extern istream &operator >> ( istream &in_file, complx &number );
extern ostream &operator << ( ostream &out_file, complx &number );
Last edited on
You don't have to do anything in the destructor; you have no resources to release. So, basically, you're not lost, you just didn't know you had nothing to do.
Last edited on
:( to be honest this class was to be an into to C++, but turned out to be a nightmare. Doing the best I can. Still getting a ridiculous amount of errors.
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
Compiler: Default compiler
Building Makefile: "C:\Dev-Cpp\Makefile.win"
Executing  make...
make.exe -f "C:\Dev-Cpp\Makefile.win" all
g++.exe -c "Exercise 4/call_complx.cpp" -o "Exercise 4/call_complx.o" -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"   

In file included from Exercise 4/call_complx.cpp:2:
Exercise 4/complx.h:11: error: expected unqualified-id before "public"

Exercise 4/complx.h:11: error: expected `,' or `;' before "public"

Exercise 4/complx.h:13: error: expected constructor, destructor, or type conversion before ';' token

Exercise 4/complx.h:14: error: friend declaration not in class definition

Exercise 4/complx.h: In function `void Set(double, double)':
Exercise 4/complx.h:19: error: `real' undeclared (first use this function)

Exercise 4/complx.h:19: error: (Each undeclared identifier is reported only once for each function it appears in.)

Exercise 4/complx.h:20: error: `imag' undeclared (first use this function)

Exercise 4/complx.h: In function `double Real()':
Exercise 4/complx.h:25: error: `real' undeclared (first use this function)

Exercise 4/complx.h: In function `double imaginary()':
Exercise 4/complx.h:30: error: `imag' undeclared (first use this function)

Exercise 4/complx.h: At global scope:
Exercise 4/complx.h:32: error: expected declaration before '}' token

make.exe: *** ["Exercise 4/call_complx.o"] Error 1

Execution terminated 

Some of the errors I am getting are from the code which was supplied by the instructor.
http://cdn.memegenerator.net/instances/400x/31450812.jpg
Topic archived. No new replies allowed.