C++ Code:
(4)
#include <iostream>
#include <vector>
using namespace std;
//Point class definition
class Point2D
{
//Private member variables
private:
double XCord, YCord;
//Public methods
public:
//Default
Constructor
Point2D()
{
XCord = 0;
YCord = 0;
}
//Constructor that
has 2 parameters(x coordinate , y coordinate)
Point2D(double x, double
y)
{
//Setting x,y values
XCord = x;
YCord = y;
}
//Function that sets
X Co-ordinate
void setXCord(double
x)
{
XCord = x;
}
//Function that sets
Y Co-ordinate
void setYCord(double
y)
{
YCord = y;
}
//Function that
returns X Co-ordinate
double getXCord()
{
return XCord;
}
//Function that
returns Y Co-ordinate
double getYCord()
{
return YCord;
}
//Function that
returns distance from point to origin
double distance()
{
double dist;
//Calculating distance d = sqrt( x^2 + y^2 )
dist = sqrt( (double)(XCord*XCord) + (double)(YCord*YCord) );
//Return distance
return dist;
}
//Overloading
<< operator
friend ostream
&operator<<( ostream &output, const Point2D
&D)
{
//Forming a result statement
output << "(" << D.XCord << ", " << D.YCord
<< ")";
return output;
}
};
//Overloading less than operator
bool operator<(Point2D p1, Point2D p2)
{
//Comparing distances
if(p1.distance() < p2.distance())
{
return true;
}
return false;
}
//Function midpoint
void midPoint(vector<Point2D> points)
{
int smallest;
//Initially assume that starting point is the
smallest point
smallest = 0;
//Iterating over vector
for(int i=0; i<points.size(); i++)
{
//Comparing points
if(points.at(i) <
points.at(smallest))
{
//Updating smallest point
smallest = i;
}
}
//Displaying smallest point
cout << "\n\n Smallest Point: " <<
points.at(smallest) << " \n\n";
}
//Main method
int main()
{
Point2D point1(6.2, 4.8);
Point2D point2(3.6, 5.9);
Point2D point3(8.6, 1.3);
Point2D point4(6.5, 2.4);
Point2D point5(10.2, 1.2);
//Creating a vector
vector<Point2D> points;
//Adding points
points.push_back(point1);
points.push_back(point2);
points.push_back(point3);
points.push_back(point4);
points.push_back(point5);
//Iterating over vector
for(int i=0; i<points.size(); i++)
{
cout << "\n\n
Distance of Point " << (i+1) << " " <<
points.at(i) << " from origin: " <<
(points.at(i)).distance();
}
cout << "\n\n\n Midpoint: ";
//Calling midpoint method
midPoint(points);
return 0;
}
____________________________________________________________________________________________
Sample Run:

f. Demonstration polymorphic behavior by declaring a Point2D pointer and separately assigning a Point2D object then...
C++ Please help. 1) Create an array to store 10 Point2D points (the Point2D class from A6). Set the coordinates from 0,0 to 9,9. Move all the points left 5 units and up 10 units. Print their new location. 2) Make a new class Point3D which inherits from the Point2D class. The class has one more data member for the z coordinate. There are two constructors, a default one and one with 3 coordinates. Add the new member functions getZ,...
This is my code that i need to finish. In BoxRegion.java I have no idea how to create the constructor. I tried to use super(x,y) but It is hard to apply. And Also In BoxRegionHashTable, I don't know how to create displayAnnotation BoxRegion.java ------------------------------------------------ public final class BoxRegion { final Point2D p1; final Point2D p2; /** * Create a new 3D point with given x, y and z values * * @param x1, y1 are the x,y coordinates for point...
The purpose of this is to use inheritance, polymorphism, object
comparison, sorting, reading binary files, and writing binary
files. In this application you will modify a previous project. The
previous project created a hierarchy of classes modeling a company
that produces and sells parts. Some of the parts were purchased and
resold. These were modeled by the PurchasedPart class. Some of the
parts were manufactured and sold. These were modeled by the
ManufacturedPart class. In this you will add a...
I am having trouble understanding how this code is able to use the contents of the header file. Can someone please provide comments in the main code to describe what is happening? (especially on the bool isNumber) THE MAIN CODE: #include<bits/stdc++.h> #include "MyCartesianPoint.h" #include <math.h> #include <iostream> using namespace std; bool isNumber(string s) { if(!isdigit (s[0])) { if(s[0] != '-') return false; else if(s.length() == 1) return false;...
Hello I need help with this program. Should programmed in C!
Program 2: Sorting with Pointers Sometimes we're given an array of data that we need to be able to view in sorted order while leaving the original order unchanged. In such cases we could sort the data set, but then we would lose the information contained in the original order. We need a better solution. One solution might be to create a duplicate of the data set, perhaps make...
please
there are some specific instructions on the question so i would
greatly appreciate if they are followed . thank you very much for
your time
This lab covers: arrays functions input exception handling Question 1 The purpose of this question is to write a python program (script) that manipulates arrays using vector arithmetic. You will compute the values of points The ellipse has a major axis whose length is a and a minor axis whose length is b. For...
I am having trouble understanding how this code is able to use the contents of the header file. Can someone please provide brief comments in the top code to show what is happening? THE CODE: #include<bits/stdc++.h> #include "MyCartesianPoint.h" #include <math.h> #include <iostream> using namespace std; bool isNumber(string s) { if(!isdigit (s[0])) { if(s[0] != '-') return false; else if(s.length() == 1) return false; } for...
: Implement the following given scenario in C++ a. Create an inheritance hierarchy by writing the source code, containing base class BankAccount and derived classes SavingsAccount and CheckingAccount that inherit from class BankAccount. b. Implement Polymorphism where required to achieve the polymorphic behavior. c. Multiple constructors be defined for initializing the account of a user. d. The class should provide four member functions. i. Member function Credit should add an amount to the current balance. ii. Member function Debit should...
Advanced Object-Oriented Programming using
Java
Assignment 4: Exception Handling and Testing in
Java
Introduction - This assignment is
meant to introduce you to design and implementation of
exceptions in an object-oriented language. It will
also give you experience in testing an
object-oriented support class.
You will be designing and implementing a version of the game
Nim. Specifically, you will design and implement a
NimGame support class that stores all actual
information about the state of the game, and detects and throws...
Need some help with this C++ code. Please screenshot the code if possible. Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of...