# Another C++ Help



## levicolerogers (Sep 10, 2004)

This is the problem the question is asking me to use user defined functions to determine if a year (input) is a leap year. I have the math equation, I figured that out I can also make the program work, however, I cannot seem to fit it into the parameters of the question. 

It asks for the following user defined functions:

1 - no formal parameters, returns value year
2- math equation for determining leap year returns a Boolean Value
3 - handles a loop function for running the main function again "y or n"

If anyone could lend me a little help I have frustrated myself to the end. Gotta love these work on your own classes. 


Thanks,

L


----------



## elf (Jul 19, 2002)

Thats a hard question because:


> # Every year divisible by 4 is a leap year.
> # But every year divisible by 100 is NOT a leap year
> # Unless the year is also divisible by 400, then it is still a leap year.


and thats a lot of things to check for...

It can probably be done with a series of for loops. I'm not sure of the exact syntax because I'm working in C not C++, that and the math problem is where I would run into problems.

as for #3 just start the whole thing with a do-while loop and set a flag = 0. If I understand correctly you want the user to be prompted something like "again? (y/n)" which you can scan in then use in the while part of the do-while loop for instance

Its sort of hard to say with the instructions you've given. They are sort of vauge and I'm not exactly sure what you are looking for.


----------



## levicolerogers (Sep 10, 2004)

*A better explanation!!!*

I will give you the exact question from the text:

Creat the design for a program that prompts the user to enter a year and then determines whether it is a leap year. Your program should have a loop and continue while the user enthers the character "y".

Write three methods according to the following descriptions:

getYear has no formal paramaters, asks the user to enter a year, and reutnrs an integer value that is assigned to the integer variable year.

isLeap has an integer formal parameter, year, determines whether the year is a leap year, and returns the Boolean value true if the year is a leap year and false if it is not. (ive figured out the math problem just fine I've got that much now just how to implement it)


more Data has no mormal parameters and returns a char value.



Now for what I have:

#include <iostream>

using namespace std;


bool isLeap (int year);
int getYear (int year1);

int main ()
{
int y;

cout << "This program will tell you if a year is a leap year." << endl;
cout << "Please enter a year: ";
cin >> y;
cout << getYear;
cout << isLeap << endl;




}


int getYear (int year1)
{


if (year1 > 0)
return year1;
else
cout << "You didn't enter the right value!" << endl;
}

bool isLeap(int year)
{	

if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)
return true;
else 
return false;
}



Please please please if anyone can help me out I am way behind again, because of this one stupid problem. 

Thanks,

LR


----------



## mgoldb2 (Dec 16, 2004)

this should work but I did it very quickly so they may be better ways of doing it but I got it to compile and it seems to give me the right answer always.



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


----------



## levicolerogers (Sep 10, 2004)

*Thanks A million*

You got me rollin in the right direction, wow, that made it a little easier. I just couldn't quite seem to put it all together. 


LR


----------



## levicolerogers (Sep 10, 2004)

*Okay Maybe I just can't do this Crap*

Moving Onward--

As the school year comes to a close I am realizing that I am still a couple of chapters behind. So, of course, I email the teacher. Can you help me with the following etc. etc.. His response he copies paragraphs out of the book(that I have) and emails them back to me. Thanks, a**hole.

Here is the problem--

In this excercise create the design for a program that has in addition to the main function, two void functions with no parameters. Name one function instruction--it should provide information on the program to the user. Name the other function reportTitle-- it should display the headings of a future report. 

Manipulators are often included in the report title function because this function is used to set up a report. In this case, because it is a payroll program, use the manipulators fixed, showpoint, and left, and show values to two decimal points. 

After all employees are processed the program displays the total gross pay and the net pay. 

--END OF PROBLEM--


If you have any ideas of what the hell I should do and how I should do it, please by all means help me pass this friggin independant study class because ya its just aggravating me. 

Here is what I have. 

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>


using namespace std;

void instruct();
void report();

int main ()
{
char h = 'h';


cout << "Welcome to our Payroll Program!" << endl;
cout << "If you need help type 'help' now!";
cin >> h;
cout << endl;
{
if (h == 'h')
instruct();
}
report();

return 0;
}
void instruct()
{
cout << "Message to the user:" << endl; 
cout << "This program is designed to take payroll data--" << endl; 
cout << "From one specific area and place it into another." << endl; 
cout << "This will use math calculations to output results in report form. " << endl;
}
void report()
{
ifstream inFile;
ofstream outFile;
string empName;
double payRate, totHour, totTax, grossPay, netPay;

inFile.open("C:\\payroll.txt");
outFile.open("C:\\payrollout.txt");

outFile << fixed << showpoint << left;
outFile << setprecision(2);

inFile >> empName;
outFile << setw(10) << "Employee\nName" << "\n" << empName; 

inFile >> payRate;
outFile << setw(4) << "Pay Rate" << payRate;

inFile >> totHour;
outFile << setw(4) << "Hours\nWorked" << totHour;

inFile >> totTax;
outFile << setw(4) << "Tax\nRate" << totTax;

grossPay = payRate * totHour;
outFile << setw(4) << "Gross\nPay" << grossPay;

netPay = grossPay * totTax;
outFile << setw(8) << "Net Pay" << netPay;




inFile.close();
outFile.close();
}


Thanks,

LR


----------



## levicolerogers (Sep 10, 2004)

*Any Ideas Yet*

I was hoping that someone had an idea or direction for me to go.


----------



## levicolerogers (Sep 10, 2004)

*This is where I am now.*

Okay well I made it past the first problem now it wants me to take input from a file and use the heading I made in the last one to come out with a report for gross and net earning. 

I don't know if anyone is actually following this but here is what i have now. 

#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>


using namespace std;

void instruct();
void report();
void grossNet (double& payRate1, double& taxRate1, double& hours1);

int main ()
{
char h = 'h';
string firstName;
string lastName;
double payRate, hours, taxRate;
ifstream inFile;



cout << "Welcome to our Payroll Program!" << endl;
cout << "If you need help type 'help' now!";
cin >> h;
cout << endl;
{
if (h == 'h')
instruct();
}
report();

inFile.open("C:\\payroll.txt");
{	
if (!inFile)
cout << "Unable to open requested file." << endl;
return 1;
}
inFile >> payRate;
inFile >> hours;
inFile >> taxRate;
report();
grossNet(payRate, hours, taxRate);
cout << "Calculating!!" << endl;





return 0;
}
void instruct()
{
cout << "Message to the user:" << endl; 
cout << "This program is designed to take payroll data--" << endl; 
cout << "From one specific area and place it into another." << endl; 
cout << "This will use math calculations to output results in report form. " << endl;
}
void report()
{
ofstream outFile;

outFile.open("C:\\payrollout.txt");
outFile << fixed << showpoint << left;
outFile << setprecision(2);

outFile << setw(25) << "Employee" << setw(8) << "Pay" << setw(8) << "Hours" << setw(8) << "Tax" << setw(8) << "Gross" << setw(8) << "Net" << endl;
outFile << setw(25) << "Name" << setw(8) << "Rate" << setw(8) << "Worked" << setw(8) << "Rate" << setw(8) << "Pay" << setw(8) << "Pay" << endl;

cout << "Report Set-Up Finished" << endl;

outFile.close();
}
void grossNet(double& payRate1, double& taxRate1, double& hours1)
{
ofstream outFile;
ifstream inFile;
double grossPay, netPay;
string firstName, lastName;
outFile.open("C:\\payrollout.txt");
inFile.open("C:\\payroll.txt");
outFile << fixed << showpoint << left;
outFile << setprecision(2);

inFile >> firstName;
inFile >> lastName;

grossPay = hours1 * payRate1;
netPay = grossPay - (taxRate1 * grossPay);

outFile << setw(25) << firstName << setw(8) << payRate1 << setw(8) << hours1 << setw(8) << taxRate1 << setw(8) << grossPay << setw (8) << netPay << endl;

outFile.close();
inFile.close();
}


----------



## levicolerogers (Sep 10, 2004)

*Got it Here she is*

/*
Levi Cole Rogers
Chapter 7
Lab 7.3
04-10-05
*/
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

void instruct();
void report();

int main ()
{
char h = 'h';
string firstName;
string lastName;


cout << "Welcome to our Payroll Program!" << endl;
cout << "If you need help type 'help' now! ";
cin >> h;
cout << endl;

if(h == 'h')
instruct();

report();

return 0;
}

void instruct()
{
cout << "Message to the user:" << endl; 
cout << "This program is designed to take payroll data--" << endl; 
cout << "From one specific area and place it into another." << endl; 
cout << "This will use math calculations to output results in report form. " << endl;
}

void report()
{
ifstream inFile;
ofstream outFile;
string name, lastName, firstName;
double payRate, hours, taxRate = 0;
double grossPay, netPay = 0;
double totalGrossPay = 0, totalNetPay = 0;

inFile.open("C:\\payroll.txt");
if(!inFile)
{
cout << "Unable to open requested file." << endl;
return;
}

outFile.open("C:\\payrollout.txt");
if(!outFile)
{
cout << "Unable to open requestion file." << endl;
inFile.close();
return; 
}

outFile << fixed << showpoint << left;
outFile << setprecision(2);
outFile << setw(25) << "Employee" << setw(8) << "Pay" << setw(8) << "Hours" << setw(8) << "Tax" << setw(8) << "Gross" << setw(8) << "Net" << endl;
outFile << setw(25) << "Name" << setw(8) << "Rate" << setw(8) << "Worked" << setw(8) << "Rate" << setw(8) << "Pay" << setw(8) << "Pay" << endl;
outFile << "-----------------------------------------------------------------" << endl;

inFile >> firstName;
while(!inFile.eof())
{
inFile >> lastName;
inFile >> payRate;
inFile >> hours;
inFile >> taxRate;

name = firstName + " " + lastName;
grossPay = hours * payRate;
netPay = grossPay - (taxRate / 100 * grossPay);

totalGrossPay += grossPay;
totalNetPay += netPay;

outFile << setw(25) << name << setw(8) << payRate << setw(8) << hours << setw(8) << taxRate << setw(8) << grossPay << setw (8) << netPay << endl;

inFile >> firstName;
}

outFile << setprecision(2);
outFile << "-----------------------------------------------------------------" << endl;
outFile << setw(49) << "Totals:" << setw(8) << totalGrossPay << setw (8) << totalNetPay << endl;

inFile.close(); 
outFile.close();
}
/*
Employee Pay Hours Tax Gross Net 
Name Rate Worked Rate Pay Pay 
-----------------------------------------------------------------
John Smith 10.45 40.00 15.00 418.00 355.30 
Jane Doe 12.50 45.00 15.00 562.50 478.13 
Harry Morgan 20.00 40.00 20.00 800.00 640.00 
Carmen Martinez 25.00 35.00 25.00 875.00 656.25 
Jacintha Washington 50.85 60.00 35.00 3051.00 1983.15 
-----------------------------------------------------------------
Totals: 5706.50 4112.83 
*/


----------

