Welcome to Code Forum!

Join a community that supports you and your coding journey from day one. We strive to be a friendly, supportive community that empowers everyone to be better developers. By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.

    GIF shows where to locate </> in the thread and or post editor toolbar.
    To learn more about how to use our BBCode feature, review our "How to post your code into threads" here.

    Thank you, Code Forum.

C++ Class

voldyy

Coder
Hello can someone help with this please
Write a receipt class.
Class to contain as data members
• The name of the store
• Array of prices of purchased goods, and member functions:

• Constructors

• get () and set () - for prices to work with individual elements of the array

• show () - displays a list of prices, the goods to be named product # 1, product # 2, etc.

• total () - determines the total price of the goods

• remove () - removes a product from the list (according to its index)

• discount () - reduces the price of goods by a certain percentage (the index of the goods in the array and the percentage are submitted as parameters)

• other member functions if desired

In the main function, illustrate how to work with the methods of the receipt class.
 
It's a start ...

You can add public and private sections in your class declaration to declare what can and cannot be accessed from outside the class.

You can add the function declarations from your question in the public section of the class declaration to indicate that they're accessible from users of the class.

One thing I'm wondering about in your original question is if an array should be used ... looking at the requirements, it seems that there isn't an option to add items to the receipt, but there is an option to remove them. I'm guessing that when you create a Receipt object you'll pass in an array of prices. For now I guess that would be the best approach: the other way would be to introduce a structure that can be resized, like a list, but I think keep it simple for now.

[CODE lang="cpp" title="Example"]
class Receipt
{
public:
// TODO: add constructor
// TODO: add destructor
void show();

private:
string storeName;
}
[/CODE]

I think with this sample: try to create an instance of it. Create the function void show(); to get a feeling for how that works. From the main function, create a Receipt object and call the show(); function.
 
Back
Top Bottom