SophiaPretty

(5)

$14/per page/Negotiable

About SophiaPretty

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Algebra See all
Accounting,Algebra,Applied Sciences,Architecture and Design,Art & Design,Biology,Business & Finance,Calculus,Chemistry,Communications,Computer Science,Economics,Engineering,English,Environmental science,Essay writing Hide all
Teaching Since: Jul 2017
Last Sign in: 314 Weeks Ago
Questions Answered: 15833
Tutorials Posted: 15827

Education

  • MBA,PHD, Juris Doctor
    Strayer,Devery,Harvard University
    Mar-1995 - Mar-2002

Experience

  • Manager Planning
    WalMart
    Mar-2001 - Feb-2009

Category > Computer Science Posted 04 Dec 2017 My Price 10.00

program that will total your wages for a pay period.

Write a program that will total your wages for a pay period. As a user, I should be asked to enter how many days I worked, the hours worked per each of those days, and then be asked for how much per hour I make. I should then see in a neatly formatted display, my total gross earnings for that pay period of days entered.

 

  • Start by asking the user how many days they have worked and their hourly rate while working those hours. Store these into variables as they will become handy later.
  • Create a pointer to a dynamically allocated array of the size equal to days worked. Remember this is done with the "new" keyword. Recall the relationship between pointers and arrays. 
  • Ask the user how many hours they worked for each day.
  • Display each day using a loop and total the number of hours worked and multiply the total times the hourly rate. Use any functions you feel is necessary to write in this program. You will be critiqued on your structure. There should be at least one other function besides main. Determine what you feel is necessary. Remember to delete the dynamic array after use before the program ends and it is deallocated automatically.

Attached is what I have so far. I am having issues with it. I really do not comprehend C++.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

void employee_info(FILE* fp, int* days, float* rate, float* hours);

float calc_gross_pay(float rate, float hours);

void display(FILE* fp, int days, float gross_pay);

int main()
{
    int days;
    float rate;
    float hours;
    float gross_pay;
    int nums;

    FILE *fpin;
    FILE *fpout;

    fpin = fopen("payperiod.in", "r");

    if(fpin == NULL)
    {
        printf("file 'payperiod.in' cannot be opened for reading\n");
        exit(1);
    }

    fpout = fopen("payperiod.out", "w");

    if (fpout == NULL)
    {
        printf("file 'employees.out' cannot be opened for writing");
        exit(1);

    }

    employee_info(fpin, &days, &rate, &hours);
    while (!feof(fpin))
    {

        nums++;

        gross_pay = calc_gross_pay(rate, hours);

        employee_info(fpin, &days, &rate, &hours);
    }

    fclose(fpin);
    fclose(fpout);

    return 0;
}

void employee_info(FILE* fp, int* days, float* rate, float* hours)
{
    fscanf(fp, "%d", days);

    fscanf(fp, "%f", rate);

    fscanf(fp, "%f", hours);

}


float calc_gross_pay(float rate, float hours)
{
    float gross_pay = 0;

    if (hours <= 40)
        gross_pay = rate * hours;
    else
        gross_pay = rate * 40 + (hours - 40) * rate * 1.5f;

    return gross_pay;
}

void display(FILE* fp, int days, float gross_pay)
{
    fprintf(fp, "%d %.2f\n", days, gross_pay);
    printf("%d %.2f\n", days, gross_pay);

}

Answers

(5)
Status NEW Posted 04 Dec 2017 01:12 PM My Price 10.00

-----------  ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly

Not Rated(0)