Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Write a class Commodity that contains the following attributes and methods:
-A public data member Name of type string that represents the Commodity name.
-A private data member Quantity that represents the quantity of the Commodity.
-A public data member Price that represents the price of 1 unit of the commodity.
-Constructor (__init__) to initialize data members to any given values.
-__str__ method to return a string represent object of type commodity.
-setQuantity method to initialize Quantity data member to any given value greater than 0.
-CalculatePrice method that calculates and returns the price of the Commodity based of the following Formula:
TotalPrice = price * Quantity
-Overload -= operator to subtract specific value from the price of the Commodity object.
-Overload < operator to test if the first object has less Quantity than the second object of type Commodity.
-Overload + operator to add one object of type Commodity to another object.

What I have tried:

I want help writing the code
Posted
Comments
0x01AA 9-Nov-23 11:55am    
Do you have question or only an order to code for you?
Trying to do by yourself is widely known as learning.

You need to show the code you have written, and explain exactly what help you need. But if you are expecting someone here to write the complete assignment for you, I am afraid you will be disappointed. This site is here to provide help, not to do other people's work for them.
 
Share this answer
 
We are here more than happy to help you, but you should try yourself to work on this assignment. Try yourself and come with the issue if you face any. Here is the link to understand the basic concepts of OOP with guide.
Introduction to Object Oriented Programming Concepts (OOP) and More[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900