home *** CD-ROM | disk | FTP | other *** search
- // %PARAMETERS = "CH16LIST C:\UT2004"
- //Identifies the package
- //CH16_04LIST.uc
-
- class CH16_04LIST extends Commandlet;
-
- //#1
- //Definiom of struct data types at class scope
- //3D vector
- struct L3DVector{
- var float x;
- var float y;
- var float z;
- };
- //2D vector
- struct L2DVector{
- var float x;
- var float y;
- };
-
- function int Main(string Args){
-
- //#2
- //Declaration of identifiers for vecotrs
- //Using the data types created above
- local L3DVector v3DFirst;
- local L2DVector v2DFirst;
- local float rMagnitude;
-
- rMagnitude = 0;
-
- //#3
- // Initialization of the 3D vector
- v3DFirst.x = 2;
- v3DFirst.y = 4;
- v3DFirst.z = 8;
-
- // Initialization of the 2D vector
- v2DFirst.x = 2;
- v2DFirst.y = 8;
-
- // #4
- // Calculation of the magnitude of the 3D vector
- rMagnitude = Sqrt(Square(v3DFirst.x)
- + Square(v3DFirst.y)
- + Square(v3DFirst.z));
-
-
- Log( Chr(10) $ Chr(10) $ " To calculate the magnitude of a vector, "
- $ Chr(10) $ " you take the square root of the sum of "
- $ Chr(10) $ " the squares of its constituent elements. ");
-
- Log(Chr(10) $" 3D Vector:" $ Chr(10));
- Log(Chr(10) $" The magnitude of [ "
- @ v3DFirst.x
- @ v3DFirst.y
- @ v3DFirst.z
- @ " ] is " @ rMagnitude);
-
- // #5
- // Calculation of the 2D vector
- rMagnitude = Sqrt( Square(v2DFirst.x) + Square(v2DFirst.y) );
-
- Log(Chr(10) $ " 2D Vector:" $ Chr(10));
- Log(Chr(10) $ " The magnitude of [ "
- @ v3DFirst.x
- @ v3DFirst.y
- @ " ] is "
- @ rMagnitude $ Chr(10));
-
-
- return 0;
- }
-
-
-
-
-
-