COSC 3319 Data Structures “Star Wars”

$30.00

Category: You will Instantly receive a download link for .zip solution file upon Payment || To Order Original Work Click Custom Order?

Description

5/5 - (2 votes)

This lab is meant to push you beyond your current level of expertise to new planes of achievement, i.e., professional grade. A goal of the assignment is to provide you the opportunity to research and master new technology either on your own or with a minimum of external help. I am always available for questions. Labs must be submitted in an envelope sufficiently large to hold your results without having to fold the lab materials. Write your name, “COSC 3319” and section number in the upper left hand corner of the envelope opposite the side the flap is folded. You may use the same envelope for all labs during the semester.

You must clearly state on the first page of your program (cover sheet) which grading option you have successfully completed. Programs failing to state the grading option will be graded as “C” option programs. Submit a printed copy of all code, any data files, and results. Do not embarrass yourself or me with screen shots. This lab is not technically challenging with respect to data structures. Its primary purpose is to ensure you gain the required background to complete “A” option work on future labs. Step up to “professional grade!”

Additional labs will be assigned prior to the due date. Do not procrastinate finishing this first assignment. It will ensure you master the language technology required to implement the advanced data structures labs. This lab is designed so you can start by implementing the “D” option first. The “D” option can be converted to the “C” option, then the “B” option, and finally the “A” option with minimal loss of effort. In essence, you tell me what you are worth! Be “Professional Grade!” Do the “A+” option.

Most of the grading options give you a choice of languages. You are encouraged to use Ada for several reasons. First, if you ever work with a company contracting with DOD (Department of Defense – possibly the largest contractors in the USA), aircraft companies, aerospace or European countries, knowledge of Ada is potentially an advantage. You should be able to use Ada, Java, Groovy, C++ or C# for the “B” and “A” options on all labs. You may use Ada, C++, C#, Java, Groovy or assembly for the “C” option on all labs. Use of Java or Groovy will normally result in a “5 point implementation fee (IMF)” for “B” and “A” options as Java and Groovy lack the required ability to manage memory etcetera in a real time environment with “hard real time constraints.” Due to experience from previous semesters, you may not use Python. This class is oriented towards a real time environment with some latitude. Python does not support the abstractions required for the advanced requirements on most labs. Experience indicates Python programmers spend excessive time researching Python to overcome its inherent short falls with respect to meeting real time restrictions. Substantial examples using Ada will be utilized in class over the next few weeks. You may use Ada code developed in class to implement labs.

If you work for bleeding edge technology companies, you will have to learn to change programming languages like you change your clothes. There are two required courses in Java (COSC1436 and COSC1437) and it is used in several other courses. “C/C++” is taught in COSC 2347 and used in several other courses. Ada will be used in this class, Software Engineering and Operating Systems when taught by me. The more languages you know prior to graduation, the easier it will be to learn new languages on the job after graduation. Most companies will expect you to learn new languages on your time using your own resources. You may record time in the lab using hours, minutes and seconds or simply the raw seconds count from the system clock.

“C”: Option (maximum grade is 75):
PROBLEM SPECIFICATION: Emperor Constantine has commanded Darth Vader to build and operate a warship repair facility for Tie Fighters and Star Destroyers. When a damaged vehicle arrives a service record must be placed in the appropriate service bay including the vehicles name and time of arrival. For security reasons, Tie fighters are assigned names of TieA, TieB etcetera. Likewise, Star Destroyers are given names of StarA, StarB etcetera. After a vehicles name ends in ‘Z’ the sequence is repeated from ‘A’. Lord Vader directed us to write a program for the facility providing support for two stacks or parish in the attempt. To minimize waste, the two stacks must occupy the same physical space, for example locations 1 through 20 for the “C” Option. The stack space must be allocated dynamically in the stack, not the heap (Box1.ada)! You must prompt the user at run time for the upper and lower array bounds. For the “C” option use 1 and 20 as the lower and upper bounds for the actual space used to track vehicles, i.e., the stack space will hold a maximum of 20 space vehicles. The following memory model was specified by Lord Vader using 1 and 20 for the lower and upper bounds respectively.

Stack Space (consisting of Maintenance records):
TieStack TTop STop StarStack M + 1
Tie base TieA TieB TieC

StarB StarA Star base
0 1 2 3 4 5 6 7 8 10 ●●● M = 20 21

Each time “push” is invoked, the Tie Fighter or Star Destroyer service record should be placed in the proper stack. When “push” is invoked if there is no available space, the space vehicle should be instructed to travel to the repair facility in the Dagaba system.
TTop = 0 and STop = 21 indicate the respective stacks are empty in the previous and following examples. I recommend the stack consist of records/objects of type “Vehicle Maintenance Record.” You should never need to use dynamic storage allocation in the heap!

The main repair center facility should operate as indicated below.

1) Write the start time from the system clock in the service log. Alternately use the elapsed time (ET) initialized to zero.

Assume there are 3 vehicles waiting for service when the facility opens. Place their vehicle maintenance records in the appropriate stacks. Determine statistically the type of vehicle using a step function. Out of every 4 arrivals (uniformly distributed) 3 should be Tie Fighters requiring 3 units of time for repair and 1 Star Destroyer requiring 7 units of time for repair.
Loop
1) Accept 1, 2, 3, or 4 new vehicles into the repair facility (equal probability). Only 1 vehicle may be repaired on each iteration through the repair facility.Determine statistically the type of the each new vehicle arriving for repair. Out of every 4 arrivals (uniformly distributed) 3 should be Tie Fighters requiring 3 seconds of time for repair and 1 Star Destroyer requiring 7 seconds of time for repair (use a step function). Place the vehicle maintenance record in the appropriate stack.

If the stack space is full reject the vehicle and send it to the repair facility in the Dagaba system. Clearly indicate vehicles that have been rejected including their name and time of rejection in the system log.

2) If a Star destroyer is available, repair it first (delay of 7.0 seconds to simulate the repair). It there are no Star Destroyers, then repair a Tie Fighter if available (delay of 3.0 seconds to simulate the repairs). It there are no vehicles currently in the system, go to the next step.

3) If a vehicle was serviced, update the elapsed time, “ET,” (or use the system clock) to reflect the time the service was completed, i.e., ET = ET + service time + 2.0 seconds to prepare the facility for the repair of the next space vehicle (alternately time completed = system clock + 2 seconds). Place the name of the vehicle serviced and elapsed time in the service log. Remember to remove serviced vehicles from their stack (pop).

4) Physically delay 2.0 seconds to prepare the facility for the repair of the next space vehicle if a vehicle was serviced.
End Loop;
5) Compute final results and print them in the system log when the 5th vehicle is rejected and sent to the Dagaba system.

Execute the above section of code at least 4 times starting with both queues empty till exactly 5 vehicles are refused entry to the system. Report the average number of Ties Fighters and average number of Star Destroyers repaired prior to meeting the goal of 5 refusals of service for each simulation (at least 4 runs with different initial seeds for the random number generator). How many vehicles of each type are serviced on each simulation by your program? On the average how many total vehicles are serviced for each simulation. Exhibit the results of your simulation runs in a formal report to Lord Vader in a tabular format! Professional use word processors, not paper and pencil. Include the output for all runs and your source code. “Data Driven Decision!”

Engineering requires the following design for the vehicle maintenance records expressed in UML/OMT, object oriented notation. For all grading options, management requires use of the system stack for all data structures. You may never use the heap. You will lose a minimum of 5 grade points every time you use “new,” “malloc’ or another dynamic storage allocator.

Vehicle Maintenance Record
Vehicle Type: (Value: “Tie Fighter” or “Star Destroyer,” 15 characters)
Vehicle Name: 8 characters
Time to repair: Your choice, probably integer, float or duration.
Start Time: Your choice: ET or clock when the vehicle is placed in the repair facility).
Finish Time: Your choice, ET or clock.
(time repairs are completed and vehicle leaves the facility)
Report ( — ); vehicle information on system log.

You may add data structures and methods to this framework as required.

Hint 0: UML/OMT
Class/Package Name
Data Structures
Methods (behavior: functions, procedures, etcetera)

Method “Report’ should print all available information on the vehicle at the time it enters and leaves the facility.

Hint 2: To determine the type of the next vehicle to arrive at the repair facility use a uniformly distributed random number where 0<= rand <1.0 and the following step function: 0 <= Rand < 0.75 then Tie Fighter 0.75 <= Rand < 1.0 then Star Destroyer Nearly all programming languages provide a uniformly distributed random number generator in the above range. Some languages provide uniformly distributed integers. Ada provides both. The above method works with all languages and allows for implementation of arbitrary step functions. Hint 3:To change the vehicle arrival pattern for each simulation, the seed to the random number generator must be changed for each new simulation, usually by large amounts. You are encouraged to minimize your effort by prompting the user for a seed each time you execute the simulation. Large, positive, odd, multiple digit integers are typically best. You may use the value on the system clock if desired.   “C+”: Option (maximum grade is 79): First answer the “C” option question. Second, the Emperor want to maximize the number of vehicles repaired prior to refusing 5 vehicles entry to the system. To accomplish this task should priority be given to repairing Tie Fighters or Star Destroyers? On average, how many vehicles will be serviced with each these 2 strategies?Support your answer with appropriate data in the form of a table and discussion in your report to Lord Vader! “B”: Option (maximum grade is 85): You need not do the “C“ Option. Rather complete the “C“ Option based on the following requirements. Determine statistically the repair time for vehicles. Tie Fighters require 2, 4 or 6 seconds time to repair with equal probability. Star Destroyers require 3, 4, 7 or 10 seconds for repair with equal probability. Answer the “C” option question. “B+”: Option (maximum grade is 89): You need not do the “C” options. Answer both the Emperor’s “C” and “C+” questions subject to the “B” service distributions. “A”: Option (maximum grade is 95): You need not do the “C“ or “B” Options. Rather answer the “C“ and “C+” option questions based on the following requirements: Out of every 4 arrivals (uniformly distributed) 3 should be Tie Fighters with 1 Star Destroyer. Place the vehicle maintenance record in the appropriate stack. Tie Fighters require 2, 3, 4 or 5 seconds to repair with equal probality. The time to repair a Star Destroyer is exponentially distributed with a mean of 10 seconds. Answer the “C” and “C+” Option questions subject to the “A” service distribution. “A+”: Option (maximum grade is 100): Complete the “A” Option. Answer both the Emperor’s “C” and “C+” questions subject to the “A” service distributions with something extra. You must receive approval from me for the “extra” prior to implementing the lab. As an example, implement Tie Fighters, Star Destroyers and the Repair Facility as separate task. I would be happy to provide hints and some sample code. You need not seek my approval to complete the following “extra” to meet “A+” option requirements. In addition to answering the Emperors question, provide the average, shortest and longest time spent in the repair facility for each type of vehicle. On average, how many vehicles remain in each stack at the time the simulation is terminated and for each vehicle type. Of the choices, which is the best strategy and why! Include your reasoning and support your conclusion with an appropriate table of data. &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& Sample Code and Hints HINT 3: The following algorithms have been suggested for the lab stack operations. Tie Empty: TTop = 0 Star Empty: Stop = 21 Push in Tie stack:: If TTop < (STop – 1) then TTop  Ttop + 1 StackSpace(Ttop)  y Else Report overflow End If Push in Star stack:: If STop > (TTop + 1) then
STop  Stop – 1
StackSpace(Stop)  y
Else
Report overflow
End If
Pop from Tie stack::
1) If TTop /= 0 then
Fix tie fighter
TTop  TTop – 1
Print “fixed” message
Else
Report underflow
End if
Pop from Star stack::
2) If STop < (M+1) then -- M + 1 = 21 Fix tie fighter STop  STop + 1 Print “fixed” message Else Report underflow End if SpaceAvailable( ):: If ( (TTop – 0) + (21 - STop) ) > 0
Return True
Else
Return False
End if SpaceAvailable( )::
If ( (TTop – 0) + (21 – STop) ) > 0
Return True
Else
Return False
End if
Method SpaceAvailable should be return true if there is at least 1 space available else return false.

The main procedure should continue to process transactions until the 5th vehicle is rejected and sent to the Dagaba system due to lack of space in the repair facility.

Hint 4:
Assume the name of your program is Pgm1.exe. If you type “Pgm1” at the DOS prompt, input is normally expected from the keyboard and results are printed on the terminal. The command “Pgm1 > file1” would expect all input to come from the keyboard but the results would be routed to a disk file in the current directory named “file1.” The command “Pgm1 < raw1 > results” would obtain input (as stream IO) from the file “raw1” and place the output in the text file “results” in the current directory.

Hint 5 (not everyone will need this):
Normally Ada will not allow an integer to be assigned to a character variable as bits must be truncated. Similarly, Ada will not normally allow a character to be assigned to an integer as there are not enough bits (padding must occur). In both cases, Ada will flag a probable error at compile time letting the programmer know they have probably made a logic error. To tell the compiler you really mean to perform the indicated operation, the generic package “Unchecked_Conversion” should be instantiated to allow the conversion as shown below. There is no actual runtime penalty for instantiations of Unchecked_Conversion (no run time function call) resulting in CPU overhead when using a good Ada compiler. The generic conversion is simply allowed at compile time as in the example below.

with Ada.Text_IO; use Ada.Text_IO; — read and write characters.
with Unchecked_Conversion; — standard package with every validated Ada translator

procedure ConvertCharacterInteger is
— To read and write 16 bit integers on the PC compiler.
package MyInt_IO is new Ada.Text_IO.Integer_IO(integer);
use MyInt_IO;

— instantiations to convert between integer and character formats, 16 bits versus 8 bits.
function integerToCharacter is new Unchecked_Conversion(Integer, Character);
function characterToInteger is new Unchecked_Conversion(Character, Integer);

c1, c2: Character;
int1, int2: Integer;

begin
c1 := ‘A’;
— int1 := c1; –error in Ada, strongly typed, suspects programmer error.
int1 := characterToInteger( c1 ); — Signal compiler to allow conversion.
put(” int1 = “); put(int1,4); put(“”);
put(“c1 = “); put(c1); new_line(2);

int2 := 66;
— c2 := int2; — error
c2 := integerToCharacter(int2);
put(” int2 = “); put(int2,4); put(“”);
put(“c2 = “); put(c2); new_line(2);

end ConvertCharacterInteger;

Hint 6: Using a “slice” to implement catenation.
A “slice” in Ada allows the user to treat a substring as a unit. Given str has the value “ABCD” str(2..3) refers to the characters in positions 2 through 3 ) as a group from the string str, i.e., ”BC.” “str(2..2) would be the second character in the string :B’.

Example:
S: string(1..10);
S(1..4) := “Bara”
S(4..7) := S(1..4);

Result: “S” is the string “BarBara” ****************** substring are helpful ***********

Hint 7: Using “enumeration types.”

subtype LastCharOfName is Character range ‘A’ .. ‘Z’;
LastCharName: LastCharOfName;

LastCharName := ‘A’; — or LastCharName := LastCharOfName’FIRST;
LastCharName := LastCharOfName’SUCC( LastCharName ); Sets LastCharName to ‘B’.

LastCharName := LastCharOfName’LAST; — sets LastCharName to ‘Z’.

*********************************************************** next character

Hint 8 (most likely needed if not using Ada):

In application programming, it is occasionally desirable to treat the same unit of memory at different times as a different data type!

Frequently used conversion trick in assembly, “C” and other languages.

ASCII Conversions
Character Decimal Integer Integer (32 bits) Binary
‘0’ 48 0 0-0000
‘1’ 49 1 0-0001
‘2’ 50 2 0-0001
‘3’ 51 3 0-0011
‘4’ 52 4 0-0100
‘5’ 53 5 0-0101
‘6’ 54 6 0-0110
‘7’ 55 7 0-0111
‘8’ 56 8 0-1000
‘9’ 57 9 0-1001

Assume we wish to convert a 32 bit one digit integer to an 8 bit ASCII character. This may be accomplished by adding the character ‘0’ (48 decimal) to the integer and dropping the leading 24 zeros. As an example the 32 bit integer 3 may be converted to a character by adding the character ‘0’ (or decimal 48) then truncating the leading 24 bits.

Ex: 3 + 48 = 3 + ‘0’ = 51 => ’3’ in ASCII

Alternately an ASCII digit represented as character may be converted to an integer by subtracting the character ‘0’ (or 48) and padding the 24 bits to the left with zeros.

Ex: ‘3’ – 48 = 51 – 48 = 3 => 3 in base 10 or 11 in binary.

Using “C:”
ch: char = ‘3’;
int1: int = 0;

int1 = (int)ch – 48; //first coerce/cast the character to an integer then convert to integer 3.
Or alternately:
int1 = int(ch) – 48; //function form of casting.

ch = char(3 + 48); // yields the character 3.
Or
ch = (char) (3 + 48); // yields the character 3.

Hint 9: Generic Arrays, passing I/O functions, and Generic Arrays

— In file GIOEX.ads. Creates a rectangle with user defined data type for length and
— width. Note that it is frequently desirable to pass methods including I/O routines
— for programmer defined data types.
— The following demonstrates how to pass I/O procedures to a generic package.
— The rectangle may also be used for inheritance if desired.

generic
type MyType is private;
with function “*”(X,Y: MyType) return MyType;
with procedure Put(X: MyType);
package GIOEX is
type Rectangle is tagged — Rectangle is exported without protection!
Record — Typically a bad decision. May use for inheritance.
Length: MyType;
Width: MyType;
end record;
function Size(r: in Rectangle) return MyType; — intrinsic functions
function RectLength(r: in Rectangle) return MyType;
end GIOEX;

–in file GIOEX.adb
with Ada.Text_IO; use Ada.Text_IO; — Access restricted to body.
package body GIOEX is

function Size(r: in Rectangle) return MyType is
begin
put(“The Size of the Rectangle with length “); put(r.Length);
put(” and width “); put(r.Width); put(” is “);
put( r.Length * r.Width); put(“!”); new_line(2);
return r.Length * r.Width;
end Size;

function RectLength(r: in Rectangle) return MyType is
begin
put(“The length is “); put(r.Length);
new_line;
return r.Length;
end;
end GIOEX;

— in file UGIOEXarray.adb
with GIOEX;
with Ada.Text_IO; Use Ada.Text_IO;
procedure UGIOEXarray is

package MyFloatIO is new Ada.Text_IO.Float_IO(Float);
use MyFloatIO;

— procedure Put( item: float; — Default I/O routine from generic instantiation.
— fore: Ada.Text_IO.field := 0;
— aft: Ada.Text_IO.Field := 0;
— exp: Ada.Text_IO.Field := 0
— );

procedure MyPut(X: Float) is –Create single parameter function required in generic GIOEX.
begin
MyFloatIO.Put(X, 0, 0, 0);
end;

package MyGIOEX is new GIOEX(Float, MyPut, “*”); –Uses default for “*” floating point math.
use MyGIOEX;

Rect1: Rectangle := (5.0, 6.0);

Len: Float;

dataArray: array(1..5) of Rectangle;

begin
Len := Size(Rect1);
Len := RectLength(Rect1);

dataArray(1) := (2.0, 3.03);
dataArray(2) := (4.0, 5.0);

Len := 7.04;
dataArray(3) := ( 2.0, Len);
Len := size( dataArray(1) );
Len := size( dataArray(2) );
Len := size( dataArray(1)) * size( dataArray(2) );
put(“size(dataArray(1)) * size( dataArray(2) ) = “); put(Len); — 2 kinds of “*” involved here.

end UGIOEXarray;

Hint 10: Allocate space in stack at runtime.
with Ada.Text_IO; use Ada.Text_IO;
procedure box1 is

package IIO is new Ada.Text_IO.Integer_IO(integer);
use IIO;

type vector is array(integer range <>) of integer;
i: integer; — scope of “i” is life of program!
begin
loop
put(“Enter array size “);
get(i);

declare — scope of “a” is life of block!
a:vector(1..i); — dynamically allocate storage in stack
begin
for k in a’range loop — for k in a’first .. a’last loop
put(“enter the next integer “);
get(a(k)); new_line;
end loop;
for k in a’range loop
put(a(k)); new_line;
end loop;
end;

put(“back in main pgm with storage deallocated”); new_line;
end loop;
end;

** Storage allocation and reclamation in the heap is the programmer’s responsibility. Storage allocation in the stack and especially storage reclamation is done very efficiently by the runtime system!

Hint 11: Random function distributions.

–in file randint.ads
package randint is — Generates a uniformly distributed random integer
function next_int return integer; — between 0 and 100.
end randint;

–in file randint.adb
Package body randint is
x: integer := 737; — seed, prime numbers best. Changing the seed changes the
function next_int return integer is — sequence of random numbers.
n : integer; — Large odd numbers tend to produce the best results.
begin
x := x*29+37;
n := x;
x := x mod 1001; — prevent overflow
return n mod 101; — number between 0 and 100
end next_int;
end randint;

–in file randflo.ads
package randflo is –Generates a uniformly distributed random real
function next_float return float; — between 0.0 <= next <= 1.0. end randflo; --in file randflo.adb Package body randflo is x: integer := 737; function next_float return float is n : integer; begin x := x*29+37; n := x; x := x mod 1001; return float(n mod 101) / 100.0; end next_float; end randflo; --in file expdist.ads package expdist is --Approximate the exponential distribution. function next_exp return float; end expdist; --in file expdist.adb with randflo; use randflo; package body expdist is function next_exp return float is x: float; begin x:= next_float; -- Return next exponential arrival interval. if x = 0.0 then -- Mean arrival time = 1. Uses “interpolation” to approximate. return 0.0; elsif x <= 0.1 then return ((x - 0.0) * 1.04 + 0.0); elsif x <= 0.2 then return ((x - 0.1) * 1.18 + 0.104); elsif x <= 0.3 then return ((x - 0.2) * 1.33 + 0.222); elsif x <= 0.4 then return ((x - 0.3) * 1.54 + 0.355); elsif x <= 0.5 then return ((x - 0.4) * 1.81 + 0.509); elsif x <= 0.6 then return ((x - 0.5) * 2.25 + 0.690); elsif x <= 0.7 then return ((x - 0.6) * 2.85 + 0.915); elsif x <= 0.75 then return ((x - 0.70) * 3.60 + 1.2); elsif x <= 0.8 then return ((x - 0.75) * 4.40 + 1.38); elsif x <= 0.84 then return ((x - 0.8) * 5.75 + 1.60); elsif x <= 0.88 then return ((x - 0.84) * 7.25 + 1.83); elsif x <= 0.9 then return ((x - 0.88) * 9.00 + 2.12); elsif x <= 0.92 then return ((x - 0.90) * 11.0 + 2.30); elsif x <= 0.94 then return ((x - 0.92) * 14.5 + 2.52); elsif x<= 0.95 then return ((x - 0.94) * 18.0 + 2.81); elsif x <= 0.96 then return ((x - 0.95) * 21.0 + 2.99); elsif x <= 0.97 then return ((x - 0.96) * 30.0 + 3.20); elsif x <= 0.98 then return ((x - 0.97) * 40.0 + 3.50); elsif x <= 0.99 then return ((x - 0.98) * 70.0 + 3.90); elsif x <= 0.995 then return ((x - 0.99) * 140.0 + 4.60); elsif x <= 0.998 then return ((x - 0.995) * 300.0 + 5.30); elsif x <= 0.999 then return ((x - 0.998) * 800.0 + 6.20); else return ((x - 0.9997) * 1000.0 + 8.0); end if; end next_exp; end expdist; --in file randuse.adb with expdist; use expdist; with randflo, randint; use randflo, randint; with Ada.Text_io; use Ada.Text_io; with Ada.Integer_Text_IO, Ada.Float_Text_IO; use Ada.Integer_Text_IO, Ada.Float_Text_IO; procedure RandUse is a,b,c: integer; x,y,z: float; begin for i in 1..20 loop for j in 1..10 loop a := next_int; a := (a mod 10)+1; --Random variant from 1 to 10. put(a); put(""); end loop; new_line; end loop; loop for i in 1..20 loop x := next_exp; put("x = "); put(x,6,3,0); new_line; x := x * 10.0; --Random variant exponentially distributed with a mean of 10 time units. put("exp with mean of 10 "); put(x,6,3,0); new_line; end loop; end loop; end RandUse;   To approximate a continuous distribution use extrapolation: a) generate a uniformly distributed random variant 0.0 <= ri<=1.0 b) the value of the function, yi, at point ri is yi = (ri - xi) * si + xi for i such that xi <= ri< xi+1. [i.e., yi = distance past base point * slope + base point] To approximate a discrete function: a) generate a uniformly distributed random variant 0.0 <= ri<=1.0 b) select yi from the graph region where xi<= ri< xi+1. Assume we wish to simulate arrivals at a grocery store exponentially distributed with a mean of 20 starting at time 0. Each time we wish to schedule a customer, get their inter-arrival time and add it to the current clock time. Keep the events in order by time. Customer Next_Exp Next_Exp * 20 Arrival Time (minutes) 1 0.104 2.08 2.08 2 0.470 9.40 11.48 3 0.087 1.74 13.22 4 4.600 92.0 105.22 5 0.137 2.74 107.96 6 0.000 0.0 107.96   **********************Star Wars********************* --in file randfloat.ads package randfloat is --Generates a uniformly distributed random real function next_float return float; -- between 0.0 <= next <= 1.0. end randfloat; --in file randfloat.adb Package body RandFloat is x: integer := 737; -- seed function next_float return float is n : integer; begin x := x*29+37; n := x; x := x mod 1001; return float(n mod 101) / 100.0; end next_float; end RandFloat; --in file ArrivalForRepair.adb -- using a “step function” so 25% of the time there are 0, 1, 2, or 3 arrivals respectively. with RandFloat; use RandFloat; with Ada.Text_IO; use Ada.Text_IO; procedure ArrivalForRepair is package FloatIO is new Ada.Text_IO.Float_IO(float); use FloatIO; package IntIO is new Ada.Text_IO.Integer_IO(Integer); use IntIO; numberArrivals: integer; randNum: float; begin for j in 1..5 loop randNum := next_float; if randNum <= 0.25 then numberArrivals := 0; elsif randNum <= 0.5 then numberArrivals := 1; elsif randNum <= 0.75 then numberArrivals := 2; else numberArrivals := 3; end if; put("The number of arrivals is "); put(numberArrivals); new_line; --SIMULATE REPAIRS 3.5 seconds. delay 3.5; end loop; end ArrivalForRepair; The number of arrivals is 3 The number of arrivals is 0 The number of arrivals is 2 The number of arrivals is 3 The number of arrivals is 1 The number of arrivals is 3 The number of arrivals is 0 The number of arrivals is 2 The number of arrivals is 3 The number of arrivals is 1 You will get the same pseudo random sequence every time you use the same seed. One solution is to add a function or procedure to seed the random number generator prior to the first call. Another is to use the system clock (not cryptographically sound). Hint 12: Sleeping to simulate the passing of time/effort. -- See package Ada.Calendar and package Ada.Real_Time for convenient functions -- to manipulate time. withAda.Text_IO; with Ada.Calendar; procedure Time2 is use Ada.Calendar; -- for the "-" and "+" operations on Time Start_Time : Ada.Calendar.Time; Next_Cycle : Ada.Calendar.Time; Period : constant Duration := 5.5; Seconds: constant Duration := 1.0; Minutes: constant Duration := 60.0; Hours: constant Duration := 3600.0; begin -- delay 2 * Hours + 40* Minutes; -- delay of 2 hours and 40 minutes Start_Time := Ada.Calendar.Clock; Next_Cycle := Start_Time; for J in 1..4 loop Ada.Text_IO.Put_Line(Duration'Image(Ada.Calendar.Clock - Start_Time)); --' -- You could use Next_Cycle instead of Ada.Calendar.Clock - Start_Time -- so the printing does not depend of the time needed to do the elapsed -- time calculation delay 3.0 * Seconds; -- This pattern assumes each cycle last less than Period. -- If you cannot ensure that, you should consider improving -- the pattern or reduce the computation load of each cycle. -- Some OS allow a maximum delay of 24 hours. Use a loop -- For longer delays. Next_Cycle := Next_Cycle + Period; delay until Next_Cycle; end loop; Ada.Text_IO.put("Total time = "); Ada.Text_IO.Put_Line(Duration'Image(Ada.Calendar.Clock - Start_Time)); Ada.Text_IO.Put_Line("End of program"); end Time2; Time expressed in seconds. *************************Sample main program ******************* -- In Step 1 we either accept 1, 2, 3, or 4 new vehicles into the repair facility. Only 1 vehicle may be repaired on each iteration through the repair facility. --in file ArrivalForRepair.adb with RandFloat; use RandFloat; with Ada.Text_IO; use Ada.Text_IO; procedure ArrivalForRepair is package FloatIO is new Ada.Text_IO.Float_IO(float); use FloatIO; package IntIO is new Ada.Text_IO.Integer_IO(Integer); use IntIO; -- Determine the number of new arrivals for Step 1 in the lab. -- Either 1, 2, 3 or 4 uniformly distributed on each call. function NumberNewArrivals return Integer is randNum: float; begin randNum := next_float; -- 0.0 <= randNumm <= 1.0. if randNum <= 0.25 then return 1; elsif randNum <= 0.5 then return 2; elsif randNum <= 0.75 then return 3; else return 4; end if; end NumberNewArrivals; numberArrivals: Integer; begin -- Lab Step 0. -- Seed the random number generator appropriately. null; -- do the operations Loop -- Lab Step 1. -- First, determine number of arrivals. -- Since they are waiting, give them the same arrival (ET/clock) time. numberArrivals := NumberNewArrivals; put("The number of new arrivals is "); put(numberArrivals); new_line; for j in 1..numberArrivalsloop --Determine if the arrival is a Tie Fighter or a Star Destroyer. --Prepare the maintenance record and place it in the appropriate queue. put("Step 1: prepare maintenance record and place in stack"); new_line; end loop; new_line(2); --Lab Step 2. null; -- do the operations. --Lab Step 3. null; -- do the operations. --Lab Step 4. null; -- do the operations, prepare for the vext repair operations. delay 2.0; endloop; -- Lab Step 5 --Five vehicles rejected. --Calculate and print results end ArrivalForRepair;