|
|
|
|
|
|
|
Now we can write the program: |
|
|
|
|
|
|
|
|
//******************************************************************
// Incomes program
// This program reads a file of income amounts classified by
// gender and computes the average income for each gender
//******************************************************************
#include <iostream.h>
#include <iomanip.h> // For setprecision()
#include <fstream.h> // For file I/O
int main()
{
char sex; //Code F = female, M = male
int femaleCount; // Number of female income amounts
int maleCount; // Number of male income amounts
float amount; // Amount of income for a person
float femaleSum; // Total of female income amounts
float maleSum; // Total of male income amounts
float femaleAverage; // Average female income
float maleAverage; // Average male income
ifstream incFile; // File of income amounts
cout.setf(ios::fixed, ios::floatfield); // Set up floating pt.
cout.setf(ios::showpoint); // output format
cout << setprecision(2);
// Separately count females and males, and sum incomes
// Initialize ending condition |
|
|
|
|
|