Anyone good with ADA 95?

Soldato
Joined
5 Feb 2006
Posts
3,386
Location
15,000ft.
Hey, in my first year at uni and I have this exercise which I don't have a clue about.
Basically I have a programme that reads characters typed in by the user and once the squence is terminated by a '.', the programme returns the number of times each character appeared in the sequence.

It uses linked lists to achieve this, adding a character to a list and each time that character is rea, a counter in the record of that character is incremeted by 1.

Pretty simple stuff, it works and everything, even tho the coding is crap.


Code:
with Ada.Text_IO, Ada.Integer_Text_IO;

procedure countletters is

type wordlist;
type wordlist_Ptr is access wordlist;

type wordlist is
   record
     letter: character;
     value: integer;
     Next: wordlist_ptr;
    end record;


list : wordlist_Ptr := null;
letter : character;

procedure lettercount(c : in character; l: in out wordlist_Ptr) is

begin

if l = null then
l := new wordlist'(letter=>c, value=>1, Next=>null);

elsif l.all.letter = c then 

l.all.value := l.all.value+1;

else 

lettercount(c=>c, l=>l.all.Next);

end if;
end lettercount;





begin

ada.text_io.put("Please enter a string of characters followed by a '.': ");
ada.text_io.get(letter);

while letter /= '.' loop
  lettercount(letter, list);
  ada.text_io.get(letter);
end loop;

while list /=null loop
  ada.text_io.put(list.all.letter);
  ada.text_io.put(" ");
  ada.integer_text_io.put(list.all.value);
  list := list.all.Next; 
  ada.text_io.put_line(" ");
end loop;

end countletters;

Now here is my problem, the next exercise says to
Modularise your solution to the problem of subsubsection 4.1.1 by implementing an
ADT for the abstract notion of a bag of characters as a linked list.

Now an ADT I think I'm fine with....but what the hell is this 'bag of characters' about do you know?

Any help would me much appreciated. :)
 
I think that's a Jeremy term, not an Ada term, have you checked the lecture slides?

I'm going to check them today after finding nothing in the ADA book. Problem is, Jeremy doesn't like having notes, he gives us some slides for complexity and a course synopsis and that's it. :(
 
A bag of characters is like a set of characters.

A Set is an ADT in which each element is unique so { 1, 1, 2, 3 } becomes { 1, 2, 3 }

A in a bag, duplicate elements are allowed, i.e. { 1, 1, 2, 3} is a bag.

So you could implement a bag as a normal array, or a list or any other ADT that basically allows dupes. (according to your lab sheet there he wants a bag backed by a link-list I think?)

Is that what you were asking? I skipped over all your ADA code :P.

http://en.wikipedia.org/wiki/Multiset
 
Last edited:
Right...so this bag....is going to be a linked list of objects or data. Then all I need to do is count how many times a object is listed and return a count?

I'll see how it goes, weeks after I should have already done this. I'm so going to fail my assessment :p.
 
Back
Top Bottom