// Example program 26 // This program calculates Income tax // by looking at a tax table. #include int main() { double tax(int); int taxable_income; cout << "Enter your taxable income:"<> taxable_income; if(taxable_income > 200 || taxable_income <0) cout << "Can't find your tax from the given table"<= income_table[i]) ++ i; -- i; return tax_table[i]; } // Example program 27 // This program calculates the largest among // a set of real numbers. #include int main() { double max(double[], int); int i,number; double real_number[50]; cout <<"How many real numbers " <<"you would like to enter [1-50]?"<> number; cout <<"Please enter "<> real_number[i]; cout <<"The largest real number is " < largest) largest = x[k]; return largest; } // Example program 28 // This program calculates the shipping charges for // mail orders based on price and sales region. // The program uses the region number to access // the array elements. #include void main() { double rate[5] = {0.075,0.080,0.085,0.088,0.090}; int region; double price, charge, total_price; cout <<"Enter the price of the item: $"; cin >> price; cout<> region; if (region < 1 || region > 5) cout <<"\n\n*** Invalid region number ***"; else { charge = price * rate[region - 1]; total_price = price + charge; cout <<"\n\nItem Price: "< void main() { int valid(double); int emp_id, emp_hours; double emp_rate; double reg_pay,ovt_pay,gross_pay; int no_emps=0; double tot_pay=0.0; ifstream infile; ofstream outfile; infile.open("ex30.in"); outfile.open("ex30.out"); infile >> emp_id >> emp_hours >> emp_rate; // Print heading outfile <<"Employee Regular Overtime Gross"<> emp_id >> emp_hours >> emp_rate; } outfile<<"---------------------------------------"< #include #include void main() { sales_rec salesperson[SIZE]; // structure array // function prototypes void read_data(sales_rec [], int&); void calc_comm (sales_rec [], int); void sort (sales_rec [], int); void write_results(sales_rec [], int); int number; // number of salespeople's records // found in input file read_data(salesperson, number); calc_comm(salesperson, number); sort (salesperson, number); write_results(salesperson, number); return; } //-------------------------------------------------------- void read_data(sales_rec x[], int& n) { ifstream infile; infile.open("sales.in"); int i, j; i = 0; while (infile && i < SIZE) // Don't exceed array size { infile >> x[i].id >> x[i].lname >> x[i].fname; for (j = 0 ; j < 4; ++ j) infile >> x[i].sales[j]; ++ i; } n = i-1; infile.close(); return; } //--------------------------------------------------- // Calculate total commission void calc_comm (sales_rec sp[ ], int n) { // Commission rates for quarters 1, 2, 3, and 4 double rate[4] = {0.03, 0.045, 0.035, 0.04}; int i, j; for (i = 0; i < n; ++ i) { sp[i].comm = 0; for (j = 0; j < 4; ++j) sp[i].comm = sp[i].comm + sp[i].sales[j]*rate[j]; } return; } //-------------------------------------------------------- // Sorts in descending order void sort(sales_rec sp[], int n) { // temporary structure for swaping use sales_rec temp; int pass, i, limit; // do bubble sort limit = n - 2; for (pass = 1; pass < n; ++ pass) { for (i = 0; i <= limit; ++ i) if (sp[i].comm < sp[i+1].comm) { // swap temp = sp[i]; sp[i] = sp[i+1]; sp[i+1] = temp; } -- limit; } return; } //----------------------------------------------------- void write_results(sales_rec sp[], int n) { int i; ofstream outfile; char name[21]; outfile.open("sales.out"); // turn on manipulators outfile.setf(ios::fixed, ios::floatfield); outfile.setf(ios::showpoint); outfile<< setprecision(2); // write heading outfile <<"Salesperson ID " <<"Salesperson Name " <<"Commission"<