An Example
...function safe_division (a, b : Integer) return Integer is
......q : Integer;
...begin
......q := a / b;
...exception
......when CONTSRAINT_ERROR => return Integer'Last;
...end safe_division;
Another Example
...procedure P is
...begin
......P;
...exception
......when STORAGE_ERROR => P;
...end P;
Problem
Define a type Day than models the days of the week then write a
function Tomorrow that returns the following day of a certain day. You
function should not contain any control statement.The funtion tomorrow
should be declared in another file called Tomorrow.adb and it should
use exception handlers to catch exceptions.The main program in file
Main.adb should call the function tomorrow that returns the next day.
Output
Enter the day of the week:- <------First prompt Sunday <------Entered by the user The next day of the week is Monday <------Output
Helpful Stuff:
1.Use
Enumeration types for the days of the week.
2.Example of seperate compilation
Main.adb
Main-put.adb
Main-next_month.adb
3.Example of exception handling
Things to be turned in :
1. Source code
2. The output of the program
Problem
Write an Ada program that plays the game "rock,paper,scissors". In this game, two players choose simlutaneously either rock, paper, or scissors. Whether a player wins or loses depends not only on that player's choice but also on the opponent's. The rules are:
rock breaks scissors :rock wins
paper covers rock :paper wins
scissor cuts paper :scissor win
All matching combinations are ties.
Each player uses the editor to prepare a text file containing his or
her choices for a number of games. Choices are rock, paper, and
scissors. (In your program, use an enumneration type for these
choices.) Each choice for a game is on seperate line. It may have
blanks before and after it.
Your program should read the choices from the two files and determine
the winner of each game. After all games have been played, display the
total number of games played, the number of games won by each player,
and the number of tie games.
Because the players have not agreed in advance on the number of games
to play, your program should terminate when all of the choices in one
file have been played. If a particular choice for a game is not spelled
correctly, that player forfeits the game. If both players have invalid
choices, it is considered a tie game.
Let the two players' files be Player1.txt and second players file be Player2.txt
Player1.txt scissor paper rockl scissor rock Player2.txt rock paper rock
The total number of games played is 3
Player 1 wins 0 games
Player 2 wins 3 games
The number of tie games is 0
Example
of Enumeration types
Example
of File I/O
Professor:Dr.Stansifer
G.S.A : Rishi Gupta
Last Modified :3/28/99