Answered step by step
Verified Expert Solution
Question
1 Approved Answer
CP220 Bonus Exercise-Vectors Preamble Vectors are sets of values representing a point in space. Graphically they can be represented as an arrow with a length
CP220 Bonus Exercise-Vectors Preamble Vectors are sets of values representing a point in space. Graphically they can be represented as an arrow with a length and direction. Here, we have a class Vector which defines a 2-dimensional vector: class Vector // The x coordinate of the object. public double x; // The y coordinate of the object. public double y; public Vector (double x, double y) this.x-x; public Vector(Vector other) this.x this,y other.x; othery; - = // Computes the length of this object. // Returns the result. CP220-2 Bonus Assignment 1.pdf Adobe Acrobat Reader DO File Edit View Window Help Home Tools Sign In CP220-2 Bonus Ass... X t Share // Computes the length of this object // Returns the result public double Length) Export PDF return Math.Sqrt(this.x * this.x + this.y *this.y); Create PDF OE Edit PDF // Computes the dot product between this and other. / Returns the result public double Dot (Vector other) F Comment Combine Files Organize Pages Redact Protect Optimize PDF return this.x * other.x + this.y *other.y; // Computes the angle between this and other. // Returns the result public double Angle(Vector other) return Math.Acos(this.Dot (other) / this.Length) / other.Length)) // Produces a string representation of the object public override string ToString() Fill&Sian return String.Format(e:F1), 1:F1)>", this.x, this.y); Convert and edit PD s with Acrobat Pro DC Start Free Trial 2:34 PM 3/5/2019 Type here to search Create an empty C# Console Application and add this class to your project You will be using this class for the remainder of the assignment. n a new document (e.g. .docx, .txt, etc.),use the provided code to complete the following tasks: Identify each data member of the Vector class, including its name and its data type. Identify each member function, including the names and data types of its parameters, and what type of value the function returns Identify each constructor. Describe its parameters including their names and data types. Describe the apparent purpose of each 1. 2. 3. Creating a Vector object In Main, create a Vector object. Print the object and its length to the console Creating a Vector object In Main, create a Vector object. Print the object and its length to the console. Vector myVectornew Vector (1, 2); Console.Write(myVector); Console.Write("); Console.WriteLine(myVector.Length)) Answer the following questions: 4. 5. 6. What's the length of your vector myVector? What is the purpose of providing values 1 and 2 in the expression "new Vector (1, 2)"? How does Console.Write(myVector) know how to format the object correctly for output? Value or reference? Create a second Vector variable in Main and assign it the value of myVector: Vector myOtherVector myVector Next, change its x and y values: myOtherVector.x 1; myOtherVector.y 20; Value or reference? Create a second Vector variable in Main and assign it the value of myVector: Vector myOtherVector-myVector; Next, change its x and y values: myOtherVector.x -10; myOtherVector.y20; Finally, print both the original vector variable myVector and the new vector variable myOtherVector to the console: Console.WriteLine (myVector); Console.WriteLine (myOtherVector); Answer the following questions 7. 8. What are myVector's values for x and y before and after modifying myOtherVector? Does myVector change when modifying myOtherVector? If so, why? If not, why? Creating an array of Vector objects Create an array of five Vector objects of your own design. Vector[] myVectors/* CP220 Bonus Exercise-Vectors Preamble Vectors are sets of values representing a point in space. Graphically they can be represented as an arrow with a length and direction. Here, we have a class Vector which defines a 2-dimensional vector: class Vector // The x coordinate of the object. public double x; // The y coordinate of the object. public double y; public Vector (double x, double y) this.x-x; public Vector(Vector other) this.x this,y other.x; othery; - = // Computes the length of this object. // Returns the result. CP220-2 Bonus Assignment 1.pdf Adobe Acrobat Reader DO File Edit View Window Help Home Tools Sign In CP220-2 Bonus Ass... X t Share // Computes the length of this object // Returns the result public double Length) Export PDF return Math.Sqrt(this.x * this.x + this.y *this.y); Create PDF OE Edit PDF // Computes the dot product between this and other. / Returns the result public double Dot (Vector other) F Comment Combine Files Organize Pages Redact Protect Optimize PDF return this.x * other.x + this.y *other.y; // Computes the angle between this and other. // Returns the result public double Angle(Vector other) return Math.Acos(this.Dot (other) / this.Length) / other.Length)) // Produces a string representation of the object public override string ToString() Fill&Sian return String.Format(e:F1), 1:F1)>", this.x, this.y); Convert and edit PD s with Acrobat Pro DC Start Free Trial 2:34 PM 3/5/2019 Type here to search Create an empty C# Console Application and add this class to your project You will be using this class for the remainder of the assignment. n a new document (e.g. .docx, .txt, etc.),use the provided code to complete the following tasks: Identify each data member of the Vector class, including its name and its data type. Identify each member function, including the names and data types of its parameters, and what type of value the function returns Identify each constructor. Describe its parameters including their names and data types. Describe the apparent purpose of each 1. 2. 3. Creating a Vector object In Main, create a Vector object. Print the object and its length to the console Creating a Vector object In Main, create a Vector object. Print the object and its length to the console. Vector myVectornew Vector (1, 2); Console.Write(myVector); Console.Write("); Console.WriteLine(myVector.Length)) Answer the following questions: 4. 5. 6. What's the length of your vector myVector? What is the purpose of providing values 1 and 2 in the expression "new Vector (1, 2)"? How does Console.Write(myVector) know how to format the object correctly for output? Value or reference? Create a second Vector variable in Main and assign it the value of myVector: Vector myOtherVector myVector Next, change its x and y values: myOtherVector.x 1; myOtherVector.y 20; Value or reference? Create a second Vector variable in Main and assign it the value of myVector: Vector myOtherVector-myVector; Next, change its x and y values: myOtherVector.x -10; myOtherVector.y20; Finally, print both the original vector variable myVector and the new vector variable myOtherVector to the console: Console.WriteLine (myVector); Console.WriteLine (myOtherVector); Answer the following questions 7. 8. What are myVector's values for x and y before and after modifying myOtherVector? Does myVector change when modifying myOtherVector? If so, why? If not, why? Creating an array of Vector objects Create an array of five Vector objects of your own design. Vector[] myVectors/*
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started