

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A line is formed using two points. Create two classes called Line and Point. Point class should only have two variables called x and y. Write code for these two classes such that the following code in main() can be run: int main() { Line newLine; newLine.set1stPoint(0,0); newLine.set2ndPoint(10,10); cout << newLine.getSlope(); return 0; } The function getSlope() should return the slope of a line using the formula (y2 − y1) / (x2 − x1). Define the function getSlope() outside the class.
Typology: Quizzes
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Q.1 (Marks 10) A line is formed using two points. Create two classes called Line and Point. Point class should only have two variables called x and y. Write code for these two classes such that the following code in main() can be run: int main() { Line newLine; newLine.set1stPoint(0,0); newLine.set2ndPoint(10,10); cout << newLine.getSlope(); return 0; } The function getSlope() should return the slope of a line using the formula (y2 − y1) / (x2 − x1). Define the function getSlope() outside the class. Ans: #include
Object Oriented Programming Page 1 of 2