Saturday 17 September 2011

Complex number using object as argument


Complex number using object as argument
Aim:
To write a C++ program to add two complex numbers using object as argument.
Algorithm:
Step 1: Create a class as complex.
Step 2: Declare the data members as real and img.
Step 3: Declare the member functions as
void getdata()
void show()
void sum(complex c1,complex c2)
Step 4: getdata() method is used to get the values .
Step 5: show() method is used to display the values.
Step 6: sum() method is used to perform addition operation using object as argument.
Step 7: In main, create the object for Complex class.
Step 8: Call the function using objectname.functionname();
Program:
#include<iostream.h>
#include<conio.h>

class complex
{
int real;
int img;
public:
void getdata()
{
cout<<"Enter the real and img part";
cin>>real>>img;
}
void show()
{
cout<<"\n"<<real<<"+"<<img<<"i"<<"\n";
}
void add(complex c1,complex c2);
};

void complex::add(complex c1,complex c2)
{
real=c1.real+c2.real;
img=c1.img+c2.img;
}

void main()
{
clrscr();
complex c1,c2,c3;
c1.getdata();
c2.getdata();
c3.add(c1,c2);
cout<<"The complex number of c1:";
c1.show();
cout<<"The complex number of c2:";
c2.show();
cout<<"The result is:";
c3.show();
}

Output:

Enter the real and img part 4 5
Enter the real and img part 2 3

The complex number of c1:
4+5i

The complex number of c2:
2+3i

The result is:
6+8i



1 comments:

otr214423 said...


Problem: HP Printer not connecting to my laptop.

I had an issue while connecting my 2 year old HP printer to my brother's laptop that I had borrowed for starting my own business. I used a quick google search to fix the problem but that did not help me.

I then decided to get professional help to solve my problem. After having received many quotations from various companies, i decided to go ahead with Online Tech Repair (www.onlinetechrepairs.com).

Reasons I chose them over the others:
1) They were extremely friendly and patient with me during my initial discussions and responded promptly to my request.
2) Their prices were extremely reasonable.
3) They were ready and willing to walk me through the entire process step by step and were on call with me till i got it fixed.

How did they do it
1) They first asked me to state my problem clearly and asked me a few questions. This was done to detect any physical connectivity issues with the printer.
2) After having answered this, they confirmed that the printer and the laptop were functioning correctly.
3) They then, asked me if they could access my laptop remotely to troubleshoot the problem and fix it. I agreed.
4) One of the tech support executives accessed my laptop and started troubleshooting.
5) I sat back and watched as the tech support executive was navigating my laptop to spot the issue. The issue was fixed.
6) I was told that it was due to an older version of the driver that had been installed.

My Experience
I loved the entire friendly conversation that took place with them. They understood my needs clearly and acted upon the solution immediately. Being a technical noob, i sometimes find it difficult to communicate with tech support teams. It was a very different experience with the guys at Online Tech Repairs. You can check out their website www.onlinetechrepairs.com or call them on 1-914-613-3786.
Would definitely recommend this service to anyone who needs help fixing their computers.
Thanks a ton guys. Great Job....!!

Post a Comment