السلام عليكم ..
إخواني انا عندي بربلم يقوم بجمع وطرح الـ Complex Numbers .. وهذا تطبيقي عليه :
#include <iostream>
using namespace std;
class Complex
{
double realPart , imaginaryPart;
public :
Complex ();
Complex add (const Complex &c1);
Complex sub (const Complex &c2);
void set (double x , double y );
void print ();
void printAdd ();
void printSub ();
}
Complex::Complex ()
{
realPart = 0.0;
imaginaryPart =0.0;
}
Complex Complex::add(const Complex &c1)
{
Complex t;
double a , b;
a = realPart + c1.realPart;
b = imaginaryPart + c1.imaginaryPart;
t.set (a , b );
return t;
}
Complex Complex::sub (const Complex &c2)
{
Complex t;
double a , b;
a = realPart - c2.realPart;
b = imaginaryPart - c2.imaginaryPart;
t.set (a , b );
return t;
}
void Complex::printAdd()
{
cout << realPart << "+" << imaginaryPart << "i" <<endl;
}
void Complex::printSub()
{
cout<<realPart << "-" << imaginaryPart <<"i"<<endl;
}
void Complex::print()
{
cout << "Add=" << printAdd() <<endl;
cout << "Sub=" << printSub() <<endl;
}
int main()
{
Complex c1 , c2 , c3;
double a , b , c , d;
cout << "Enter First Complex Number :";
cin >> a >> b;
c1.set(a , b );
cout << "Enter Second Complex Number :";
cin >> c >> d;
c2.set (c , d );
c3 = c1 .add (c2);
c3 = c1 .sub (c2);
c3.print();
return 0;
}لكن المشكلة تطلع لي هذي الأخطاء !! :
--------------------Configuration: Complex - Win32 Debug-------------------- Compiling... Complex.cpp D:\Unevirsty\Csc113\6.6\Complex.cpp(20) : error C2533: 'Complex::Complex' : constructors not allowed a return type D:\Unevirsty\Csc113\6.6\Complex.cpp(28) : error C2264: 'Complex::Complex' : error in function definition or declaration; function not called D:\Unevirsty\Csc113\6.6\Complex.cpp(39) : error C2264: 'Complex::Complex' : error in function definition or declaration; function not called D:\Unevirsty\Csc113\6.6\Complex.cpp(61) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion) D:\Unevirsty\Csc113\6.6\Complex.cpp(62) : error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'void' (or there is no acceptable conversion) D:\Unevirsty\Csc113\6.6\Complex.cpp(68) : error C2264: 'Complex::Complex' : error in function definition or declaration; function not called D:\Unevirsty\Csc113\6.6\Complex.cpp(68) : error C2264: 'Complex::Complex' : error in function definition or declaration; function not called D:\Unevirsty\Csc113\6.6\Complex.cpp(68) : error C2264: 'Complex::Complex' : error in function definition or declaration; function not called Error executing cl.exe. Complex.obj - 8 error(s), 0 warning(s)
ياليت إذا تقدرون تساعدوني وتفهموني سبب هالأخطاء !!
Wase3 Sadr