C / C++ Code Portfolio


Operator Overloading: Complex Numbers



Download 112,15 Kb.
bet15/30
Sana01.03.2022
Hajmi112,15 Kb.
#475852
1   ...   11   12   13   14   15   16   17   18   ...   30
Bog'liq
dddd

Operator Overloading: Complex Numbers
#ifndef CHRISBERGER_COMPLEX_H
#define CHRISBERGER_COMPLEX_H

#include


using std::ostream;
using std::istream;
namespace ChrisBerger
{
class Complex
{
// prototype for friend << overloader
friend ostream &operator<<(ostream &out, const Complex &value);
// prototype for friend >> overloader
friend istream &operator>>(istream &in, Complex &value);
public:
// constructor with defualt values taking two argumnets
Complex(double real = 0, double imaginary = 0);
// prototype for + operator overloader
Complex operator+(const Complex &other) const;
// prototype for - operator overloader
Complex operator-(const Complex &other) const;
// prototype for == operator overloader
bool operator==(const Complex &other) const;
// prototype for != operator overloader
bool operator!=(const Complex &other) const;
private:
// data members for real and imaginary components
double real, imaginary;
};
}

#endif // !CHRISBERGER_COMPLEX_H


#include "Complex.h"


#include

using std::ostream;
using std::istream;

// constructor taking two double arguments


ChrisBerger::Complex::Complex(double real, double imaginary) : real(real), imaginary(imaginary)
{ }

// + operator overloader


ChrisBerger::Complex ChrisBerger::Complex::operator+(const ChrisBerger::Complex &other) const
{
return Complex(real + other.real, imaginary + other.imaginary);
}

// - operator overloader


ChrisBerger::Complex ChrisBerger::Complex::operator-(const ChrisBerger::Complex &other) const
{

Download 112,15 Kb.

Do'stlaringiz bilan baham:
1   ...   11   12   13   14   15   16   17   18   ...   30




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish