7.1

Crate a class FLOAT that contains one float data member. Overload all the four arithmetic operators so that they operate on the objects of FLOAT.

Answer

OUTPUT

F1 = 2.5
F2 = 3.1
F1+F2 = 5.6
F1-F2 = -0.6
F1*F2 = 7.75
F1/F2= 0.806452

7.2

Design a class Polar which describes a point in the plane using polar coordinates radius and angle. A point in polar coordinates is shown below figure 7.3
Use the overload + operator to add two objects of Polar.
Note that we cannot add polar values of two points directly. This requires first the conversion of points into rectangular coordinates, then adding the respective rectangular coordinates and finally converting the result back into polar coordinates. You need to use the following trigonometric formula:
x = r * cos(a);

polar-coordinates

y = r * sin(a);
a = atan(y/x); //arc tangent
r = sqrt(x*x + y*y);

Answer

OUTPUT

Enter radius and angle : 10 45
P1:
radius = 10
angle = 44.999998
P2 :
radius = 8
angle = 44.999998
P3 :
radius = 18
angle = 44.999998

7.3

Create a class MAT of size m * n. Define all possible matrix operations for MAT type objects.

Answer

OUTPUT

Enter first matrix size : 2  2

m1 =

1     2

3     4

Enter second matrix size : 2    2

m2 =

5     6

7     8

m1 =

1     2

3     4

m2 =

5     6

7     8

m1+m2:

6       8

10     12

m1-m2:

-4       -4

-4      -4

m1 x m2:

19      22

43     50

7.4

Define a class String. Use overload == operator to compare two strings.

Answer

OUTPUT

Enter 1st string : our sweetest songs tel our saddest thought
enter 2nd string : a burning desire lead to success.
Two string are not equal

7.5

Define two classes Polar and Rectangle to represent points in the polar and rectangle systems. Use conversion routines to convert from one system to the other.

Answer

OUTPUT

Press 1 to input certecian point
Press 2 to input polar point
what is your input ? 1
Enter the value of x & y : 4 5
POLAR FORM :
r = 6.403124
theta = 51.340073 degree


Next Previous