CSE240 – Assignment 6 Points 50 Introduction The aim of this assignment is to ha
ID: 3739440 • Letter: C
Question
CSE240 – Assignment 6
Points 50
Introduction
The aim of this assignment is to have you work with Object Oriented C++ with simple inheritance.
Objectives
? Build a Point3D Class
? Build a Vector3D Class that inherits from Point3D
? Demonstrate the classes working
Outcomes:
? Creation and use of classes
? Inheritance
? Pointer use, management and manipulation
Description:
You will create two classes for this project. The first will be a basic 3D Cartesian- Coordinate that stores and X,Y,Z value and has a distance formula function to get the distance between two points.
The second class is a 3D Vector class that will do basic vector math. It will inherit from the Cartesian coordinate since both share a similar base.
Specifications
Point3D.h/.cpp
? double x,y,z Method:
? Constructor taking in x,y,z
? Getters and Setters
double GetDistance(Point3D*)
Vector3D.h/.cpp
This class inherits from Point3D since it also contains: X,Y,Z values and requires a distance formula.
? double size – the size of the vector
? double ux,uy,uz – the vector components as a unit vector
? double angle – angle in radians
? Vector3D(x,y,z) - Constructor that takes in X,Y,Z then calculates size, angle and unit vector
? Vector3D(p1,p2) - Constructor that takes in two Point3Ds and makes a vector from them
? private CalculateSize()
? private CalculateUnitVector()
? public Vector3D* getUnitVector()- create and return the unit vector
? public double dotProduct(Vector3D* other) – returns dot product
? public Vector3D* crossProduct(Vector3D* other) – returns cross product vector
? public Vector3D* add(Vector3D* other) – add two vectors together get a third
? public Vector3D* subtract(Vector3D* other) – subtract two vectors together get a
third
? public void scale(double value) – multiply the vector by the value, don’t forget
you might need to recalculate angle, size and unit vector components
? Getters and setters
? Anything else you need to make these things work!
Main.cpp
Create a simple program showing off ALL the functionality of your classes.
Extra Credit Opportunity
Overload the +, -, and * operators with add, subtract and scale functionality for the Vector3D class as described above (+3)
Overload the % operator in Point3D to return the distance between two points. (+2)
Grading of Programming Assignment
The TA will grade your program following these steps:
(1) Compile the code. If it does not compile, If it does not compile you will receive a U on the Specificationsin the Rubric
(2) The TA will read your program and give points based on the points allocated to each component, the readability of your code (organization of the code and comments), logic, inclusion of the required functions, and correctness of the implementations of each function.
Rubric:
What to Submit?
You are required to submit your solutions in a compressed format (.zip). Zip all files into a single zip file. Make sure your compressed file is labeled correctly - lastname_firstname6.zip.
The compressed file MUST contain the following:
? lastname_firstname_hw6.cpp (where the main is)
? lastname_Point3D.h & .cpp files
? lastname_Vector3D.h & .cpp files
No other files should be in the compressed folder.
If multiple submissions are made, the most recent submission will be graded, even if the assignment is submitted late.
1. The list below shows the occurrences of key conodont species in the Usolka River section. Using this data, plot the ranges of all conodont species on figure 2.3. Ranges of S. bellus, S. pawhuskaensis, and S. brownvillensis have already been done by way of example. Sample 13 S. bellus, S. pawhuskaensis Sample 15/1 S. pawhuskaensis, S. brownvillensis Sample 16/1 S. brownvillensis, S. simplex Sample 16/2 S. brownvillensis Sample 16/3 S simplex, S. wabaunsensis Sample 16/4 S. wabaunsensis Sample 16/5 S. wabaunsensis, S. isolatus Sample 16/6 S. wabaunsensis, S. isolatus, S. cristellaris, S. longissimus Sample 16/7 S. cristellaris Sample 18/1 S. longissimus, S. constrictus Sample 20 S. longissimus, S. barskovi Sample 21 S. constrictus, S. barskovi 19 18 17 16 15 14 13 18/4 graded bedding 18/3 18/2 18/1 17 16/7Explanation / Answer
#include <iostream>
#include <math.h>
using namespace std;
class Point3D{
protected:
double x,y,z;
public:
Point3D(double X, double Y, double Z){
this->x = X;
this->y = Y;
this->z = Z;
}
void setX(double X);
void setY(double Y);
void setZ(double Z);
double getX();
double getY();
double getZ();
double getDistance(Point3D point);
};
void Point3D :: setX(double X){
this->x = X;
}
void Point3D :: setY(double Y){
this->y = Y;
}
void Point3D :: setZ(double Z){
this->z = Z;
}
double Point3D :: getX(){
return this->x;
}
double Point3D :: getY(){
return this->y;
}
double Point3D :: getZ(){
return this->z;
}
double Point3D :: getDistance(Point3D point){
double tempX = (this->x - point.getX())*(this->x - point.getX());
double tempY = (this->y - point.getY())*(this->y - point.getY());
double tempZ = (this->z - point.getZ())*(this->z - point.getZ());
return pow((tempX+tempY+tempZ),.5);
}
class Vector3D : public Point3D{
private:
double size;
double ux, uy, uz;
double angle;
void calculateSize(){
double tempX = (this->x)*(this->x);
double tempY = (this->y)*(this->y);
double tempZ = (this->z)*(this->z);
this->size = pow((tempX+tempY+tempZ),.5);
}
void calculateUnitVector(){
this->ux = (this->x)/(this->size);
this->uy = (this->y)/(this->size);
this->uz = (this->z)/(this->size);
}
public:
Vector3D(double X, double Y, double Z) : Point3D(X,Y,Z){
calculateSize();
calculateUnitVector();
}
Vector3D(Point3D p1, Point3D p2):Point3D(p2.getX() - p1.getX(),p2.getY() - p1.getY(),p2.getZ() - p1.getZ()){
calculateSize();
calculateUnitVector();
this->x = ux;
this->y = uy;
this->z = uz;
this->size = 1;
}
Vector3D getUnitVector();
double dotProduct(Vector3D vect);
Vector3D crossProduct(Vector3D vect);
Vector3D add(Vector3D vect);
Vector3D subtract(Vector3D vect);
Vector3D scale(double val);
double getSize();
};
Vector3D Vector3D :: getUnitVector(){
Vector3D vect = Vector3D(this->ux, this->uy, this->uz);
return vect;
}
double Vector3D :: dotProduct(Vector3D vect){
return (this->x)*(vect.getX()) + (this->y)*(vect.getY()) + (this->z)*(vect.getZ());
}
Vector3D Vector3D :: crossProduct(Vector3D vect){
double tempX = this->y*vect.getZ() - this->z*vect.getY();
double tempY = -(this->x*vect.getZ() - this->z*vect.getX());
double tempZ = this->x*vect.getY() - this->y*vect.getX();
Vector3D temp = Vector3D(tempX,tempY,tempZ);
return temp;
}
Vector3D Vector3D :: add(Vector3D vect){
Vector3D temp = Vector3D(this->x + vect.getX(),this->y + vect.getY(),this->z + vect.getZ());
return temp;
}
Vector3D Vector3D :: subtract(Vector3D vect){
Vector3D temp = Vector3D(this->x - vect.getX(),this->y - vect.getY(),this->z - vect.getZ());
return temp;
}
Vector3D Vector3D :: scale(double val){
Vector3D temp = Vector3D(this->x*val,this->y*val,this->z*val);
return temp;
}
double Vector3D :: getSize(){
return this->size;
}
int main()
{
Point3D p1 = Point3D(3,4,5);
Point3D p2 = Point3D(6,8,10);
cout << "The distance between p1 and p2 is " << p1.getDistance(p2) << endl;
Vector3D v1 = Vector3D(p1.getX(),p1.getY(),p1.getZ());
Vector3D v2 = Vector3D(p2.getX(),p2.getY(),p2.getZ());
Vector3D addVect = v1.add(v2);
Vector3D subVect = v1.subtract(v2);
Vector3D scaleVect = v1.scale(5);
Vector3D uV1 = v1.getUnitVector();
Vector3D cPVect = v1.crossProduct(v2);
cout << "The unit vector of v1 = (" << v1.getX() << "," << v1.getY() << "," << v1.getZ() << ") is (" << uV1.getX() << "," << uV1.getY() << "," << uV1.getZ() << ")." << endl;
cout << "The dotProduct of v1 = (" << v1.getX() << "," << v1.getY() << "," << v1.getZ() << ") and v2 = (" << v2.getX() << "," << v2.getY() << "," << v2.getZ() << ") is " << v1.dotProduct(v2) << endl;
cout << "The crossProduct of v1 = (" << v1.getX() << "," << v1.getY() << "," << v1.getZ() << ") and v2 = (" << v2.getX() << "," << v2.getY() << "," << v2.getZ() << ") is (" << cPVect.getX() << "," << cPVect.getY() << "," << cPVect.getZ() << ")." << endl;
cout << "The addition of v1 = (" << v1.getX() << "," << v1.getY() << "," << v1.getZ() << ") and v2 = (" << v2.getX() << "," << v2.getY() << "," << v2.getZ() << ") is (" << addVect.getX() << "," << addVect.getY() << "," << addVect.getZ() << ")." << endl;
cout << "The subtraction of v1 = (" << v1.getX() << "," << v1.getY() << "," << v1.getZ() << ") and v2 = (" << v2.getX() << "," << v2.getY() << "," << v2.getZ() << ") is (" << subVect.getX() << "," << subVect.getY() << "," << subVect.getZ() << ")." << endl;
cout << "The scaled vector with value 5 of v1 = (" << v1.getX() << "," << v1.getY() << "," << v1.getZ() << ") is (" << scaleVect.getX() << "," << scaleVect.getY() << "," << scaleVect.getZ() << ")." << endl;
return 0;
}
In this code all classes are there. Put them in different files accordingly.
Also i was not able to add any functionality for angle as i was not able to understand what do we mean by angle of a vector.
Otherwise the code is running Fine.