Page 614 - Computer science 868 Class 12
P. 614
Subject Code = 6, Marks = 98, Points = 1
Total Points = 7
Best 4 subjects
Code = 4
Code = 5
Code = 3
Code = 6
Program 18 D2 point
A Class d2point defines the coordinates of a point in a plane while another class d3point
defines the coordinates of a point in space. The details of both the classes are given below.
Class Name : d2point
Data Members
double x, y : To store x and y coordinates
Member Functions
d2point() : Constructor to assign 0 to x and y
d2point(double nx, double ny) : Constructor to assign nx to x and ny to y
double distance2d(d2point b) : To return distance between the point b and the current
point in the plane
Class Name : d3point
Data Members
double z : To store z coordinates
Member Functions
d3point() : Constructor to assign 0 to z
d3point(double nx, double ny,
double nz) : Parameterised constructor to assign the data member of
both classes
double distance3d(d3point b) : To return distance between the point b and the current
point in a space
Specify the class d2point giving details of the two constructors and functions double
distance2d(d2point b). Using concept of inheritance specify the class d3point giving details
of the two constructors and function double distance3d(d3point b).
1 import java.util.*;
2 class d2point
3 {
4 doublex,y;
5 d2point()
6 {
7 x=y=0;
8 }
612612 Touchpad Computer Science-XII

