Question

OVERVIEW: The purpose of this assignment is to reinforce Ada concepts. Specifically, the assignment is to...

OVERVIEW: The purpose of this assignment is to reinforce Ada concepts.

  • Specifically, the assignment is to construct a Book class where a book contains the following:
    • an author
    • a title
    • a number of pages
  • You also need a “main program” to create a book and then display its contents.
  • Have it allow the user to change the values.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

CODING :

books.adb

with Ada.Characters.Handling;
use Ada.Characters.Handling;

package body Books is

-----------------
-- create_book --
-----------------

function create_book
(author: in String;
title: in String;
leaves: in PAGES)
return Book
is
boo : Book;
begin
if author'Length > MAX_AUTHOR_NAME_SIZE then
boo.author := author(1 .. MAX_AUTHOR_NAME_SIZE);
else
boo.author (1 .. author'Length) := author;
end if;
if title'Length > MAX_TITLE_SIZE then
boo.title := title(1 .. MAX_TITLE_SIZE);
else
boo.title (1 .. title'Length) := title;
end if;

boo.leaves := leaves;
return boo;
end create_book;

----------------
-- get_author --
----------------

function get_author (s: in Book) return String is
begin
return s.author;
end get_author;

---------------
-- get_title --
---------------

function get_title (s: in Book) return String is
begin
return s.title;
end get_title;

---------------
-- get_pages --
---------------

function get_pages (s: in Book) return PAGES is
begin
return s.leaves;
end get_pages;

end Books;
books.ads

package Books is

type Book is private;

MAX_AUTHOR_NAME_SIZE: constant Positive := 30;

MAX_TITLE_SIZE: constant Positive := 100;

MAX_PAGES_SIZE: constant Positive := 10000;

type PAGES is new Positive range 1 .. MAX_PAGES_SIZE;

function create_book (author: in String; title: in String; leaves: in PAGES)
return Book
with pre => author'Length > 0 and title'Length > 0;

function get_author (s: in Book) return String;

function get_title (s: in Book) return String;

function get_pages (s: in Book) return PAGES;

private
type Book is
record
author: String (1 .. MAX_AUTHOR_NAME_SIZE) := (others => ' ');
title: String (1 .. MAX_TITLE_SIZE) := (others => ' ');
leaves: PAGES;
end record;

end Books;
test_book.adb

with Books, Ada.Text_IO;
use Books, Ada.Text_IO;

procedure Test_Book is

boo: Book;

procedure display_book (s: in Book) is

begin
put ("Author: ");
put_line (get_author (s));
put ("Title: ");
put_line (get_title (s));
put ("Pages: ");
put_line (Positive'Image (Positive(get_pages(s))));
end display_book;

begin
boo :=create_book("Hu","The life of me",150);
display_book(boo);
end Test_Book;

Hit the thumbs up if you are happy with the answer

Add a comment
Know the answer?
Add Answer to:
OVERVIEW: The purpose of this assignment is to reinforce Ada concepts. Specifically, the assignment is to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The purpose of this assignment is to reinforce dynamic programming algorithms. Specifically, the assignment is to...

    The purpose of this assignment is to reinforce dynamic programming algorithms. Specifically, the assignment is to do problem 15-8 on page 409 of the text. In addition, implement the algorithm that you construct. You may write your program in any modern language. I suggest Python because the output can be put in a visual representation Part 1 reinforces the recurrence relation of the Fibonacci sequence with a comparison to the dynamic programming algorithm. (goals 1, 3, 4) Using the same...

  • The goal of this lab is to reinforce binary tree concepts. Specifically, this lab is to...

    The goal of this lab is to reinforce binary tree concepts. Specifically, this lab is to do construct a function (and construct a test program using a non-trivial tree) which will display a binary tree by levels showing “vacant spots”. The display for the following tree should be: M H T E null P W A null null null null Q null null The function header should be: template <typename T> void display_complete_tree (const binary_tree_node<T>* t) The files "bintree.h" and...

  • Purpose of the assignment To apply simple JavaScript concepts to create a Fahrenheit to Celsius (and...

    Purpose of the assignment To apply simple JavaScript concepts to create a Fahrenheit to Celsius (and Celsius to Fahrenheit) conversion program. I need both please! What’s required of you. Having looked at some basic examples of JavaScript on http://www.w3schools.com and at the “simple math with forms/inputs and validation” example in detail , I would like you to now apply those concepts to create a simple page that lets users type in some temperature value in the Fahrenheit/Celsius scale and when...

  • Create a base class named Book. Data fields include title and author; functions include those that...

    Create a base class named Book. Data fields include title and author; functions include those that can set and display the fields. Derive two classes from the Book class: Fiction, which also contains a numeric grade reading level, and NonFiction, which contains a variable to hold the number of pages. The functions that set and display data field values for the subclasses should call the appropriate parent class functions to set and display the common fields, and include specific code...

  • M01 PA C++ Classes and Objects INTRODUCTION: Write a C++ program that implements and utilizes a...

    M01 PA C++ Classes and Objects INTRODUCTION: Write a C++ program that implements and utilizes a Stereo Receiver Class/Object. INCLUDE IN YOUR ASSIGNMENT At the top of each of your C++ programs, you should have at least four lines of documentation: Program name (the C++ file name(s)), Author (your name), Date last updated, and Purpose (a brief description of what the program accomplishes). Here is an example: // Program name: tictactoe.cpp // Author: Rainbow Dash // Date last updated: 5/26/2016...

  • Part 1 The purpose of this part of the assignment is to give you practice in...

    Part 1 The purpose of this part of the assignment is to give you practice in creating a class. You will develop a program that creates a class for a book. The main program will simply test this class. The class will have the following data members: A string for the name of the author A string for the book title A long integer for the ISBN The class will have the following member functions (details about each one are...

  • C++ program Correctly complete the following assignment. Follow all directions. The main purpose is to show...

    C++ program Correctly complete the following assignment. Follow all directions. The main purpose is to show super and sub class relationships with an array of super media pointers to sub class objects and dynamic binding. The < operator will be overloaded in the super class so all subclasses can use it. The selection sort method will be in the main .cpp file because it will sort the array created in main. The final .cpp file, the three .h header class...

  • IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand...

    IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand the Application The assignment is to first create a class calledTripleString.TripleStringwill consist of threeinstance attribute strings as its basic data. It will also contain a few instance methods to support that data. Once defined, we will use it to instantiate TripleString objects that can be used in our main program. TripleString will contain three member strings as its main data: string1, string2, and string3....

  • The purpose of this lab is to help reinforce container class concepts and linked list concepts...

    The purpose of this lab is to help reinforce container class concepts and linked list concepts in C++. Specifically, the lab to repeat the sequence lab from last week except to use a linked list. You need to use the author's files sequence3.h and sequence_exam3.cpp. Author - Michael Main, Book - Data Structures and other objects using c++, 4th edition // FILE: sequence3.h // CLASS PROVIDED: sequence (part of the namespace main_savitch_5) // This is the header file for the...

  • This assignment shpuld be code in java. Thanks Overview In this assignment you will write a...

    This assignment shpuld be code in java. Thanks Overview In this assignment you will write a program that will model a pet store. The program will have a Pet class to model individual pets and the Assignment5 class will contain the main and act as the pet store. Users will be able to view the pets, make them age a year at a time, add a new pet, and adopt any of the pets. Note: From this point on, your...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT