
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;
}

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 9 images

- C library functions are collection of function declarations saved in C header files. is a macro constant defined by the programmer. all functions defined in a program code by a programmer. programmer-defined functions shared among a team of software engineers.arrow_forwardwrite this using javascript arrow functionsarrow_forwardC++ programingarrow_forward
- Function 1: Password Checkerfunction _one(pwd)Create a JavaScript function that meets the following requirements:• Is passed a string representing a potential password• The function determines if the password meets the following requirementso The length of the password is between 8 – 12 characterso Contains at least 1 number (numeric character)o Contains at least 1 special character▪ Special characters are punctuation characters that are present on a standard keyboardnamely, any character encapsulated within the following double quotes“(!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~)”o Contains at least 1 capital letter• The function should NOT employ the use of regular expressions to solve the problem• The function also displays the result (console log) of its password validation as illustrated below.• The function returns a Boolean back to the caller indicating valid or not. Function 2: Calculate Remainderfunction _two(dividend, divisor)Create a JavaScript function that meets the…arrow_forwardWrite in c language please: write a statement that calls the function IncreaseItemQty with parameters computerInfo and addStock. Assign computerInfo with the returned value. #include <stdio.h> typedef struct ProductInfo_struct { char itemName[50]; int itemQty;} ProductInfo; ProductInfo IncreaseItemQty(ProductInfo productToStock, int increaseValue) { productToStock.itemQty = productToStock.itemQty + increaseValue; return productToStock;} int main(void) { ProductInfo computerInfo; int addStock; scanf("%s", computerInfo.itemName); scanf("%d", &computerInfo.itemQty); scanf("%d", &addStock); /* Your code goes here */ printf("Name: %s, stock: %d\n", computerInfo.itemName, computerInfo.itemQty); return 0;} thank you in advancearrow_forwardneed help in C++ Problem: You are asked to create a program for storing the catalog of movies at a DVD store using functions, files, and user-defined structures. The program should let the user read the movie through the file, add, remove, and output movies to the file. For this assignment, you must store the information about the movies in the catalog using a single vector. The vector's data type is a user-defined structure that you must define on functions.h following these rules: Identifier for the user-define structure: movie. Member variables of the structure "movie": name (string), year (int), and genre (string). Note: you must use the identifiers presented before when defining the user-defined structure. Your solution will NOT pass the unit test cases if you do not follow the instructions presented above. The main function is provided (you need to modify the code of the main function to call the user-defined functions described below). The following user-defined functions are…arrow_forward
- C++ formatting please Write a program (not a function) that reads from a file named "data.csv". This file consists of a list of countries and gold medals they have won in various Olympic events. Write to standard out, the top 5 countries with the most gold medals. You can assume there will be no ties. Expected Output: 1: United States with 1022 gold medals 2: Soviet Union with 440 gold medals 3: Germany with 275 gold medals 4: Great Britain with 263 gold medals 5: China with 227 gold medalsarrow_forwardGame of Hunt in C++ language Create the 'Game of Hunt'. The computer ‘hides’ the treasure at a random location in a 10x10 matrix. The user guesses the location by entering a row and column values. The game ends when the user locates the treasure or the treasure value is less than or equal to zero. Guesses in the wrong location will provide clues such as a compass direction or number of squares horizontally or vertically to the treasure. Using the random number generator, display one of the following in the board where the player made their guess: U# Treasure is up ‘#’ on the vertical axis (where # represents an integer number). D# Treasure is down ‘#’ on the vertical axis (where # represents an integer number) || Treasure is in this row, not up or down from the guess location. -> Treasure is to the right. <- Treasure is to the left. -- Treasure is in the same column, not left or right. +$ Adds $50 to treasure and no $50 turn loss. -$ Subtracts…arrow_forwardstruct employee{int ID;char name[30];int age;float salary;}; (A) Using the given structure, Help me with a C program that asks for ten employees’ name, ID, age and salary from the user. Then, it writes the data in a file named out.txt (B) For the same structure, read the contents of the file out.txt and print the name of the highest salaried employee and youngest employee names name in the outputscreen.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





