Answer to Question #271124 in C++ for Tinker

Question #271124

Write a C++ one dimensional array program that prompts and reads in the sales for each salespeople(number of salespeople are 5 and each salespeople name should be stored) for each category(viz.. Living,bed,dining,office,decor) in a company. Then prints out the salespeople's name and amount of sales for each category and their respective total sales.

a.  Each salespeople's total sale should be stored and cumulatively added everytime the program runs.

b.  also overall sale(sum of every salespeople's total sales) should be displayed and stored and should also be cumulatively added everytime the program runs.



1
Expert's answer
2021-11-25T00:53:19-0500
#include <iostream>
#include <string>




using namespace std;
int main (){
	float sales[1000];
	int numberSalespeople=0;
	string name;
	//reads in the sales for each salespeople in a company.
	cout<<"Enter the number of salespeople in a company: ";
	cin>>numberSalespeople;
	for(int i=0;i<numberSalespeople;i++){
		sales[i]=-1;
		while(sales[i]<0){
			cout<<"Enter sales for salespeople "<<(i+1)<<": ";
			cin>>sales[i];
		}
	}
	//It then prints out the ID and amount of sales for each salesperson and the total sales.
	float totalSales=0;
	float maximumSale=sales[0];
	int maximumSaleIndex=0;
	float minimumSale=sales[0];
	int minimumSaleIndex=0;
	cout<<"ID\tAmount of sales\n";
	for(int i=0;i<numberSalespeople;i++){
		cout<<(i+1)<<"\t"<<sales[i]<<"\n";
		totalSales+=sales[i];
		if(maximumSale<sales[i]){
			maximumSale=sales[i];
			maximumSaleIndex=i;
		}
		if(minimumSale>sales[i]){
			minimumSale=sales[i];
			minimumSaleIndex=i;
		}
	}
	cout<<"\nTotal sales: "<<totalSales<<"\n";
	//Compute and Print the average sale.
	float averageSale=totalSales/(float)numberSalespeople;
	cout<<"\nThe average sale: "<<averageSale<<"\n";
	//Find and print the maximum sale. Print both the ID of the salesperson with the max sale and the amount of sale.
	cout<<"\nThe maximum sale: "<<maximumSale<<"\n";
	cout<<"The ID of the salesperson with the maximum sale: "<<(maximumSaleIndex+1)<<"\n";
	//Do the same for the minimum sale.
	cout<<"\nThe minimum sale: "<<minimumSale<<"\n";
	cout<<"The ID of the salesperson with the minimum sale: "<<(minimumSaleIndex+1)<<"\n";
	//After the list, sum, average, max and minimum have been printed, ask the user to enter a value.
	float amountSales=-1;
	while(amountSales<0){
		cout<<"Enter the value for sales: ";
		cin>>amountSales;
	}
	//Then print the ID of each salesperson who exceeded that amount, and the amount of their sales.
	cout<<"\nSalesperson who exceeded this amount:\n";
	cout<<"ID\tAmount of sales\n";
	int totalNumberSalespeople=0;
	for(int i=0;i<numberSalespeople;i++){
		if(amountSales<=sales[i]){
			cout<<(i+1)<<"\t"<<sales[i]<<"\n";
			totalNumberSalespeople++;
		}
	}
	//Also print the total number of salespeople whose sales exceeded the value entered.
	cout<<"The total number of salespeople whose sales exceeded this value: "<<totalNumberSalespeople<<"\n\n";




	system("pause");
	return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS