• 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.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.
    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

C++ Class


New 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.

Krusty the Senile

Active Coder
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.

class Receipt
    // TODO: add constructor
    // TODO: add destructor
    void show();

    string storeName;

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.
Top Bottom