473,405 Members | 2,272 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Compling errors

I'm working on a program, overloading operators, when I compile the program together it works, however when I separate it into the various files such as the .h and the .cpp I'm getting a lot of error messages. Can you offer any suggestions.

Here's the code:
Expand|Select|Wrap|Line Numbers
  1. //#include "complex.h"//implementation file
  2. #include <iostream>
  3. //#include<math.h>  
  4. using namespace std;
  5.  
  6. class Complex
  7. {
  8.     public:
  9.         Complex(double, double);
  10.         Complex();
  11.         Complex(double);   
  12.         friend ostream& operator <<(ostream& out, const Complex& c);
  13.         friend istream& operator >>(istream& in, Complex& c);
  14.         friend const Complex operator *(const Complex& l, const Complex& r);
  15.         friend const Complex operator -(const Complex& l, const Complex& r);
  16.         friend const Complex operator +(const Complex& l, const Complex& r);
  17.         friend bool operator ==(const Complex& l, const Complex& r);
  18.     private:
  19.          double real, imag;
  20. };
  21.  
  22. // define constructor
  23. Complex::Complex( double r, double i )
  24. {
  25.     real = r; imag = i;
  26. }
  27.  
  28. Complex::Complex()
  29. {
  30.     real = 0;
  31.     imag = 0;
  32. }
  33.  
  34. Complex::Complex(double realPart ) //constructor that takes a single parameter
  35. {
  36.     realPart = 0;
  37.     int i = 1;
  38. }
  39.  
  40. ostream& operator <<(ostream& out, const Complex& c)
  41. {
  42.     out << c.real << "+" << c.imag << "i";
  43.     return out;
  44. }
  45.  
  46. istream& operator >>(istream& in, Complex& c)
  47. {
  48.     char op;
  49.     char i;
  50.     in >> c.real >> op >> c.imag >> i; 
  51.  
  52.     return in;
  53. }
  54.  
  55. // define overloaded + (plus) operator
  56. const Complex operator +(const Complex& l, const Complex& r) 
  57. {
  58.     Complex result;
  59.     result.real = (l.real + r.real);
  60.     result.imag = (l.imag + r.imag);
  61.  
  62.     return result;
  63. }
  64.  
  65. const Complex operator -(const Complex& l, const Complex& r) 
  66. {
  67.       Complex result;
  68.       result.real = (l.real - r.real);
  69.       result.imag = (l.imag - r.imag);
  70.       return result;
  71. }
  72.  
  73. const Complex operator *(const Complex& l, const Complex& r) 
  74. {
  75.  
  76.       int a = (l.real*r.real - l.imag*r.imag);
  77.       int b = (l.imag*r.real + l.real*r.imag);
  78.       Complex result(a,b);
  79.       return result;
  80. }
  81.  
  82. bool operator ==(const Complex& l, const Complex& r)
  83. {
  84.     return ((l.real == r.real) && (l.imag == r.imag));
  85. }
  86.  
  87.  
  88.  
  89. int main()
  90.     Complex a(4,5), b(6,5);
  91.     double realPart = 0;
  92.     Complex i(0,1);
  93.     cout << "First complex number is " << a << endl;
  94.     cout << "Second complex number is " << b << endl << endl;
  95.     cout << "Testing constant i..."<<endl; 
  96.     cout << "The value of our constant i is: " << i << endl <<endl;
  97.     cout << "Enter 2 new complex numbers in the form a+bi(with no spaces):" << endl;
  98.     cin >> a >> b;
  99.     cout << endl;
  100.  
  101.  
  102.     cout << a << " + " << b <<" = "<< a + b<< endl;
  103.     cout << a << " - " << b <<" = "<< a - b<< endl;
  104.     cout << a << " * " << b <<" = "<< a * b<< endl << endl;
  105.     cout << "Testing equality operator..." << endl;
  106.     if (a == b)
  107.         cout << a << " is equal to " << b << endl;
  108.     else
  109.         cout << a << " is not equal to " << b << endl;
  110.     return 0;
  111.  
  112. }
Here are the error messages:


C:\Documents and Settings\Default\Desktop>cl /EHsc pr3d.cpp
pr3.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version
13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights
reserved.

pr3d.cpp
c1xx : fatal error C1083: Cannot open source file:
'pr3d.cpp': No such file or d
irectory
pr3.cpp
c1xx : fatal error C1083: Cannot open source file:
'pr3.cpp': No such file or di
rectory
Generating Code...

C:\Documents and Settings\Default\Desktop>cd exP-3\

C:\Documents and Settings\Default\Desktop\exP-3>cl /EHsc
pr3d.cpp pr3.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version
13.10.3077 for 80x86
Copyright (C) Microsoft Corporation 1984-2002. All rights
reserved.
Mar 14 '07 #1
2 1905
DeMan
1,806 1GB
Welcome to theScripts,

I am taking the liberty of moving this thread to the C forum, where I'm sure the experts will be more than willing to offer some advice....
Mar 14 '07 #2
Ganon11
3,652 Expert 2GB
What is the name of the files you are saving this code in? You may be trying to open a file that doesn't exist.
Mar 14 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: Douglas Buchanan | last post by:
I am using the following code instead of a very lengthly select case statement. (I have a lot of lookup tables in a settings form that are selected from a ListBox. The data adapters are given a...
1
by: yanwan | last post by:
Hello I am now compling a project, but in one source file of this project, I met this problem. It seems very strange. Below is this source file: ----------------------------------------...
0
by: doli | last post by:
Hi, I have the following piece of code which iterates through the potential errors: i =0 For Each error_item in myConn.Errors DTSPackageLog.WriteStringToLog myConn.Errors(i).Description...
5
by: shiling zhang | last post by:
I have a C program that is complied fine under DOS and UNIX. However, the same C program has the following compling error under IBM 390. TIA. ...
4
by: yanwan | last post by:
Hello I am now compling a project, but in one source file of this project, I met this problem. It seems very strange. Below is this source file: ----------------------------------------...
4
by: johnb41 | last post by:
I have a form with a bunch of textboxes. Each text box gets validated with the ErrorProvider. I want the form to process something ONLY when all the textboxes are valid. I found a solution,...
24
by: pat | last post by:
Hi everyone, I've got an exam in c++ in two days and one of the past questions is as follows. Identify 6 syntax and 2 possible runtime errors in this code: class demo {
8
by: ImOk | last post by:
I just have a question about trapping and retrying errors especially file locking or database locks or duplicate key errors. Is there a way after you trap an error to retry the same line that...
2
by: usmita | last post by:
I' m inserting record in database through html & jsp file while compling jsp file this exception occured. what,s the reason behind this- root cause org.apache.jasper.JasperException: Unable...
2
by: =?Utf-8?B?UmFuZHlz?= | last post by:
This just started when I updated to sp 1 working on a APS.net, Visual Studio 2008, c# Project. When I open a project, I get tons of Errors showing in the list 300+ if I double click on them I go...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.