I am working on an assignment for my C++ course, and could really use some help with the following problem:

Instructions:
1. In this assignment we are going to write an object oriented program to calculate provincial tax, federal tax and net income. Your objective is to design a class called CTaxCalc with the following functionality.
1. The program should allow you to enter a SIN number, gross income and province code and display the Federal Tax Amount, Provincial Tax Amount and Net Income.
2. Federal Tax – if gross income > 55000 then the tax rate is .28 otherwise it’s .21.
3. Provincial Tax is calculated according to the following table, use an if statement in your class to determine the provincial tax.

Province Code Tax Rate
ON .19
BC .22
MB .11
NS .09
QC .13
SK .06

4. Your class must contain a default constructor and at least 1 overloaded constructor to initialize your variables.
5. Pay close attention as to which class member functions and variables should public or private.
6. You do not need a menu for this assignment; we are strictly focusing on class design.
7. Your class should contain the appropriate GetValue() methods to display private variables to the screen.
8. Instantiate at least 3 objects of type CTaxCalc and display the results to the screen.

Here is the code that I have. I know for a fact, then I am not using the class properly, and I am not sure exactly how I would implement a default constructor or an overloaded constructor. Any help would be greatly appreciated!!!

// lab4.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

class CTaxCalc
{
    public:

    double PTaxAmount(double, double);
    double FTaxAmount(double, double);
    double NIncome(double, double, double);

    void output(int, double, double, double);   
};

int _tmain(int argc, _TCHAR* argv[])
{

    //Variable Declarations
    int sinNumber;
    double provincialTaxRate;
    double federalTaxRate;
    double grossIncome;
    double federalTaxAmount;
    double provincialTaxAmount;
    double netIncome;
    string provinceCode;

    //Input

    cout << "Enter S.I.N. Number: ";
    cin >> sinNumber;

    cout << "Enter gross income: ";
    cin >> grossIncome;

    cout << "Enter Province code: ";
    cin >> provinceCode;


    if (provinceCode == "ON")
            {
                provincialTaxRate = 19;         
            }
        else if (provinceCode == "BC")
            {
                provincialTaxRate = 22;     
            }
        else if (provinceCode == "MB")
            {
                provincialTaxRate = 11;     
            }
        else if (provinceCode == "NS")
            {
                provincialTaxRate = 9;      
            }
        else if (provinceCode == "QC")
            {
                provincialTaxRate = 13;     
            }
        else if (provinceCode == "SK")
            {
                provincialTaxRate = 6;      
            }



        if (grossIncome <= 55000)
        {
            federalTaxRate = 28;
        }

        else
        {
            federalTaxRate = 21;
        }

    CTaxCalc Lab4;

    provincialTaxAmount = Lab4.PTaxAmount(provincialTaxRate, grossIncome);

    federalTaxAmount = Lab4.FTaxAmount(grossIncome, federalTaxRate);

    netIncome = Lab4.NIncome(provincialTaxAmount, grossIncome, federalTaxAmount);

    Lab4.output(sinNumber, federalTaxAmount, provincialTaxAmount, netIncome);

    return 0;



}




//Calculation Functions
double CTaxCalc::PTaxAmount( double provincialTaxRate, double grossIncome)

{

        //calculations

        double provincialTaxAmount;

        provincialTaxAmount = provincialTaxRate / 100 * grossIncome;

        return provincialTaxAmount;

}

double CTaxCalc::FTaxAmount(double grossIncome, double federalTaxRate)

{

        //calculations  

        double federalTaxAmount;

        federalTaxAmount = federalTaxRate / 100 * grossIncome;

        return federalTaxAmount;

}

double CTaxCalc::NIncome(double provincialTaxAmount, double grossIncome, double federalTaxAmount)

{

        //calculations

        double netIncome;

        netIncome = grossIncome - provincialTaxAmount - federalTaxAmount;

        return netIncome;

}





void CTaxCalc::output(int sinNumber, double federalTaxAmount, double provincialTaxAmount, double netIncome)

{
    //output

        cout << endl;
        cout << "S.I.N. Number: " << sinNumber << endl;
        cout << "Federal Tax Amount: $" << setprecision(2) << fixed << federalTaxAmount << endl;
        cout << "Provincial Tax Amount: $" << setprecision(2) << fixed << provincialTaxAmount << endl;
        cout << "Net Income: $" << setprecision(2) << fixed << netIncome << endl;


        system ("pause");

}

Edited 4 Years Ago by pennywise134: problem with image

When you have two functions of the same name that take a different list of parameters, this is called overloading a function. When you do this sort of thing on a class constructor function, it is callled an overloaded constructor. Your default constructor is the class constructor that you define that has no parameter list, so it is therefore called by default when you create an instance of your class with no parameters.

Take this code, for a good example of what I'm talking about:

#include <iostream>

using std::cout;
using std::endl;

class myclass
{
    public:
        //Default constructor, empty parameter list.
        myclass()
        {
            cout << "Default constructor was called." << endl;
        }

        //Overloaded constructor, taking an integer as a parameter.
        myclass(int parameter)
        {
            cout << "myclass constructor called with paramater " << parameter << endl;
        }
};

int main()
{
    //This calls the default constructor since you're just creating the object and not
    //giving it any parameters.
    myclass myobj1;

    //This calls the overloaded constructor myclass::myclass(int) because you supplied
    //an integer in parenthesis after the object name.
    myclass myobj2(32);
    return 0;
}

Your job here is to find out a good use for this technique, and implement it into the program you're writing.

This article has been dead for over six months. Start a new discussion instead.