Gratuity calculator

Alright fellow c++ programmers. I am having a headache of a problem with this program. my difficulty comes from the fact that it needs to be broke down into 3 parts. a gratuity.h file a Gratuity file than the main revised .cpp file. I shall put what i have of each so far, my verified Uml document by my teacher, and what the book ask.

What the book ask:
Design a Tips class that calculates the gratuity on a restaurant meal. Its only class member variable, taxRate, should be set by a one parameter constructor to whatever rate is passed to it when a Tips object is created. if no argument is passed a default tax rate of .065 should be used. The class should have just one public function, computeTip. This function needs to accept two arguments, the total bill and the tip rate. It should use this information to compute what the cost of the bill was before tax was added. It should than apply the tip rate to just the meal cost portion of the bill to compute and return the tip amount. Demonstrate the class by creating a program that creates a single tip object, and than loops multiple times to allow the program user to retrieve the correct tip amount using various bill totals and desired tip rates.


The verified UML by my teacher:
Gratuity calculator
Tips

-taxRate: double

+Tip()
+Tip(r: double)
+computeTip(tB: double, tR: double): double



Gratuity.h

// File Gratuity.h -- Gratituity specification file
// Notice that the variables are declared here and so
// are the function protottypes.

#ifndef GRATUITY_H
#define GRATUITY_H

// Gratituity declaration
class Tip
{

private:

// These varidables are declared as private so they won't be accidently changed.
double taxRate;

public: // These varidables are declared as public to be used.
Tip();


// The following function is called whenever an outide program wants
// to know the totalAmountPaid.
double computeTip( double tB, double tR);

};

#endif // !GRATITUITY_H

Gratuity.cpp

// File Gratuity.cpp -- Tip class function

#include "Gratuity.h"

/****************************************************************
* Here is the default constructor. It is used when the main *
* program creates an object without any values. The constructor *
* will assign a value of 0 to totalBill and tipRate .065 to *
* taxRate. *
*****************************************************************/

Tip::Tip()
{

taxRate = .065;

}



/******************************************************************
* Tip::gettotalAmountPaid *
* This function calculates and returns the total paid ammount. *
*******************************************************************/
double Tip::gettotalAmountPaid(double tip)
{

double totalAmountPaid, tipRate, totalBill, taxCalculation;
taxCalculation = (tipRate + totalBill) * taxRate;

totalAmountPaid = tipRate + totalBill + taxCalculation;

return double(tip) = totalAmountPaid;

revisedGratuity.cpp

// Kohl Lobsiger
// C.I.S.P. 1010
// lab 7A final part
// 3/28/17
// this program uses the Tip class.
// The Tip class declaration is in file Gratuity.h.
// The Tip member function definitions are in Gratuity.cpp
// These files should all be combined into a project.

#include <iostream>
#include "Gratuity.h"

using namespace std;

int main()
{

double taxRate, tipRate, totalBill, totalAmountPaid;

Tip server;

cout << " What was the total bill? $";
cin >> totalBill;

cout << " What was the tip? $";
cin >> tipRate;

cout << " What was the taxes? if less than 0 is entered program will defer to .065: ";
cin >> taxRate;

totalAmountPaid = totalBill + tipRate + taxRate;


double tTotal = server.gettotalAmountPaid(totalAmountPaid);

cout << " The Total amount paid is. : $" << totalAmountPaid << endl;

return 0;
what is the trouble? Do you know how to add both cPP files to your project (IDE, etc) or makefile and get it to compile? Is that the question?
No, im just missing something or im not doing something right with the program.
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// This becomes the Tips.h file
#include <iostream>

class Tips{
    
private:
    double taxRate;
    
public:
    Tips(double = .065);
    
    double computeTip(double, double);
    
};

// This becomes the Tips.cpp file - add #include Tips.h
Tips::Tips(double aTaxRate){
    taxRate = aTaxRate;
}

double Tips::computeTip(double aTotalBill, double aTiprate){
    return aTotalBill/(1 + taxRate) * aTiprate;
}


int main()
{
    Tips customer;
    std::cout << "Tip: $" << customer.computeTip(106.5, .1) << '\n';
    
}


Tip: $10
Program ended with exit code: 0


Don't forget the loop in main.
Last edited on
alright now i just got to mold that to my main right? thanks for your help!
Last edited on
closed account (48T7M4Gy)
You will have 3 files with includes as follows

Tips.h - no #include required
Tips.cpp - #include "Tips.h"

main() program file, some_name.cpp file - #include "Tips.h" and #include <iostream>

Yah, i got that i just mean i need to figure out the main sill right? or? I'm sorry this multiple parts to program things got me scratching lol i probably sound really stupid.
yah im still getting a crazy amount of errors
closed account (48T7M4Gy)
main sill right? or?
Whatever that means.

Just make up the 3 files and put all 3 in the same directory. Should work.

BTW You need to re-read the question you were given.
The class should have just one public function, computeTip
Last edited on
Topic archived. No new replies allowed.