Question: // MAINTENANCE11 // This program accepts product data about 100 products. // It displays data about the most expensive product // and the average price

// MAINTENANCE11 // This program accepts product data about 100 products.

// It displays data about the most expensive product

// and the average price of all products.

// Modify the program to use a Product class to

// hold product data. Include a constructor

// that accepts all the data fields as parameters.

class Product

Declarations

private string idNum

private string description

private num price

private num double price

public Product(string id, string descrip, num pr)

id = idNum

description = descrip

price = pr

return

public void setIdNum(string id)

idNum = idNum

return

public void setDescription(string desc)

description = desc

return

public void setPrice(num pr)

if pr < 0

price = 0

else

price = pr

endif

return

public string getIdNum()

return idNum

public getDescription()

return description

public num getPrice()

return price

endClass

start

Declarations

num SIZE = 100

Product = products[SIZE]

num x = 0

num total = 0

num avg

num highestPrice = 0

string highestId

string higestDescrip

while x < SIZE

products[SIZE] = getData()

total = total + products[x].getPrice()

if products[x].getPrice() > highestPrice

highestPrice = products[x].getPrice()

highestDesc = products[x].getHighest()

highestId = products[x].getIdNum()

endif

x = x + 1

endwhile

avg = total / SIZE

output "The highest priced product is ,highestId,

highestDescrip, " $", highestPrice

output "The average price of all products is $", avg

stop

Product getData()

string id

string descrip

num price

output "Enter id or "

input id

output "Enter description "

input descrip

output "Enter price "

input price

Product p(id, descrip, price)

return p

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!