{John Lynch
CS382-60
12/18/00
project1
Language: Pascal
Purpose: vector arithmetic

This program takes two vectors prints out their coordinates and calculates
 the norm of each vector and then adds them}
program vectors (input, output);


type 
	vector = array [1..3] of integer;
	
{global variables to hold values of the vectors 
and thier norms}
var
	t, u, v : vector;
	unorm : real;
	vnorm : real;

				
	{write out the coordinates of the vector}
	procedure writevector(var w : vector);
		{the variable f is used by a for loop to
		 print out each value in an array(vector)}
		var
			f : integer;
		begin
			for f := 1 to 3 do
			begin
				write(w[f]:3);
				write(',');
			end;
		end; {writevector}

		
	{calculate the norm of the vector}	
	procedure calcnorm (var w : vector; var normvalue : real);
		{the variable d is used by a for loop that 
		adds the squares of each array value}
		var
			d : integer;
		begin			
			for d := 1 to 3 do
			begin
				normvalue := normvalue + sqr (w[d]);
			end;
			normvalue := sqrt(normvalue);
		end; {calcnorm}


	{calculate the addvectors}	
	procedure addvectors (var w, z : vector);
		{the variable d is used by a for 
		loop that adds two arrays}
		var
			d : integer;
		begin			
			for d := 1 to 3 do
			begin
				t[d] := z[d]+w[d];
			end;
		end; {addvectors}
begin
	{assign values to the first array,v 
	and second array u}
	v[1] := 1;
	v[2] := 5;
	v[3] := 15;
	
	u[1] := 4;
	u[2] := 3;
	u[3] := 5;
	


	{the folling statments call the above 
	procedures and print out results}	
	write('The coordinates of vector v are ');
	writevector (v);
	writeln;
	writeln;
	
	write('The norm of vector v is ');
	calcnorm (v, vnorm);
	write(vnorm:5:2);
	writeln;
	writeln;
	
	write('The coordinates of vector u are ');
	writevector (u);
	writeln;
	writeln;
	
	write('The norm of vector u is ');
	calcnorm (u, unorm);
	write(unorm:5:2);
	writeln;
	writeln;
	
	addvectors (u, v);
	write('The vector that results from adding u and v is: ');
	writevector (t);	
end. {vectors}