Answer to Question #272741 in C++ for rina

Question #272741

Techics Comp has 5 salesmen. Each salesman keeps track of the number of computer sold each month. The manager assigns a number, 1 to 5, to each salesperson with their name. 

 

Write a complete C++ program to store the number of computers sold by each salesperson in the array comp[] and output the total number of computer sold for the given month. The program will calculate and display the highest and the lowest number of computer sold for the month together with the salesperson’s name. It also can search the amount of sold computers by the salesperson whether it was exist or not. If found, display the salesperson name. If not, display it is not exist.

 

Your program should allow the user to repeat this process as often as the user wishes.



1
Expert's answer
2021-11-28T11:44:54-0500
#include<iostream>
#include<string>
using namespace std;


int main()
{
	const int N = 5;
	string salespers[N] = { "Jack","Mary","Ann","Michale","Sofi" };
	int comp[N];
	int i = 0;
	char ch;
	do
	{
		cout << "Please, enter a number of computers sold by " << salespers[i] << ": ";
		cin >> comp[i];
		if (i == N-1)
		{
			int n = comp[0];
			int max_num = 0;
			for (int j = 1; j<N; j++)
			{
				if (comp[j] > n)
				{
					n = comp[j];
					max_num = j;
				}
			}
			cout << "The highest number of sold computers is " 
				 << n << ". It was sold by " << salespers[max_num];
			n = comp[0];
			int min_num = 0;
			for (int j = 1; j != N; j++)
			{
				if (comp[j] < n)
				{
					n = comp[j];
					min_num = j;
				}
			}
			cout << "\nThe lowest number of sold computers is " 
				 << n << ". It was sold by " << salespers[min_num];
			char c;
			do
			{
				cout << "\nDo you want to search the amount of sold computers by the salesperson - y/n(Yes or No):";
				cin >> c;
				string name;
				bool find = false;
				if (c == 'y'||c=='Y')
				{
					cout << "Please, enter the name of salesperson: ";
					cin >> name;
					int count;
					for (int j = 0; j < 5; j++)
					{
						if (salespers[j] == name)
						{
							count = comp[j];
							find = true;
						}
					}
					if (!find)cout << name << " is not exist!";
					else
					{
						cout << name << " sold " << count << " computers";
					}
				}
			} while (c != 'n'&&c!='N');
			do
			{
				cout << "\Do you want to to start over - y/n(Yes or No):";
				cin >> ch;
				if (ch == 'y' || ch == 'Y')
				{
					i = -1;
					break;
				}
			} while (ch != 'n'&&ch != 'N');
		}	
		i++;
	} while (i < N);
}

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