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;
const int NUM=5;
int main() {
string salesmen[NUM];
int comp[NUM];
char ans;
for (int i=0; i<NUM; i++) {
cout << "Enter a name of the " << i+1 << "-th salesmen: ";
cin >> salesmen[i];
cout << "Enter a number of computers sold by " << salesmen[i] << ": ";
cin >> comp[i];
}
int iMin=0, iMax=0;
for (int i=1; i<NUM; i++) {
if (comp[i] > comp[iMax]) {
iMax = i;
}
if (comp[i] < comp[iMin]) {
iMin = i;
}
}
cout << endl;
cout << "The highest numberer of sold computers is " << comp[iMax] << endl;
cout << "They were sold by " << salesmen[iMax] << endl;
cout << "The lowest numberer of sold computers is " << comp[iMin] << endl;
cout << "They were sold by " << salesmen[iMin] << endl;
do {
int search;
cout << endl << "Enter a number of sold comuters you want to search: ";
cin >> search;
int i;
for (i=0; i<NUM; i++) {
if (comp[i] == search) {
break;
}
}
if (i == NUM) {
cout << "The number does not exist" << endl;
}
else {
cout << "It was done by " << salesmen[i] << endl;
}
cout << endl << "Would you like to repeat (y/N)? ";
cin >> ans;
} while (ans == 'y' || ans == 'Y');
return 0;
}
Comments
Leave a comment