Not exactly sure where to start with this one.. there are several methods and da
ID: 3603106 • Letter: N
Question
Not exactly sure where to start with this one.. there are several methods and data needs to be stored as the questions are asked
Use arrays & methods. USE METHODS. DO NOT use global variables. All data must
be passed to methods using the parameters. A car dealership wants to process sales
information for each of his dealers. Ask the user to enter the number of dealers. Don’t allow the
user to enter a negative number for the number of dealers and also don’t allow for a number
more than 30 for the number of dealers. For each dealer, store the name of the dealer and the
amount of sales in 2 parallel arrays. Don’t allow the user to enter a negative number for sales.
Create a continuous loop to keep asking the user for valid values. Calculate commission in
dollars and store it in another array based on the following table:
Write a method to input and return the number of dealers. Perform the appropriate data
validation here.
Write a method to gather the required input data. Perform the appropriate data validation here.
Write a method to calculate the commission array.
Write a method to calculate and return total sales for the dealership. Totals sales does not
include the commission.
Write a method to calculate and return average sales for the dealership. The average sales value
does not include the commission.
Write a method to calculate and return the total commission for the dealership.
Write a method to display the dealer name and amount of sales and the amount of commission
for all dealers in a tabular format.
Write a method that accepts the name of a dealer as its parameter and returns the amount of
commission for the given dealer. If the given name does not exist, return an error code (i.e. -1)
that can be used in the main method to issue an error message. NOTE that the method does not
have any print statements in it.
In your main method, make sure to call your methods to perform the operations. MAKE sure
to display all the calculated data returned by your methods. For example, the totals and
averages must be displayed, so the answers could be checked. Make output descriptive and
provide 2 digits after the decimal point for all monetary values.
Explanation / Answer
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
void gatherdata(string &a, double &b){
cout << "Enter name of the dealer :";
cin >> a;
cout << "Enter sales of the dealer :";
cin >> b;
while (b < 0){
cout << "Error : Please enter a positive value :";
cin >> b;
}
}
int input(string *a, double *sales){
int n;
cout << "Enter number of dealers :";
cin >> n;
while (n < 0 || n > 30){
cout << "Error : Please enter a positive value (1-30) :";
cin >> n;
}
for (int i = 0; i<n; i++){
gatherdata(a[i],sales[i]);
}
return n;
}
void calCommision(double *sales, double *commision, int n){
for (int i = 0; i<n; i++){
if (sales[i] >= 1 && sales[i] <=5000)
commision[i] = 8;
else if (sales[i] > 5000 && sales[i] <=15000)
commision[i] = 15;
else if (sales[i] > 15000 )
commision[i] = 20;
}
}
double averageSales(double *sales, int n){
double sum = 0;
for (int i = 0; i<n; i++){
sum = sum + sales[i];
}
return sum/n;
}
double totalSales(double *sales, int n){
double sum = 0;
for (int i = 0; i<n; i++){
sum = sum + sales[i];
}
return sum;
}
double totalCommision(double commision[], int n){
double sum = 0;
for (int i = 0; i<n; i++){
sum = sum + commision[i];
}
return sum;
}
void display(string a[], double sales[], double commision[], int n){
cout << setw(20) << "Name" << setw(20) << "Sales" << setw(20) << "Commision" << endl;
for (int i = 0; i<n; i++){
cout << setw(20) << a[i] << setw(20) << setprecision(2) << fixed << sales[i];
cout << setw(20) << commision[i] << "%" << endl;
}
}
double getCommision(string a[], double commision[] ,string b, int n){
for (int i = 0; i<n; i++){
if (a[i] == b){
return commision[i];
}
}
return -1;
}
int main(){
string names[30];
double sales[30];
double commision[30];
int n = input(names,sales);
calCommision(sales,commision,n);
display(names,sales,commision,n);
cout << totalSales(sales,n) << endl;
cout << averageSales(sales,n) << endl;
cout << totalCommision(commision,n) << endl;
cout << getCommision(names,commision,"John",n) << endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.