/* Sip no : 2-1 Write a C++ program
using class which contains two data members of type integer. Create and
initialize the object using default constructor, parameterized constructor and
parameterized constructor with default value. Write a member function to display
maximum from given two numbers for all objects.*/
#include<stdio.h>
#include<conio.h>
#include<iostream.h>
class max
{
int
a,b;
public:
max()
{
cout<<"\nEnter
2 numbers : ";
cin>>a;
cin>>b;
}
max(int
a1,int b1)
{
a=a1;
b=b1;
}
max(int
a1,int b1=10)
{
a=a1;
b=b1;
}
void
maximum()
{
if(a>b)
cout<<endl<<a<<"is
greater";
else
cout<<endl<<b<<"is
greater";
}
};
void main()
{
int
c,d;
clrscr();
cout<<endl<<"enter
number";
cin>>c;
cin>>d;
max
a(12,56),b(c,d),e;
a.maximum();
b.maximum();
e.maximum();
getch();
}
/* Slip no 2_2: Create a class
Compelx Number contaning data member as:
- real
- imaginary
Write a C++ program to calculate
and display the sum of two complex numbers.
(Use friend function and return by object) */
#include<iostream.h>
#include<conio.h>
class complex
{
float
real;
float
imaginary;
public:
complex(float
a=0.0,float b=0.0)
{
real=a;
imaginary=b;
}
void
display()
{
cout<<"\n
real :"<<real;
cout<<"\n
imaginary :"<<imaginary<<"i";
}
friend
complex operator +(complex,complex);
};
complex operator +(complex
c1,complex c2)
{
complex
temp;
temp.real=c1.real+c2.real;
temp.imaginary=c1.imaginary+c2.imaginary;
return
temp;
}
void main()
{ float
n1,n2,n3,n4;
clrscr();
cout<<"\n
Enter 1st real and imaginary no : ";
cin>>n1;
cin>>n2;
complex
c1(n1,n2);
cout<<"\n
Enter 2nd real and imaginary no : ";
cin>>n3;
cin>>n4;
complex
c2(n3,n4),c3;
cout<<"\n
1st complex no is : ";
c1.display();
cout<<"\n
2nd complex no is : ";
c2.display();
c3=c1+c2;
cout<<"\n
After adding of float and imaginary no are :";
c3.display();
getch();
}
slips 2
Reviewed by Dinesh Varal
on
January 15, 2018
Rating:
Mast Bhaiii...
ReplyDeletety
Delete