cpp2_code_f07

# cpp2_code_f07 - USERNAME NAME_E2 1(15 pts This refers to...

This preview shows pages 1–2. Sign up to view the full content.

USERNAME ___________________ NAME ________________________________E2 1.(15 pts) This refers to pro6. Add a new method called Perpendicular2D() to the Vector class. Here is an example. Vector v1(1,1,0); Vector v2; v2 = v1.Perpendicular2D(); This method returns a vector that is perpendicular to vector v1. We will only consider the 2-dimensional case (z-component is 0). If v1 was 3- dimensional, then the method would return a zero vector (all components are zero). For the sake of simplicity, we will assume that the calling vector (v1 in the above example) is on the first quadrant ( 0 , 0 > y x ). To find the perpendicular vector: rotate the original vector 90 0 in counter-clockwise direction, as shown in the figure. Hint: In your solution, you can use the constructor that takes a magnitude and an angle as arguments. Sample Run: Vector v1(1,1,0), v3(1,1,2); Vector v2; v2 = v1.Perpendicular2D(); // v2 will be ( -1, 1, 0) v2 = v3.Perpendicular2D(); // v2 will be (0,0,0) --------------------------------------------- Your Solution -------------------------------------------- Vector Vector::Perpendicular2D(){ Vector zero; if( z != 0){ return zero; } double mag = sqrt(x*x + y*y); double ang = (atan(y/x)/PI)*180 + 90; Vector per(mag,ang); // Or replace these 3 lines with: Vector per( -y, x, 0); return per; }

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern