//pg 368 #1
/*
void initialize (double& h, double& r)
{
h=0;
r=0;
}
void getHoursRate (double& h, double& r)
{
cout<<"please enter how many hours you worked. ";
cin>>h;
cout<<endl;
cout<<"please enter your rate. ";
cin>>r;
cout<<endl;
}
double paycheck (double h, double r)
{
double overTime, finalAmount=0, ot=0;
if (h<=40)
finalAmount = h * r;
else
{
overTime = h * (r * 1.5) - (40 * r * 1.5);
finalAmount =overTime + 40 * r;
}
return finalAmount;
}
void printCheck (double h, double r, double finalAmount)
{
cout<<"You worked "<<h<<" hours."<<endl;
cout<<"Your rate was $"<<r<<" dollars an hour."<<endl;
if (h>40)
{
cout<<"You worked "<<h-40<<" hours over time."<<endl;
cout<<"Your overtime pay is $"<<(h-40) * (r * 1.5)<<" dollars."<<endl;
}
else
{
cout<<"You worked "<<0<<" hours over time."<<endl;
cout<<"Your overtime pay is $"<<0<<" dollars."<<endl;
}
cout<<"Your total paycheck is $"<<finalAmount<<" dollars."<<endl<<endl;
}
int main()
{
double rate, hours;
double amount;
initialize(hours, rate);
getHoursRate (hours, rate);
amount= paycheck(hours, rate);
printCheck(hours, rate, amount);
return 0;
}
*/
//pg 369 #4
/*
void openFiles (ifstream& inp, ofstream& out)
{
inp.open("g:\\GPA.txt");
out.open("g:\\GPAOut.txt");
out<<fixed<<showpoint;
out<<setprecision(2);
out<<"Tim Stroud"<<endl;
}
void initialize (int& countFemale, int& countMale, double& sumFemaleGPA, double& sumMaleGPA)
{
countFemale=0;
countMale=0;
sumFemaleGPA=0;
sumMaleGPA=0;
}
void sumGrades (char& gender, int& grade, int& countFemale, int& countMale, double& sumFemaleGPA, double& sumMaleGPA)
{
if (gender=='M' ||gender=='m')
{
sumMaleGPA=sumMaleGPA+grade;
countMale++;
}
else
{
sumFemaleGPA=sumFemaleGPA+grade;
countFemale++;
}
}
void averageGrades (int countFemale, int countMale, double sumFemaleGPA, double sumMaleGPA, double& avgMale, double& avgFemale)
{
avgMale=0;
avgFemale=0;
avgFemale=sumFemaleGPA/countFemale;
avgMale=sumMaleGPA/countMale;
}
void printResults (int countFemale, int countMale, double sumFemaleGPA, double sumMaleGPA, double avgMale, double avgFemale, ofstream& out)
{
out<<"The sum of the males is "<<sumMaleGPA<<endl;
out<<"The sum of the females is "<<sumFemaleGPA<<endl;
out<<"The average grade for the males is "<<avgMale<<endl;
out<<"The average grade for the females is "<<avgFemale<<endl;
}
int main ()
{
int countFemale, countMale;
double sumFemaleGPA, sumMaleGPA, avgMale, avgFemale;
ifstream inp;
ofstream out;
int grade;
char gender;
openFiles(inp, out);
initialize (countFemale, countMale, sumFemaleGPA, sumMaleGPA);
inp>>gender>>grade;
while (inp)
{
sumGrades (gender, grade, countFemale, countMale, sumFemaleGPA, sumMaleGPA);
inp>>gender>>grade;
}
averageGrades (countFemale, countMale, sumFemaleGPA, sumMaleGPA, avgMale, avgFemale);
printResults (countFemale, countMale, sumFemaleGPA, sumMaleGPA, avgMale, avgFemale, out);
return 0;
}
*/
timdog345 -1 Light Poster
Nick Evan 4,005 Industrious Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.