Hi everyone, I am new to C++ and have no idea where to start with classes. I took my first programming class last semester and just started object oriented programming. I am new to classes and this is my first assignment. Any help with a link or anything would be greatly appreciated. Thanks in advance, Jillian

Create a program that displays the result of a sales transaction. The calculation requires three numbers. The first number represents the product price. The second number is the sales person commission. These two numbers should be added together. The third value represents a customer discount; subtract this third number from the result of the addition. Create two classes. The first class contains the method to do the calculation. The three numbers are passed to this method by a statement in the other class. The display is performed in the class that calls the calculation method. Save the programs as Transaction.cpp (driver program) and Commission.cpp (has the calculations).


What part do you need help with?

Classes generally have two aspects to them: Things they know and things they do. The first is generally taken care of by the class member variables, while the second is the job of the class's member functions (sometimes called class methods).

The task you posted already states that you're going to need to make two classes, so that's a start! So now think of the things that need to be known and done by the two classes (you might as well call the two classes Commission and Transaction, since these seem as good a names as any).

The question says that Commission needs to do the actual calculating, so that should probably have a method with a name that indicates that's what it's doing. You know that the calculation uses three numbers and results in a single number, so you kind of know what the function should look like from that. And that's about it for the Commission class, It doesn't seem to need to do anything else.

Transaction needs to know the numbers that the calculation is done with, so it's going to have to have member variables for those. It also needs to do several things: Ask the user for the numbers, call the function in Commission that does the calculation and display the result to the user. You'll probably need member functions for all of those actions.

If you don't know the syntax for declaring and defining classes in C++ then you can easily look this up on the internet.

Have fun.


Thanks for responding! To be honest, I don't know yet. I have read the post from ravenous which is very helpful. I am going to code what I can and then post and get help from there :). Thanks for your willingness to help!



Thank you so very much for the detailed and clear explanation of classes. You broke down the problem to a simple format where I can understand. I will code and post when I am doen to see if I am on the right track :)

Thank you so much!