Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Programming language: Ada 95. Function Vector_Length You must write a function,

ID: 3786896 • Letter: P

Question

Programming language: Ada 95.

Function Vector_Length

You must write a function, Vector_Length, that takes in three real numbers through the parameter list. The three parameters should correspond to a coordinate in space, i.e. x, y and z. Function to calculate the length of the vector going from the origin to this coordinate. Length is also a real number.

Procedure Create_Vector_Data

A little background to this subtask.

We begin with a description that explains how the final shape is constructed. Otherwise it can be a little abstract. We limit ourselves a bit in the beginning and assume that we have a vector with length L that starts from point A (which is at the origin) and follow the Z axis.

From the original position we are turning down our vector for the x-axis with a given angle of view. This angle may only be in the range 0-180 degrees. The next step is that we are projecting the vector L on two axes. This provides that we have two new "vectors" as we call L1 and Lz which is located along the axis. We will get back to why we call one of the L1 (we have a reason to not call the Lx as one might in the first moment would call it).

If we imagine that we see this "top down" (i.e. that one sees from the arrow on the Z axis and looking down towards point A) so we can see the X-Y plane instead. We don't draw out the Lz and L in the picture, but they are obviously still in our memory.

What we do with L1 now is turning it in a counter-clockwise direction (i.e. towards the Y axis) with an angle vz located between 0 and 360 degrees. This means that we turn the whole L in the same way in the 3-dimensional space. Try to imagine how this looks. In the figure on the next page, you'll see how it looks. Projecting to L1 on the X and Y axes, we presented the vectors Lx and Ly. The vector L extends now from point A to a point in space that we call B (see figure on next page). B's coordinates (xB, yB, zB) can be calculated from point (A), by adding the three vectors Lx, Ly, Lz.

Now to your task. It is to go through the back door to the description above. This means the coordinates of points A and B and, from there, figure out L, vy and vz. You must write a procedure, Create_Vector_Data, which calculates these data given koordinarna for A and B (which comes in as parameters). The coordinates are given in centimeters. The procedure must return the three values; the length of the vector between A and B (L, in the drive), the angle between the z axis and the vector (view) as well as the angle in the X-Y plane as the vector has calculated from the x axis (vz). The angle of view is in the plane strapped up the z axis and the vector. See the figure below for more visual representation of the data that is given and what is expected of your procedure. In the figure, we assume for the sake of enkelhelts to (A) is at the origin, but your procedure to be able to handle that (A) is in a different location in the room (we can see it as a "virtual origin").

We selected the names view respective vz on the angles of the figure is due to the fact that one can see these angles as they specify how much to rotate a vector of y-and z-axis to get to this particular vector (described on the previous page). Revolutions are made then counter clockwise around the shoulder given to standing and looking toward the origin from the tip of the current axis.

It is clear that the input to the procedure is the integers, and it is intended that the procedure must return the vector data are rounded to whole numbers. As a result, the angles must be in degrees.

Tip 1: something you have to keep in mind is that one should get as good a value as possible on the angles. It should in principle be able to obtain coordinate B based on coordinate A and the output. It provides that it may not be able to count accurately all the time.

Tip 2: If result vector, length 0 (zero), it doesnt matter what angle the procedure returns. Hard to say what is right in this case.

Thought: Why can this not be a feature? To send the data and get the data.

On the next page follows a number of inputs with accompanying results (outputs) of the procedure Create_Vector_Data. Good to test these before reporting the laboratory work. Some values will be wrong if we do not ensure that use the rounded value of L for further calculations. This is due to people otherwise, values that don't "fit together" (that is, that you can not get back to their original values, if you count "backwards again").

A (x A, yA, zA) (0,0,0) A (xA, yA, zA) (0,0,0) A (xA, yA, zA) (0,0,0)

Explanation / Answer

#include<iostream>
#include<string>
#include<stdlib>


// during this example items aer represented as number values
// we are going to build them constants, in order that if at any time we would like to alter their values we will do thus here
// however can still ought to recompile

const int pawn = 100;
const int bishop = 305;
const int knight = 300;
const int rook = 500;
const int queen = 900;
const int king = 2000;

// an alternate would be to use string constants or another information kind

//now we want a board to place the items on and move around on
//the board information kind ought to match the items information kind
// the board in regular chess is usually 8x8, except for speedy legal move generator
//other programs use larger than 8x8 wherever Associate in Nursing 8x8 real board exists in an exceedingly larger array id est 12x14
// except for simplicity of understanding we are going to use the easy 8x8

int board[8][8];

// board [rank] [file];
// wherever rank = zero - seven (1 to eight on a true chess board) and file = zero - seven (a - h)

const startup[8][8] = ;

// the startup constant contains the quality beginning position of all chess games (not variants)
//each facet has eight items and eight pawns / all pawns ar on the colors individual ranks
// for black items we have a tendency to use -piecetype. (negative)

void setup (void) {
int i, j;
   for (i = 0; i < 8; i++){
       for (j = 0; j < 8; j++){
           board[i][j] = startup[i][j]; //setup beginning position
   }
       }

}

//the 2 for loops run through all the iteratins of the 8x8 array and replica the beginning position to the important board.

// next we want a operate which will show the board how either graphics or text
// during this case we are going to print to the screen a text version of the boards contents

//it is commonplace in FEN notations and different text of a chess board to specific each bit by it's 1st letter
// except the knight that uses 'N'

// the black items ar minuscule whereas the white items ar capital letter
// otherwise it's not possible to differentiate black items from white items

void printb (void)should be here so as to start mistreatment strings.
int a, b;
string piece;
for (a = seven; a > -1; a--){ // we have a tendency to should tell the ranks down from 7 to zero otherwise the board are going to be the wrong way up
cout << endl;
for (b = 0; b < 8; b++)
       if (passd.substr(0, 5) == "print") { // show the board
       printb();
       }
       if (passd.substr(0, 3) == "new") enkindle a brand new game
       setup();
       }
       if (passd.substr(0, 1) >= "a" && passd.substr(0, 1) <= "h" && passd.substr(1, 1) >= "1" && passd.substr(1, 1) <= "8" && passd.substr(2, 1) >= "a" && passd.substr(2, 1) <= "h" && passd.substr(3, 1) >= "1" && passd.substr(3, 1) <= "8") certain each squares ar on the chess board once capital punishment //a move
       // execute move
       // then show new board position

       int a, b, c, d;


       a = passd[0] - 'a';
       b = passd[1] - '1';
       c = passd[2] - 'a';
       d = passd[3] - '1';

//executes the move if its on the board!
       board[d][c] = board[b][a];
       board[b][a] = 0;

       printb(); //prints bent the screen the updated position when moving the items
       }
       }
}