In Pseudocode //This program accepts data about 100 books and determines a price
ID: 652192 • Letter: I
Question
In Pseudocode
//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.
start
Declarations
num sub
string titles[SIZE]
num pages[SIZE]
num prices[SIZE]
num MIN_PAGES = 200
num HIGH_PRICE = 0.10
num LOW_PRICE = 0.08
sub = 0
while sub
output "Enter title...."
input title[sub]
output "Enter pages...."
input pages[sub]
if pages[sub]<= MIN_PAGES then
price[sub] = pages[sub] *HIGH_PRICE
else
price[sub] = MIN_PAGES * HIGH_PRICE +
(pages[sub] - MIN_PAGES) * LOW_PRICES
endif
endwhile
displayBooks(titles,pages,prices,SIZE)
stop
void displayBooks(string[] titles, num[] prices, num SIZE)
Declarations
int x
x = 0
while x
output "Titles:", titles[x]
output "Pages:", pages[x]
output "Price:", prices[x]
x = x + 1
endwhile
return
Explanation / Answer
Answer:
Begin class Books:
string title
num pages
num price
num MIN_PAGES=200
num HIGH_PRICE=0.10
num LOW_PRICE=0.8
Books(tit, page)
title=tit
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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.