comp.lang.ada
 help / color / mirror / Atom feed
* Ada stacks and the time system
@ 2019-09-16  6:39 sandeep parajuli
  2019-09-16  8:14 ` Niklas Holsti
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: sandeep parajuli @ 2019-09-16  6:39 UTC (permalink / raw)


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.

How can we do this is Ada


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Ada stacks and the time system
  2019-09-16  6:39 Ada stacks and the time system sandeep parajuli
@ 2019-09-16  8:14 ` Niklas Holsti
  2019-09-16 16:02 ` Dennis Lee Bieber
  2019-09-18 19:09 ` Ludovic Brenta
  2 siblings, 0 replies; 4+ messages in thread
From: Niklas Holsti @ 2019-09-16  8:14 UTC (permalink / raw)


Is this a homework problem? Sounds like the kind of lame humour some of 
them use.

On 19-09-16 09:39 , sandeep parajuli wrote:
> 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

How many service bays can there be? An unlimited number? How are they 
identified, in case the program should keep track of several bays at the 
same time?

> 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’.

Oops, a built-in "26-ship-wrap-around-problem" right there...

>  Lord Vader directed us to write a
> program for the facility providing support for two stacks or parish

What does a church parish have to do with it? Oh, I guess you meant 
"perish".

What are the "stacks" for? To store the service records? Why should they 
be "stacks" (last-in-first-out)? It seems much more likely that ships 
follow a queue order (first-in-first-out). Why are there two stacks? Is 
one for the Ties and the other for the Stars?

> 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.

What is the "C" Option? To use the C language instead of Ada?

What are these "locations" that you speak of? Elements in an array, perhaps?

Where does the number 20 come from? Is this the largest number of 
vehicles (Ties or Stars) that can be under repair at the same time in 
any one service bay? Ah, I see that it is explained a little later in 
your posting.

> 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.

What "following memory model"?

> How can we do this is Ada

I am tempted to answer: by studying the Ada language and then writing 
the program. Have you even thought about it? Do you know how to 
implement any part of it in Ada, for example prompting for and receiving 
the lower and upper bounds? Which part do you not know how to solve? Can 
you solve it in the C language? If so, can you map your C solution to an 
Ada solution?

As it seems to be a homework problem, I will of course not give you a 
complete solution. But I will give you one hint: to store two stacks in 
the "same" space, such as an array of a given size, a method already 
known to the ancients of computing is to make one stack start at the 
low-index end of the array and grow towards higher indices, while the 
other stack starts at the high-index end of the array and grows towards 
lower indices. Of course this means that the sum of the sizes of the two 
stacks cannot exceed the length of the array, but that seems to be 
exactly how "lord Vader" has set up the problem.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Ada stacks and the time system
  2019-09-16  6:39 Ada stacks and the time system sandeep parajuli
  2019-09-16  8:14 ` Niklas Holsti
@ 2019-09-16 16:02 ` Dennis Lee Bieber
  2019-09-18 19:09 ` Ludovic Brenta
  2 siblings, 0 replies; 4+ messages in thread
From: Dennis Lee Bieber @ 2019-09-16 16:02 UTC (permalink / raw)


On Sun, 15 Sep 2019 23:39:53 -0700 (PDT), sandeep parajuli
<parajulisandeep.sp205168@gmail.com> declaimed the following:

>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.
>
>How can we do this is Ada


	This reads like a homework assignment -- and one should not expect to
receive answers to homework itself.

	Show us what you've done, pointing out where you are stuck, and we'll
often provide hints for that specific point.

	Are these names permanently assigned to each ship, or are they assigned
when the ship arrives and "forgotten" once the repair is completed and the
ship leaves the facility (meaning the same ship could come in a second
time, and get a different "name").

	Are the "records" different for fighters vs destroyers? That is: do you
have a base "ship" type which is extended for "TIE fighter" and "star
destroyer", with the service bays and "stack" having to handle either class
at any moment?

	There is no explanation of what you mean by "'C' option" -- program
written in the C language? Given the rest of the description, it could be
specifications for how the instructor will test the operation of your
program (ie: will feed it a test set expecting only 20 service bays --
while the program must be flexible enough to be run with a different number
of service bays based upon initialization value from the user; note that
Ada would actually permit you to run with lower bound -9, upper bound +10,
and still have 20 service bays).

	Are ships serviced in order of arrival (which would imply a queue, not
a stack). If in stack order, with two "stacks" I first thought a deque
structure -- fighters coming in at one end, and destroyers at the other
end, but that doesn't really work. Using a structure in which each type
builds in from the ends, and the facility is full when the two types meet
in the middle might work.

	The assignment sounds like an exercise in data structures and
algorithms -- so you should study how stacks and deques are handled; then
figure out how to modify such a structure to work for the two classes of
ships.

	A priority (ship class) ordered double-ended linked-list with a pool of
free-nodes would be my next candidate. That would allow processing each
class in queue order (by traversing the linked list to find the oldest
entry of the ship type and removing it) while not having to shift data.
(The free pool actually would represent the unused service bays).


	BTW: Your subject line references "time system", but nothing in your
post mentions how time is involved in this exercise. Does each received
ship get assigned a "repair time" (maybe a random generated value), which
controls how long it stays in a repair bay?


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Ada stacks and the time system
  2019-09-16  6:39 Ada stacks and the time system sandeep parajuli
  2019-09-16  8:14 ` Niklas Holsti
  2019-09-16 16:02 ` Dennis Lee Bieber
@ 2019-09-18 19:09 ` Ludovic Brenta
  2 siblings, 0 replies; 4+ messages in thread
From: Ludovic Brenta @ 2019-09-18 19:09 UTC (permalink / raw)


sandeep parajuli <parajulisandeep.sp205168@gmail.com> writes:
> Emperor Constantine has commanded Darth Vader to build and operate a

Presumably you mean Palpatine.

I'm simply happy to see that Ada is being taught at school.

Oh and by the "time system", maybe you mean that I should spend my time
so you can save yours? Is that correct?

-- 
Ludovic Brenta.
The attackers remove barriers. 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-09-18 19:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-16  6:39 Ada stacks and the time system sandeep parajuli
2019-09-16  8:14 ` Niklas Holsti
2019-09-16 16:02 ` Dennis Lee Bieber
2019-09-18 19:09 ` Ludovic Brenta

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox