All pastes #165135 Raw Edit

Untitled

public text v1 · immutable
·published 2006-09-09 14:52 UTC
rendered paste body
#include <iostream> // included for the IO stream
#include <fstream> // for the filestream
#include <iomanip> // to manipulate output to the screen
#include <string> // allows the use of strings
#include "structs.h" //Include the struct//

using namespace std;


int read_data(ifstream& infile, employeetype elist[]) //Begin read_data function
{
	
    int i = 0; //Initialize counter variable to 0
    
	infile  >> elist[i].id_number >> elist[i].first_name >> elist[i].last_name //Input the data from the text file
        	>> elist[i].number_of_sales >> elist[i].revenue >> elist[i].commission_rate;

	//Begin sentinel while loop
	while(infile)
    {
		i++; //Increment the counter variable
		infile >> elist[i].id_number >> elist[i].first_name >> elist[i].last_name //Input the data from the text file
			   >> elist[i].number_of_sales >> elist[i].revenue >> elist[i].commission_rate;
    }
	//End sentinel Logic

    return i; //Return I to be stored into "number_of_employees"
}



void calculate_data(employeetype elist[], int number_of_employees) //Begin calculate function
{
	int i = 0;//Initialize counter variable to 0
	while(i < number_of_employees) //Begin while loop
	{
		elist[i].average_sale = (elist[i].revenue / elist[i].number_of_sales); //Calculate and store averages
		elist[i].commission_earned = (elist[i].revenue * elist[i].commission_rate); //Calculate and store commission
		i++; //Increment Counter Variable i 
	}


}

void output_data(employeetype elist[], int number_of_employees) //Beging output_data function
{
	int i = 0;//Initialize counter variable to 0
	float total_sales = 0; //Float: Total Sales over this time period
	cout << fixed; // Allow fixed decimals
	while(i < number_of_employees) // Begin while loop
	{
		//Begin outputing the appropriate data
		cout << endl << "Sales Record: " << i;
		cout << endl << "Salesperson: " << elist[i].last_name << ", " << elist[i].first_name;
		cout << endl << "ID Number: " << elist[i].id_number;
		cout << endl << "Sales Made: " << setprecision(2) << elist[i].number_of_sales;
		cout << endl << "Total Revenue: " << setprecision(2) << elist[i].revenue;
		cout << endl << "Commission Percent: " << setprecision(2) << elist[i].commission_rate;
		cout << endl << "Average Per Sale: $" << setprecision(2) << elist[i].average_sale;
		cout << endl << "Commission Earned: $" << setprecision(2) << elist[i].commission_earned << endl << endl;
		//End outputing the appropriate data
		total_sales = total_sales + elist[i].revenue; //Continuous Adding of Total Sales
		i++; // Increment Counter i 
	}
	
	cout << endl << "Total Sales for this Period: $" << total_sales << endl; // Output total sales

}