Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8167031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T20:04:35+00:00 2026-06-06T20:04:35+00:00

I have this simple program that computes salaries for four different worker types. It’s

  • 0

I have this simple program that computes salaries for four different worker types. It’s written semantically but I want to refactor it so I can have each worker type be it’s own class.

The main control of the program is in the switch statement. What I’d like to do is create a class for each worker type and then by use of appropriate setters and getters, perform the right calculations.

payroll.cpp

#include <iostream>
#include <iomanip>
using namespace std;

// Function Prototype
void userPrompt (void);

int main ()
{
// declare paycode and salary
int paycode; 
double salary;

// run user prompt function, input paycode
userPrompt ();
cin >> paycode;

while( paycode != -1 ) {

    //switch statement to handle user input
    switch( paycode ) {

        case 1: // manager
            cout << "Manager Selected." << endl;
            cout << "Enter Weekly Salary: ";
            // calculate manager's salary
            cin >> salary;
            cout << "Manager's pay is $" << std::fixed << setprecision( 2 ) << salary << "\n" << endl;
            break;

        case 2: // hourly worker
            double wage;
            int hours;
            cout << "Hourly worker Selected." << endl;
            cout << "Enter the hourly salary: ";
            cin >> wage;
            cout << "Enter the total hours worked: ";
            cin >> hours;
            // calculate hourly worker's pay
            // with respect to possible overtime
            if ( hours <= 40 )
                salary = hours * wage;
            else
                salary = 40.0 * wage + ( hours - 40 ) * wage * 1.5;
            cout << "Hourly worker's pay is $" << std::fixed << setprecision( 2 ) << salary << "\n" << endl;
            break;

        case 3: // commission worker
            int sales;
            cout << "Commission Worker Selected." << endl;
            cout << "Enter gross weekly sales: ";
            cin >> sales;
            // calculate commission worker's pay
            salary = sales * 0.092 + 250;
            cout << "Commission worker's pay is $" << std::fixed <<  setprecision( 2 ) << salary << "\n" << endl;
            break;

        case 4: // widget worker
            int widgets, wagePerWidget;
            cout << "Widget Worker Selected." << endl;
            cout << "Enter number of pieces: ";
            cin >> widgets;
            cout << "Enter wage per piece: ";
            cin >> wagePerWidget;
            // calculate widget worker's pay
            salary = widgets * wagePerWidget;
            cout << "Widget Worker's pay is $" << std::fixed <<  setprecision( 2 ) << salary << "\n" << endl;
            break;
    }

    // prompt user to input paycode again or exit
    cout<< "Enter paycode (-1 to end): ";
    cin >> paycode;
}

exit (0);
}

// userPrompt function declaration
void userPrompt (void)
{
// prompt user to input paycode
cout << "Enter paycode (-1 to end): ";

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T20:04:37+00:00Added an answer on June 6, 2026 at 8:04 pm

    Please review some tutorials for c++ class design if you need to learn the fundamentals of OOP.
    You will learn much more if you can answer your own question after some research.

    • http://www.tenouk.com/cplusplustutorial.html
    • http://www.cpp-tips.net/Simple_class_example
    • MIT OCW 6.088 Intro to C/C++
    • Youtube has some good resources too
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created this simple program to learn shared_ptr using namespace std; #define Yes
I have this simple example: using System; using System.Collections.Generic; namespace ConsoleApplication1 { class Program
My situation is simple. I have this in my program: File folder = new
I have this simple code, using Joda-time. Works fine, but I have a problem.
I have written a Java program on my computer that searches on the net
This should be pretty simple, but I can't seem to get it. I have
I am having some difficulty compiling a C++ program that I've written. This program
I have a simple C# and C++ code that computes a sum of dot
I've written a simple Node.js app that streams content (primarily for videos, but other
I have this simple piece of code : int a = 1, b =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.