5.3k views
4 votes
// This program accepts data about 100 books and// determines a price for each.// The price is 10 cents per page for the// first 200 pages, then 8 cents// per page after that.// After pricing, all the data is displayed.// Create a Book class and modify the program to use// an array of Book objects instead of individual// data items.startDeclarationsnum SIZE = 100num substring titles[SIZE]num pages[SIZE]num prices[SIZE]num MIN_PAGES = 200num HIGH_PRICE = 0.10num LOW_PRICE = 0.08sub = 0while sub < SIZEoutput "Enter title "input title[sub]output "Enter pages "input pages[sub]if pages[sub] <= MIN_PAGES thenprice[sub] = pages[sub] * HIGH_PRICEelseprice[sub] = MIN_PAGES * HIGH_PRICE +(pages[sub] MIN_PAGES) * LOW_PRICEendifendwhiledisplayBooks(titles, pages, prices, SIZE)stopvoid displayBooks(string[] titles, num[] pages, num[] prices, num SIZE)Declarationsint xx = 0while x < SIZEoutput "Title: ", titles[x]output "Pages: ", pages[x]output "Price: ", prices[x]x = x + 1endwhilereturn

User Jruzafa
by
4.0k points

1 Answer

5 votes

Answer:

Check the explanation

Step-by-step explanation:

Begin class Books:

string title

num pages

num price

num MIN_PAGES=200

num HIGH_PRICE=0.10

num LOW_PRICE=0.8 Books(title, page)

title= title

pages=page

price=0.0

end of constructor

string getTitle()

return title

end of getTitle

num getPages()

return pages

end of getPages

num getPrice()

if(pages<=MIN_PAGES)

price=getPages()*HIGH_PRICE

else

price=MIN_PAGES*HIGH_PRICE+(pages-MIN_PAGES)*LOW_PRICE

end of if

return price

end of getPrice

string toString()

string s=""

s+="Title: "+getTitle()

s+="\\Pages: "+getPages()

s+="\\Price: "+getPrice()

return s

end of toString

end Books class

start

class BooksImplementation

main()

Declarations

Books books[100]

num size

string title

num pages

output "Enter the size of the Books array: "

input size

for i=0; i<size; i++

output "Enter Book title: "

input title

output "Enter number of pages in the book: "

input pages

books[i]=new Books(title, pages)

end of for

output "The details of book and it prices are: ")

for int i=0; i<size ; i++

output "Book "+(i+1)+": "

output books[i].toString()

end of for

end of main

end of class

stop

User Sirupsen
by
3.0k points