Subprograms are the conventional parameterized unit of programming. In Ada, subprograms fall into two categories: Functions and Procedures. This lab covers the subject of Functions in Ada. Functions are called as components of expressions and returns a value as part of the expression, whereas procedures are called as statements standing alone.
Functions, and in general subprograms, are composed of a specification part and a body part . A Function generally takes arguments (parameters). Functions without arguments often return a constant value. This may be useful for inheritance purposes.
You do not have to use functions in this problem.
Problem 1: You are putting together some music tapes for a party. You've arranged a list of songs in the order in which you want to play them.However,you would like to minimize the empty tape left at the end of each side of a cassette.(a cassette plays for 45 minutes on a side)So you want to figure out the total time for a group of songs and see how well they fit.
Task : To write an Ada program to help solve this problem. The program should take as input the reference number and the time for each song until it encounetrs a reference number of 0. Each time should be entered in the form of minutes and seocnds(two integer values).
Use Functions in this problem.
Problem 2 : Write an Ada program to calculate the two roots of a Quadratic equation of the form
ax2+ bx + c=0
using the quadratic formula
Root1 = (-b + (b2 -4ac)1/2)/2a
Root2 = (-b - (b2-4ac)1/2)/2a
Task : To write an Ada program that should prompt for the
values a,b and c (all float values). If the quantity b2-4ac
is negative, display a message indicating that the roots are
imaginary.Otherwise calculate and display (with appropriate labels) the
two roots. The Quadratic formula to calculate should be a function
which takes as parameters a,b and c.
This program should have three functions for the following :-
1.To calculate b2-4ac.
2.To calculate Root1.
3.To calculate Root2.
Example :The program should prompt the user with the following messages
Enter the value of a : <-----Input prompt
2
Enter the value of b :
2
Enter the value of c :
4
The roots are imaginary<-----Output of the program
Another example
Enter the value of a :
2
Enter the value of b :
8
Enter the value of c :
3
Root1 = <-----------Output of the program
Root2 =
The program should terminate by asking the user whether he wants to continue or not.
Helpful Stuff : Example of Use of a Function
Problem 3 : Write an Ada program to calculate the wind chill as done in the previous LAB6 using functions.
Task: Modify the program such that the formula to calculate the wind chill is a function which is called in the main procedure.
The program should terminate by asking the user whether he wants to
continue or not.
Professor:Dr.Stansifer
G.S.A : Rishi Gupta
Last Modified :2/20/99