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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started