First ADA program is required to display a message "Hello!! This is your computer speaking".
put (Hello!! This is your computer speaking)
-- Skansholm #2.4.2 pp26-28 -- a simple ada output program with TEXT_IO; -- declare the package use TEXT_IO; procedure hello is begin -- hello PUT_LINE ( "Hello!! This is your computer speaking."); end hello;
Calculate the sum and product of two numbers.
1. get the two numbers 1.1 ask for the two numbers 1.2 get number1 1.3 get number2 2. calculate and print the sum 2.1 print "The sum is " 2.2 print (number1 + number2) 3. calculate and print the product 2.1 print "The product is " 2.2 print (number1 * number2)
number1: number number2: number put (Give me two whole numbers) get (number1) get (number2) put (The sum of the numbers is ) put (number1 + number2) put (The product of the numbers is ) put (number1 * number2)
------------------------------------------------------- -- sum_prod - sum and product, Skansholm #2.4.2 ------------------------------------------------------- with TEXT_IO; -- specify packages we depend on use TEXT_IO; procedure sum_prod is -- declare integer I/O package package int_io is new TEXT_IO.INTEGER_IO( INTEGER ); use int_io; -- declare any constants and variables required number1, number2 : integer; -- numbers used begin -- sum_prod -- ask user for numbers and read them PUT_LINE("Give me two whole numbers!"); GET(number1); GET(number2); -- display sum and product of numbers PUT("The sum of the numbers is:"); PUT(number1+number2); NEW_LINE; PUT("The product of the numbers is:"); PUT(number1*number2); NEW_LINE; end sum_prod;
Give me two whole numbers! 4 12 The sum of the numbers is: 16 The product of the numbers is: 48
more than one way to solve a given problem specification
with TEXT_IO; use TEXT_IO; procedure sum_prod is -- declare integer I/O package package int_io is new TEXT_IO.INTEGER_IO( INTEGER ); use int_io; -- declare any constants and variables required number1, number2, total, product : integer; begin -- sum_prod -- ask user for numbers and read them PUT ( "Please enter the first number "); GET ( number1 ); skip_line; PUT ( "Please enter the second number "); GET ( number2 ); skip_line; -- display sum and product of numbers total := number1 + number2; product := number1 * number2; PUT("The sum of the numbers is:"); PUT(total, width=>7); NEW_LINE; PUT("The product of the numbers is:"); PUT(product, width=>3); NEW_LINE; end sum_prod;
meet specification
natural
understandable
efficient
"elegant"