Write the function readSalesData. #include #include #include #include #include using namespace std; // structure definition struct Sales {     string name;     int amount; }; // function prototypes double detCommissionPercent(int sales); double detAmountEarned(int sales); Sales* readSalesData(string filename, int& noPeople); int calculateTotal(Sales* list, int noPeople); void showSalesData(Sales* list, int noPeople, int total); void saveSalesData(string filename, Sales* list, int noPeople, int total); int main() {     // pointer to be used to dynamically allocate an array of Sales structures     Sales *list;              // other variables     int noPeople;           // number of sales people     string filename;        // input file name      int total;          // function calls     cout << "Enter input file name: "; // without extension     cin >> filename;     filename += ".txt";     // call readSalesData      ifstream inFile;          //Open the file     inFile.open(filename.c_str());          //Test for file open errors     if (!inFile)     {         cout << "Error opening the input file: " << filename << "." << endl;         exit (101);     }//if          inFile >> noPeople;          //Display error when number of salesperson is 0 or negaative     if (noPeople <= 0) {             cout << "The array size is invalid." << endl;             cout << "The program ends here!" << endl;             return 0;     }     else {            list = new Sales[noPeople];            readSalesData (filename, noPeople);             }                   // call calculateTotal     total = calculateTotal (list, noPeople);          string answer;     cout << "\nShow Report(Y/N)? ";     cin >> answer;     if (answer == "y" || answer == "Y") {         // call showSalesData         showSalesData (list, noPeople, total);     }          // call saveSalesData     saveSalesData (filename, list, noPeople, total);          delete [] list;          return 0; } /* Write your code here. For each function definition write a short comment too, as demonstrated in previous assignments */ /*~*~*~*~*~*~  This function determines the commision percent based on the following table:     Sales        Commission    $0 - 1000        3%  1001 - 5000        4.5%  5001 - 10,000      5.25%  over 10,000        6% *~*/ double detCommissionPercent(int sales) {     double commission = 0;     /*Write your code here */     if (sales <= 1000) {         commission = 3;     }     else if (sales <= 5000) {         commission = 4.5;     }     else if (sales <= 10000) {         commission = 5.25;     }     else {         commission = 6;     }          return commission; } /*~*~*~*~*~*~  This function determines the amount earned:  it calls the detCommisionPercent) function. *~*/ double detAmountEarned(int sales) {     double amountEarned = 0;     /* Write your code here */     amountEarned = detCommissionPercent(sales) * sales / 100.0;          return amountEarned; } ///////////////////////////////////// //Calculate all data and add to the total int calculateTotal(Sales *list, int noPeople) {     int total = 0;     for(int i = 0; i < noPeople; i++) {         total += list[i].amount;     }          return total; }//calculateTotal ///////////////////////////////////// //Read the sales data from file and store it in an array of structures Sales* readSalesData(string filename, int& noPeople) {     }//readSalesData /////////////////////////////////////////// /*Display the amount sold, names, comission percent, and amount earned for each person on screen. It also shows the total amount earned by all sales persons.*/ void showSalesData(Sales* list, int noPeople, int total) {     cout << "ABC Company Report" << endl;     for(int i = 0; i < noPeople; i++)     {         cout << "$";         cout << right << setw(6) << list[i].amount;         cout << " " << list[i].name << ",";         cout << fixed << setprecision(2) << " " << detCommissionPercent(list[i].amount);         cout << "% ($" << detAmountEarned(list[i].amount) << ")" << endl;     }     cout << "Total Sales: $" << total << endl; }//showSalesData ///////////////////////////////////////////// //Save data void saveSalesData(string filename, Sales* list, int noPeople, int total) {     string out_file_name = "";     for(int i = 0; filename[i]; i++)     {         if(filename[i] == '.')             break;         out_file_name += filename[i];     }     out_file_name += "_report.txt";     ofstream fout(out_file_name);     fout << "ABC Company Report" << endl;     for(int i = 0; i < noPeople; i++)     {         fout << "$";         fout << right << setw(6) << list[i].amount;         fout << " " << list[i].name << ",";         fout << fixed << setprecision(2) << " " << detCommissionPercent(list[i].amount) << "%";         fout << " ($" << detAmountEarned(list[i].amount) << ")" << endl;     }     fout << "Total Sales: $" << total;     cout << "The Sales Report has been saved to \"" << out_file_name << "\"" << endl; }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write the function readSalesData.

#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <string>

using namespace std;

// structure definition
struct Sales {
    string name;
    int amount;
};

// function prototypes
double detCommissionPercent(int sales);
double detAmountEarned(int sales);

Sales* readSalesData(string filename, int& noPeople);
int calculateTotal(Sales* list, int noPeople);
void showSalesData(Sales* list, int noPeople, int total);
void saveSalesData(string filename, Sales* list, int noPeople, int total);

int main()
{
    // pointer to be used to dynamically allocate an array of Sales structures
    Sales *list;
        
    // other variables
    int noPeople;           // number of sales people
    string filename;        // input file name 
    int total;
    
    // function calls
    cout << "Enter input file name: "; // without extension
    cin >> filename;
    filename += ".txt";
    // call readSalesData 
    ifstream inFile;
    
    //Open the file
    inFile.open(filename.c_str());
    
    //Test for file open errors
    if (!inFile)
    {
        cout << "Error opening the input file: " << filename << "." << endl;
        exit (101);
    }//if
    
    inFile >> noPeople;
    
    //Display error when number of salesperson is 0 or negaative
    if (noPeople <= 0) {
            cout << "The array size is invalid." << endl;
            cout << "The program ends here!" << endl;
            return 0;
    }
    else {
           list = new Sales[noPeople];
           readSalesData (filename, noPeople);        
    }
    
        
    // call calculateTotal
    total = calculateTotal (list, noPeople);
    
    string answer;
    cout << "\nShow Report(Y/N)? ";
    cin >> answer;
    if (answer == "y" || answer == "Y") {
        // call showSalesData
        showSalesData (list, noPeople, total);
    }
    
    // call saveSalesData
    saveSalesData (filename, list, noPeople, total);
    
    delete [] list;
    
    return 0;
}

/* Write your code here. For each function definition write a short comment too,
as demonstrated in previous assignments */

/*~*~*~*~*~*~
 This function determines the commision percent based on the following table:
    Sales        Commission
   $0 - 1000        3%
 1001 - 5000        4.5%
 5001 - 10,000      5.25%
 over 10,000        6%
*~*/
double detCommissionPercent(int sales)
{
    double commission = 0;

    /*Write your code here */
    if (sales <= 1000) {
        commission = 3;
    }
    else if (sales <= 5000) {
        commission = 4.5;
    }
    else if (sales <= 10000) {
        commission = 5.25;
    }
    else {
        commission = 6;
    }
    
    return commission;
}

/*~*~*~*~*~*~
 This function determines the amount earned:
 it calls the detCommisionPercent) function.
*~*/
double detAmountEarned(int sales)
{
    double amountEarned = 0;
    /* Write your code here */
    amountEarned = detCommissionPercent(sales) * sales / 100.0;
    
    return amountEarned;
}

/////////////////////////////////////
//Calculate all data and add to the total
int calculateTotal(Sales *list, int noPeople)
{
    int total = 0;
    for(int i = 0; i < noPeople; i++) {
        total += list[i].amount;
    }
    
    return total;
}//calculateTotal

/////////////////////////////////////
//Read the sales data from file and store it in an array of structures
Sales* readSalesData(string filename, int& noPeople)
{
   
}//readSalesData

///////////////////////////////////////////
/*Display the amount sold, names, comission percent,
and amount earned for each person on screen.
It also shows the total amount earned by all sales persons.*/

void showSalesData(Sales* list, int noPeople, int total)
{
    cout << "ABC Company Report" << endl;
    for(int i = 0; i < noPeople; i++)
    {
        cout << "$";
        cout << right << setw(6) << list[i].amount;
        cout << " " << list[i].name << ",";
        cout << fixed << setprecision(2) << " " << detCommissionPercent(list[i].amount);
        cout << "% ($" << detAmountEarned(list[i].amount) << ")" << endl;
    }
    cout << "Total Sales: $" << total << endl;
}//showSalesData

/////////////////////////////////////////////
//Save data
void saveSalesData(string filename, Sales* list, int noPeople, int total)
{
    string out_file_name = "";
    for(int i = 0; filename[i]; i++)
    {
        if(filename[i] == '.')
            break;
        out_file_name += filename[i];
    }
    out_file_name += "_report.txt";
    ofstream fout(out_file_name);
    fout << "ABC Company Report" << endl;
    for(int i = 0; i < noPeople; i++)
    {
        fout << "$";
        fout << right << setw(6) << list[i].amount;
        fout << " " << list[i].name << ",";
        fout << fixed << setprecision(2) << " " << detCommissionPercent(list[i].amount) << "%";
        fout << " ($" << detAmountEarned(list[i].amount) << ")" << endl;
    }
    fout << "Total Sales: $" << total;
    cout << "The Sales Report has been saved to \"" << out_file_name << "\"" << endl;
}

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 9 images

Blurred answer
Knowledge Booster
Variables
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education