with Ada.Text_IO; use Ada.Text_IO; with genStack; -- generic stack defined in genStack.ads /.adb with Unchecked_Conversion; procedure initStack is package intIO is new Ada.Text_IO.Integer_IO(integer); use intIO; --let the compiler write IO functions for me --functions to convert characters to integer and integers to characters function intToChar is new Unchecked_Conversion(Integer, Character); function charToInt is new Unchecked_Conversion(Character, Integer); selection: integer; --selection for main menu stackSize: integer; --stack size variable buffer: string(1..4); parameter:string(1..256); --package intStack is new genStack(max,integer); use intStack; --package to create integer stack begin Ada.Text_IO.put_line("+-----------------------------------------------------------------------------------------+"); Ada.Text_IO.put_line("| Stack Data Traversal Software v0.1Alpha"); Ada.Text_IO.put_line("| +----Author:: Adam Miller"); Ada.Text_IO.put_line("| |---Type 'quit' to end data traversal"); Ada.Text_IO.put_line("| |---Type the 'push' command to be prompted for input"); Ada.Text_IO.put_line("| |---Type the 'pop' command to receive output"); Ada.Text_IO.put_line("| +--Capable of traversing the following data types::"); Ada.Text_IO.put_line("| |---1) Character (Telescope Spec)"); Ada.Text_IO.put_line("| |---2) Integer ('B' Option Spec, 0 Sentential)"); Ada.Text_IO.put_line("| |---3) Date ('A' Option Spec)"); Ada.Text_IO.put_line("+-----------------------------------------------------------------------------------------+"); Ada.Text_IO.put_line("Please enter selection:: "); get(selection); --read in the selection of stack type put("Please enter stack size:: "); get(stackSize); --read in the size of stack if selection = 1 then --process selection declare --declare procedure to process character stack procedure processCharStack (max: in integer) is --variables used within this procedure type command is (push, pop, quit); input: command; type node is new String(1..256); element: node; count: integer; convert: character; cmd: string := buffer(buffer'first .. last); element: string:= parameter(parameter'first .. last); --declare a new stack of type character and of user defined size. package charStack is new genStack(max,character); use charStack; begin while cmd /= "quit" loop --denote that exit input by user will end the loop Ada.Text_IO.put_line(":"); --put a colon to prompt user for a command get_line(cmd, last); --get the input from the user count:=0; --count variable initialized to 0 if input = "push" then --user enters push command Ada.Text_IO.put_line(":enter string:: "); --prompt for the character string to be pushed get_line(element, last); --read in the stack element for x in 1..element'length loop --for the length of the string, loop push(element(x)); --push each character of the string onto the stack count:=count+1; --increment count by 1 on each push operation end loop; convert:=intToChar(count); --convert the count variable to a character type push(convert); --push the newly converted character onto the stack elsif input = "pop" then --user enters pop command convert:=pop; --pull off the count variable in order to convert it count:=charToInt(convert); --convert the character to an integer for i in 1..count loop --for the size of the count integer, loop put(pop); --pop each preceeding character from the stack end loop; end if; end loop; end processCharStack; begin processCharStack(stackSize); --call processCharStack procedure if 1 is selected. end; --else ------processIntStack end if; end initStack;