C++ Programs by Yamrajbhalla
This Will Do the +,-,*and / of the complex numbers
/*Operator overloading for complex Numbers*/ #include#include class complex { float real; float img; public: complex() { real=img=0; } complex(float real,float img) { this->real=real; this->img=img; } void setcomplex(float r,float i) { real=r; img=i; } void print() { cout<
out put
(3+3i) + (5+5i) =(8+8i)
(3+3i) - (5+5i) =(-2+-2i)
(3+3i) * (5+5i) =(15+15i)
(3+3i) / (5+5i) =(0.6+0.6i)
Replies
-
pradeep_agrawalThe program looks good except the logic of for * (multiplication) and / (division). The code for that was mentioned as
complex operator *(complex c) {complex t; t.real=real*c.real; t.img=img*c.img; return t; } complex operator /(complex c) {complex t; t.real=real/c.real; t.img=img/c.img; return t; }
with output
(3+3i) * (5+5i) =(15+15i)
(3+3i) / (5+5i) =(0.6+0.6i)
The output should be
(3+3i) * (5+5i) = 3*5 + 3i*5 + 3*5i + 3i*5i = 15 + 15i + 15i -15 = (0+30i)
(3+3i) / (5+5i) = [(3+3i)/(5+5i)] * [(5-5i)/(5-5i)]
= (15 + 15i -15i + 15) / (25 + 25i -25i + 25) = 30/50 = 0.6 = (0.6+0i)
Coding for multiplication should be easy. Lets try coding for division.
-Pradeep -
shalini_goel14
Hey pradeep, Don't you think for division it should be like following :pradeep_agrawal(3+3i) / (5+5i) = [(3+3i)/(5+5i)] * [(5+5i)/(5+5i)]
= (15 + 15i -15i + 15) / (25 + 25i -25i + 25) = 30/50 = 0.6 = (0.6+0i)
Coding for multiplication should be easy. Lets try coding for division.
-Pradeep
(3+3i) / (5+5i) = [(3+3i)/(5+5i)] * [(5-5i)/(5-5i)]
Please correct me if anything wrong. ๐
Thanks ! -
pradeep_agrawalYes that should be [(3+3i)/(5+5i)] * [(5-5i)/(5-5i)].
I did all calculation using [(3+3i)/(5+5i)] * [(5-5i)/(5-5i)] but mentioned [(3+3i)/(5+5i)] * [(5+5i)/(5+5i)] by mistake.
Thanks for correcting me. I am modifying the above statement to reflect this.
-Pradeep -
yamrajbhallabro after posting this i have chnged the code for multiplication and divison bt i stuck with fever and i am nt able to update it
by the way thanks for view my post
You are reading an archived discussion.
Related Posts
Hello everyone,
Please do let me know what you think of the following by clicking on the link --> Theft, Copyright Infringement, File Sharing and Piracy
๐๐๐
Cheers,
Suyash
CEans,
Quick Heal CEan Of The Month, March '09 is..
๐Shalini Goel aka CEan - shalini_goel14 ๐
*Shalini Wins*
Quick Heal Total Security 2009 [10 in 1 protection for PC!]...
Discuss the announcement:
https://www.crazyengineers.com/forum/announcements/18864-quick-heal-cean-month-march-09-a.html
in this thread!
hi
why we use spice and can i get the spice s/w to my pc any site for free downloading
CEans,
CE experienced unexpected downtime of about 40-45 minutes today; starting at about 1:45 pm (IST).
We exceeded our bandwidh limits and started facing downtime. I had to buy more...