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.
#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);
}
Comments
Leave a comment