submit itec320-02 homework_two.adb
Last modified:
Updates:
This homework is similar to the first homework. It should be fairly easy, and won't be worth as many points as the other programming projects. It will help you learn about procedures and parameter modes.
Given the input file shown, your program should produce the output shown.
Sample input file h2.txt:
Joe Jones 30 3.5 Jack Spratt 40 1.500Sample output:
rucs@/home/nokie> ./homework_two < h2.txt Name: Joe Jones Hours: 30 GPA: 3.500 Grade Points: 105.00 Points above: 45.00 Name: Jack SprattMy name: Jack SprattHours: 40 GPA: 1.500 Grade Points: 60.00 Points below: 20.00
Specifications - Rewrite the program shown below following these specifications:
in
or out
. in out
parameters. Unbounded_String
operates essentially like a Java String. -- 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_two;
Submission:
Use the submit command to turn your
program in for grading.
You do not need to submit any data files.
You may submit
as many times as you like, but only the last submission
is kept because submit wipes out any earlier submissions of the same name.
Since only the last submission is kept,
if the last one is late, then your assignment is late and will thus
receive a late penalty. Also remember that you must be on
rucs for submit to work.
To submit your work for grading do the following:
submit itec320-02 homework_two.adbNotice that you are to submit ONLY the .adb source file.
Late Penalty: Late programs not accepted (unless you have very extenuating circumstances).