2 Replies - 564 Views - Last Post: 31 October 2012 - 08:02 AM Rate Topic: -----

#1 Mgssidley   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 14
  • Joined: 01-October 12

How do I integrate code for windows CMD?

Posted 31 October 2012 - 01:35 AM

I had the assignment to create a program that I will paste in a minute. I prompts for first and last name, then a pay rate and number of hours worked. It returns the name, along with the gross pay, state and federal taxes, and the net pay. As extra credit the goal was that we could open the program through command prompt, and just enter the pay rate and hours worked, then get back everything from before except for the name. Are there any simple to follow guides or someone who can help me with this? Here's my code: (You will see I used pass-by-reference with pointer and reference arguments, it was required to do one of each for the assignment so that's why.)


Source.cpp
#include "Salary.h"

int main()
{
	Salary getSalary;
	getSalary.displayMessage();
	system("Pause");
}


Salary.h
#include <iostream>
#include <string>
using namespace std;

class Salary
{
public:
	void displayMessage();
	void getName();
	void getPay();
	void grossPay( double &, double &);
	void getTax( double * );
	void getNet();
};


Salary.cpp
#include <iostream>
#include "Salary.h"
#include <string>
using namespace std;

string first;
string last;
double hours;
double rate;
double gross;
double *grossPtr;
double fTax;
double sTax;
double net;

void Salary::displayMessage()
{
	getName();
	getPay();
	grossPay(hours, rate);
	getTax( &gross );
	getNet();

	cout << endl << last << ", " << first << endl << 
		"Worked " << hours << " hours" << endl <<
		"$" << rate << " per hour" << endl <<
		"Gross pay is $" << gross << endl <<
		"Federal taxed ammount is $" << fTax << endl <<
		"State taxed ammount is $" << sTax << endl <<
		"Net pay is $" << net << endl;
}

void Salary::getName()
{
	cout << "Welcome, please enter the first and last name of employee: ";
	cin >> first >> last;
}

void Salary::getPay()
{
	cout << endl << "Please enter the number of hours this employee worked: ";
	cin >> hours;
	cout << endl << "Please enter this employee's pay rate: ";
	cin >> rate;
}

void Salary::grossPay( double &, double & ) // Pass by Reference
{
	if (hours <= 40) { // rate for < 40 hours
		(gross = hours * rate);
	}

	if (hours > 40) { // rate for > 40 hours (with overtime)
		(gross = ((40 * rate) + ((hours - 40) * (1.5 * rate))));
	}
}

void Salary::getTax( double *grossPtr )
{
  fTax = *grossPtr * .2;
  sTax = *grossPtr * .1;
}

void Salary::getNet()
{
	net = (gross - fTax - sTax);
}



Is This A Good Question/Topic? 0
  • +

Replies To: How do I integrate code for windows CMD?

#2 jimblumberg   User is offline

  • member icon

Reputation: 5519
  • View blog
  • Posts: 17,109
  • Joined: 25-December 09

Re: How do I integrate code for windows CMD?

Posted 31 October 2012 - 07:51 AM

If you mean you want to pass the arguments by use of the command line arguments then this tutorial may be a good starting point.

Jim

This post has been edited by jimblumberg: 31 October 2012 - 07:52 AM

Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades   User is offline

  • Saucy!
  • member icon

Reputation: 6246
  • View blog
  • Posts: 24,014
  • Joined: 23-August 08

Re: How do I integrate code for windows CMD?

Posted 31 October 2012 - 08:02 AM

Actually, I think what they're looking to do is saving to a file on entry, then allowing lookup from that file.

In which case, look into File I/O.

And what's with the globals in salary.cpp? Why aren't those member variables?
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1