progenius


{ City }
< Country > india
* Profession *
User No # 95226
Total Questions Posted # 0
Total Answers Posted # 3

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 29
Users Marked my Answers as Wrong # 16
Questions / { progenius }
Questions Answers Category Views Company eMail




Answers / { progenius }

Question { 52051 }

c++ program to add 2 complex number using operator
overloading technique


Answer

Write a C++ program to create a class called COMPLEX and
implement the following overloading functions ADD that
return a COMPLEX number .
I. ADD(a,s2) - where a is an integer(real part) and s2 is a
complex number.
II. ADD(s1,s2) - where s1 and s2 are complex objects.


#include
#include
class complex
{
int r,i;
public:
void read();
void print();
friend complex add(int a,complex c);
friend complex add(complex c1,complex c2);
};
void complex::read()
{
cout<<"Enter real and imaginary\n";
cin>>r>>i;
}
void complex::print()
{
cout< }
complex add(int a,complex c)
{
complex t;
t.r=a+c.r;
t.i=c.i;
return t;
}
complex add(complex c1,complex c2)
{
complex t;
t.r=c1.r+c2.r;
t.i=c1.i+c2.i;
return t;

}
void main()
{
int a=2;
clrscr();
complex s1,s2,s3;
s1.read();
cout<<"\ns1 : ";
s1.print();
s2=add(a,s1);
cout<<"s2 : 2+s1\n";
cout<<" : ";
s2.print();
s3=add(s1,s2);
cout<<"s3=s1+s2\n";
cout<<"s1 : ";
s1.print();
cout<<"s2 : ";
s2.print();
cout<<"s3 : ";
s3.print();
getch();
}


MORE C++ PROGRAMS AND SOLUTIONS:
1. ADDING 'TIME' OBJECTS AND DISPLAYING THE RESULT IN
HH:MM:SS FORMAT USING MEMBER FUNCTION

2. OPERATOR OVERLOADING - ADDITION, SUBTRACTION OF MATRICES
USING OPERATOR OVERLOADING

3. STACK IMPLEMENTATION USING OPERATOR OVERLOADING IN C++

http://programscpp.blogspot.in/

Is This Answer Correct ?    3 Yes 3 No

Question { IBM, 22951 }

1.program to add any two objects using operator overloading
2.program to add any two objects using constructors
3.program to add any two objects using binary operator
4.program to add any two objects using unary operator


Answer

Create a class called 'time' that has three integer data
members for hours, minutes and seconds, define a member
function to read the values, member operator function to add
time, member function to display time in HH:MM:SS format.
Write a main function to create two time objects, use
operator function to add them and display the results in
HH:MM:SS format.


#include
#include
#include
class time
{
int h,m,s;
public:
void read();
void print();
time operator+(time t2);
};
void time::read()
{
cout<<"\nEnter hour,minutes and seconds\n";
cin>>h>>m>>s;
}
void time::print()
{
cout<<"\nTime is-> "< cout<<":"< cout<<":"< }
time time::operator+(time t2)
{
time t;
t.h=h+t2.h;
t.m=m+t2.m;
t.s=s+t2.s;
return t;
}
void main()
{
clrscr();
time t1,t2,t3;
t1.read();
t1.print();
t2.read();
t2.print();
t3=t1+t2;
cout<<"\nTime1+ Time2:\n";
t3.print();
getch();
}

This link may help

http://programscpp.blogspot.in/2012/08/operator-overloading-adding-two-time.html

Is This Answer Correct ?    20 Yes 11 No


Question { NIIT, 7373 }

write a programming using for loop in c++ to generate diamond
trangel?


Answer

C++ program to print a diamond inside a box using asterisks.


#include
#include
#include
void main()
{
int i=0,j=0,num;
clrscr();
cout<<"Enter limit\n";
cin>>num;
cout< for(i=-(num+2);i<=num+2;i++)
{
for(j=-(num+2);j<=num+2;j++)
{
if(abs(i)+abs(j)<=num||j==-(num+2)
||j==(num+2)||i==-(num+2)||i==(num+2))
{
cout<<"*";
}
else
{
cout<<" ";
}
}
cout< }
getch();
}


Another solution for the same question :

http://programscpp.blogspot.in/2012/08/program-to-print-diamond-in-box-2.html

Is This Answer Correct ?    6 Yes 2 No