You are on page 1of 1

Capital University of Science and Technology

Department of Computer Science


CS1143 – Object Oriented Programming
Solution- QUIZ NO. 2
Semester: Spring 2023 Max Marks: 10
Instructor: Dr. Umair Rafique Date: 21st Mar,
2023
Name: Reg. No.

Question:
Write a function to compute distance between two point objects.

#include <iostream>
#include <math.h>
using namespace std;
class Point
{
public:
int x;
int y;
double distance(Point &temp);
};

double Point :: distance(Point &temp)


{
double distance = sqrt ((x-temp.x)*(x-temp.x) + (y-temp.y)*(y-temp.y));
return distance;
}

int main ( )
{
Point p1, p2;
p1.x=0;
p1.y=0;
p2.x=5;
p2.y=5;
cout<<"The distance is: "<<p1.distance(p2)<<endl;
cout<<pow(4,0.5);
return 0;
}

You might also like