-name: std::string - sales_price_: long - cost price: long - items_in_stock_: int Product + Product(name_ref: std::string&, cost_price: long, sales_price: long) + set_name(name_ref: std::string&): void + set_sales_price(sales_price: long): void + set_cost_price (cost_price: long) : void + set_items_in_stock(items int) : void + name(): std::string + sales_price(): long +cost_price(): long + items_in_stock(): int + sell(number_items_to_sell : int): long + purchase(number_items_to_buy : int): long

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 10PE
icon
Related questions
Question

Based on the class Product defined above, the member function sell() is now to be implemented. If number_items_to_sell is negative, then this variable is to be set to zero inside the function for further processing. When selling, two things can happen. First, you can have more items in stock than items to be sold. In this (good) case, the function is to reduce the number of items in stock by the number of items to be sold. Second, you have fewer items in stock than items to be sold. In this case, all items in stock are to be sold, and the number of items in stock is to be set to zero. In both cases, the function returns the money made during the sale (in Cents). This function definition is to be put into the file task5.cpp. 

-name: std::string
- sales_price_: long
- cost price: long
- items_in_stock_: int
Product
+ Product(name_ref: std::string&, cost_price: long, sales_price: long)
+ set_name(name_ref: std::string&): void
+ set_sales_price(sales_price: long): void
+ set_cost_price (cost_price: long) : void
+
set_items_in_stock(items int) : void
+ name(): std::string
+ sales_price(): long
+cost_price(): long
+ items_in_stock(): int
+ sell(number_items_to_sell : int): long
+ purchase(number_items_to_buy : int): long
Transcribed Image Text:-name: std::string - sales_price_: long - cost price: long - items_in_stock_: int Product + Product(name_ref: std::string&, cost_price: long, sales_price: long) + set_name(name_ref: std::string&): void + set_sales_price(sales_price: long): void + set_cost_price (cost_price: long) : void + set_items_in_stock(items int) : void + name(): std::string + sales_price(): long +cost_price(): long + items_in_stock(): int + sell(number_items_to_sell : int): long + purchase(number_items_to_buy : int): long
AI-Generated Solution
AI-generated content may present inaccurate or offensive content that does not represent bartleby’s views.
steps

Unlock instant AI solutions

Tap the button
to generate a solution

Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage