From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Ada stacks and the time system Date: Mon, 16 Sep 2019 11:14:44 +0300 Organization: Tidorum Ltd Message-ID: References: <8c293e09-fc74-45a4-b109-cd4041a4a311@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: individual.net /rUKIICU4Fq0P7PCOBurBAIisnDNEo5D8OAKKMHME+4Ozi5EKT Cancel-Lock: sha1:0VbX5geZVCUGfnbwqVcySsy3pbM= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 In-Reply-To: <8c293e09-fc74-45a4-b109-cd4041a4a311@googlegroups.com> Xref: reader01.eternal-september.org comp.lang.ada:57157 Date: 2019-09-16T11:14:44+03:00 List-Id: 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 . @ .