Question #36974

Generate an array containing information about the number of items collected by collectors shop this week. The structure type contains the fields: name picker, the number of products it had collected daily nedelnik, Tuesday, etc. Write a program that prints out:
- The name of the collector and the total number of parts, assembled them after week-lu;
- The name of the collector who collected the largest number of products, and the day when he reached the highest productivity.

Expert's answer

#include <iostream>
#include <string>
using namespace std;
const int size = 7;
const string dayOfWeek[size] = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
struct Collector
{
    string name;
    int number[size];
};
int Count(int mas[size]);
int Index(int mas[size]);
int main()
{
    Collector c[3];
    //Input data
    for(int i = 0; i < 3; i++)
    {
        cout << "Input name of the collector" << endl;
        cin >> c[i].name;
        for(int j = 0; j < size; j++)
        {
            cout << "Input number of products: " << dayOfWeek[j] << " = ";
            cin >> c[i].number[j];
        }
        cout << endl;
    }
    cout << "---" << endl;
}
//-------------------------------------------------------------------
//Print the name of the collector and the total number of parts, assembled them after weekly;
for(int i = 0; i < 3; i++)
{
    cout << "Name: " << c[i].name << "  Number: " << Count(c[i].number) << endl;
}
cout << "--------------------------------- " << endl;
//-------------------------------------------------------------------
//Print the name of the collector who collected the largest number of products, and the day
//when he reached the highest productivity.
int max = 0;
string name;
int count = 0;
int index;
for(int i = 0; i < 3; i++)
{
    count = Count(c[i].number);
    if(max < count)
    {
        max = count;
        name = c[i].name;
        index = Index(c[i].number);
    }
}
cout << "Name: " << name << "  Day: " << dayOfWeek[index] << endl;
return 0;
}
int Count(int mas[size])
{
    int count = 0;
    for(int i = 0; i < size; i++)
    {
        count += mas[i];
    }
    return count;
}
int Index(int mas[size])
{
    int index = 0;
    int max = 0;
    for(int i = 0; i < size; i++)
    {
        if(max < mas[i])
        {
            max = mas[i];
            index = i;
        }
    }
    return index;
}

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!

LATEST TUTORIALS
APPROVED BY CLIENTS