{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

cpp2_code_x08

# cpp2_code_x08 - Name_SOLUTION KEY Username_Key 1(15pts...

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

Name _____SOLUTION KEY ________________ Username ___Key ________________ 1. (15pts) Write a function called copy() that copies a one-dimensional array into a 2- dimensional array. Prototype: void copy(double A[][100], B[],int N, int K) Where A is the 2-dim array and B is the one-dim array. K is the number of elements of B and N indicates the row number of A, which B will be copied to. In other words, B[0] -> A[N][0] B[1] -> A[N][1] B[2] -> A[N][2] .. .. B[K-1] -> A[N][K-1] --------------------------------------------------------- Your Solution ------------------------------------------------------- void copy(double A[][100], B[],int N, int K){ for ( int i = 0; i < K; i++) A[N][i] = B[i]; }

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

View Full Document
2. (15pts) This question is related to project 6. You are asked to add a method called direction(position p) in the position() class. This method returns a number from 1 to 4. Where 1 represents northeast, 2 northwest, 3 southwest and 4 southeast. It determines in which direction we need to move to reach the position p. The prototype is given below. int position::direction(position p); Example: position p1, p2; p1.setPosition(2,3); p2.setPosition(4,-1); cout << p1.direction(p2)<< endl; //move from p1 to p2 cout << p2.direction(p1)<< endl; //move from p2 to p1 Output: 4 2
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