Create a class ComplexNumber containing members as: - real - imaginary Write a C++ program to calculate and display the sum of two complex numbers.
//If you are not using Borland or Turbo C then Add the following line after header files :
//using namespace std;
#include<conio.h>
#include<iostream.h>
class complex
{
int real,imag;
public:
void accept()
{
cout<<"\nEnter real no: ";
cin>>real;
cout<<"\nEnter imaginary: ";
cin>>imag;
}
void dis()
{
cout<<"complex no is : "<<real<<" + "<<imag<<" i"<<endl;
}
friend void cal(complex &a,complex &b); //decalaration of friend function
void display()
{
cout<<"Addition is : ";
cout<<real<<" + "<<imag<<" i";
}
};
void cal(complex &a,complex &b)
{
//addtion of real and imaginary no
a.real=a.real+b.real;
a.imag=a.imag+b.imag;
}
int main()
{
complex c1,c2;// creating 2 instance of class complex
cout<<"Enter details of 1st no";
c1.accept();
cout<<"Enter details of 2nd no";
c2.accept();
c1.dis(); //display 1st no
c2.dis(); //display 2nd no
cal(c1,c2); //passing values to cal function
c1.display();
getch();
return(0);
}
-
Next Write a C++ program to create a class Date which contains three data members as dd, mm, yyyy. Create and initialize the object by using parameterized constructor and display date in dd-mon-yyyy format. (Input: 19-12-2014 Output: 19-Dec-2014) Perform validation for month.
-
Previous Write a C++ program to create a class Worker with data members as Worker_Name, No_of_Hours_worked, Pay_Rate. Write necessary member functions to calculate and display the salary of worker. (Use default value for Pay_Rate)
0 Comments