Welcome!

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.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

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.
 
@Krusty the Senile
I have only this, but i don't think its correctly written.


C++:
#include <iostream>
using namespace std;
class receipt {  
   string name;  
   static const double STOCKS=3;
   double price [STOCKS];
};
 
Last edited by a moderator:
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.
 
What else have you tried? We won't just give you the answer, the point of Code Forum is to help you figure it out, help you troubleshoot. Although we may just give the answer in certain questions, it's important we help you learn as well.
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom