//----------------------------------------------- // FormLetter.cpp // // Illustrate an if-then structure using a very // simple form-letter program. // // D. Searls // Asbury College // Sept. 2006 //----------------------------------------------- #include<iostream> #include<iomanip> #include <string> #include <fstream> using namespace std; int main() { ifstream infile; // The input file ofstream outfile; // The output file string filename; string firstName; char middleInitial; string lastName; string streetAddress; string city; string state; string zipcode; double donation; int years; cout << "Enter the name of the input file (file1.dat, file2.dat): "; cin >> filename; infile.open(filename.c_str()); filename = "FormLetter.txt"; outfile.open(filename.c_str()); infile >> firstName >> middleInitial >> lastName; infile.ignore(1); getline(infile, streetAddress); infile >> city >> state >> zipcode; infile >> donation; infile >> years; infile.close(); outfile << setprecision(2) << fixed; outfile << firstName << ' ' << middleInitial << ". " << lastName << endl; outfile << streetAddress << endl; outfile << city << ", " << state << " " << zipcode << endl << endl; outfile << "Dear " << firstName << "," << endl << endl; outfile << "Thank you for supporting Asbury College. Your generous gift of $" << donation << " will help insure that Asbury can continue to offer " << "the best possible education to deserving young people at a reasonable " << "cost." << endl << endl; if (years > 5) { outfile << "We especially appreciate loyal supporters, like you, who have given " << "faithfully over the years. We owe you a debt of gratitude that can " << "never be repaid." << endl << endl << endl; } outfile << "Sincerely," << endl << endl << endl << endl << "Dr. Dudley Deux Right" << endl << "Vice President of Development"; outfile.close(); cout << "The output was sent to the file 'FormLetter.txt'.\n"; return 0; }
//********************************************************* // GrossPay1.cpp // // Calculate and display the gross pay given the hourly // wage and the number of hours worked. // // D. Searls // Asbury College // Aug 2003 //********************************************************* #include <iostream> #include <iomanip> #include <string> using namespace std; const double MAXHOURS = 40.0; const double OT_MULTIPLIER = 1.5; int main() { string empID; double hoursWorked; double hourlyWage; double regularPay; double overtimePay; double grossPay; // Get Employee Data cout << "Enter employee ID: "; cin >> empID; cout << "Enter hourly wage: "; cin >> hourlyWage; cout << "Enter hours worked: "; cin >> hoursWorked; cout << endl << endl; // Calculate Gross Pay if (hoursWorked <= MAXHOURS) { regularPay = hoursWorked * hourlyWage; overtimePay = 0.0; } else { regularPay = MAXHOURS * hourlyWage; overtimePay = (hoursWorked - MAXHOURS) * OT_MULTIPLIER * hourlyWage; } grossPay = regularPay + overtimePay; // Display Employee ID and gross pay cout << fixed << setprecision(2); cout << "Gross pay for employee " << empID << " is " << grossPay; cout << endl << endl; return 0; }