![]() |
![]() |
|
This homework takes the first homework, and refactors it to use functions/procedures appropriately. It should be fairly easy; it is worth considerably fewer points than the other programming projects. It will help you learn about procedures and parameter modes.
Joe Jones 30 3.5 Jack Spratt 40 1.500
Find the bug: There is an unintentional bug below, for you to find and fix. You'll notice it when you compare the output to the sample-input/outputs stated above (which are correct). (Even us profs, when we skip writing test-cases first, accidentally ship bugs in our code!)
-- Purpose: Calculate points surplus or deficit -- based on hours taken and GPA -- Input format: -- Line 1: Name -- Lines 2 and 3: hours attempted and desired GPA with Ada.Text_IO; use Ada.Text_IO; with Ada.Strings.Unbounded; use Ada.Strings.Unbounded; with Ada.Text_IO.Unbounded_IO; use Ada.Text_IO.Unbounded_IO; with Ada.Float_Text_IO; use Ada.Float_Text_IO; with Ada.Integer_Text_IO; use Ada.Integer_Text_IO; procedure homework_two is name: Unbounded_String; -- Student name hours_attempted: Natural; -- Hours taken gpa: Float; -- Current GPA earned_points: Float; -- Points attained -- Requirements Required_GPA: constant := 2.0; -- GPA required to graduate required_points: Float; -- Points needed to graduate -- Points calculations surplus, deficit: Float; -- Points above or below required begin -- Read values get_line(name); get(hours_attempted); get(gpa); -- Calculation earned_points := Float(hours_attempted) * gpa; required_points := Required_GPA * Float(hours_attempted); -- Calculate both even though one will not be needed surplus := earned_points - required_points; deficit := required_points - earned_points; -- Output put_line("Name: " & name); put_line("Hours:" & hours_attempted'img); put("GPA: "); put(item => gpa, fore => 1, aft => 3, exp => 0); new_line; put("Grade Points: "); put(earned_points, 1, 2, 0); new_line; -- Surplus or deficit if earned_points = Required_GPA then put_line("Exact: 0"); elsif earned_points >= Required_GPA then put("Points above: "); put(surplus, fore => 1, aft => 2, exp => 0); new_line; else put("Points below: "); put(deficit, fore => 1, aft => 2, exp => 0); new_line; end if; end homework_v2;
This page licensed CC-BY 4.0 Ian Barland Page last generated | Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |