FloridaTech - College of Engineering
CSE1001 - LABORATORY

Author: Jamal Faik

Lab Assignment 7: Procedures (and Functions) in Ada.

This lab covers the subject of procedures (and functions) in Ada. It is composed of five small problems and one take_home (interesting) problem. For each problem, you should also provide a test procedure. Knowledge of the type STRING is necessary to answer the problems. Information will be given in class in necessary.

Problem 1: Reverse : Write a procedure reverse (S : in out STRING) that reverses the string S.

Example of execution:
******************************************
********* String reverse *****************
******************************************
Enter a string : tide
The reverse string of tide is : edit


Problem 2: Concatenation : Write a function cattac that takes as argument a string S then return the concatenation of S and its reverse string.
Function cattac (S : STRING) return STRING is...

Example of execution:
******************************************
********* Concatenation ******************
******************************************
Enter a string : palindrome
The concatenation of palindrome and its reverse gives : palindromeemordnilap


Problem 3 (Optional) : Palindrome : A palindrome is a string reading the same forward and backward.
Examples of palindromes are : ada radar madam cattac palindromeemordnilap.

You are to write a function that takes as argument a STRING S and returns TRUE if S is a palindrome as FALSE otherwise.
Function is_palindrome (S : STRING) return BOOLEAN is...
As a comment, explain why is_palidrome(cattac(S)) return always TRUE. (S in a given string).


Problem 4: Capital Letters : In some problems, it is necessary to normalize some text so that all the letters within it are capitalized. You are to write a procedure to_upper (S : in out STRING) that capitalizes all small letters in S. The procedure should have no effect on capital letters or non-letters characters.

Example of execution:
******************************************
********* Capitalizing *******************
******************************************
Enter a string : Do you know a one-to-one mapping between N and N x N? Think Cantor!
The capitilized STRING is : DO YOU KNOW A ONE-TO-ONE MAPPING BETWEEN N AND N X N? THINK CANTOR!

Note : Use of attributes POS and VAL is highly recommended.



Take-Home Problems

Problem 5: Ada Identifier : You are to write a function is_identifier that takes as argument a string ID and return TRUE is the string a valid Ada identifer and FALSE otherwise.
Function is_identifier (ID : STRING) return BOOLEAN is...

Example of execution:
******************************************
********* Ada Identifiers*****************
******************************************
Enter an Identifier : Ada95 --> valid Ada identfier
Enter an Identifier : Ada95_beta_version --> valid Ada identifer
Enter an Identifier : __valid_C_identifier --> non valid Ada identifier


Problem 6 : Polynomes_IO (Optional) Polynomes are very interesting in Mathematics. It is crucial for a lot of applications to have an efficient implementation of polynomes. In this problem, you are to write a procedure test_polynome that takes as argument a STRING P representing a polynome and prints valid_polynome is P is a valid polynome and non_valid_polynome otherwise.

A polynome is defined as follows:

POLYNOME ::= MONOME | MONOME ADD_OP POLYNOME
MONOME ::= NUMBER VARIABLE_X NUMBER | NUMBER
NUMBER ::= DIGIT | DIGIT NUMBER
DIGIT ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0
VARIABLE_X ::= X
ADD_OP ::= + | -

NOTE : An algorithm using an FSM will be given in class. Other algorithms are also welcome.