Answer to Question #97126 in C++ for Edwin

Question #97126
A company distributes 10 different items around Nairobi through its 5 salesmen in Nairobi. Using dynamic arrays, write a c++ program to input a salesman and the corresponding sales made by each of the salesman for wach of the item. The program should then
1
Expert's answer
2019-10-23T07:07:07-0400
#include <iostream>
#include <stdlib.h>
#include <time.h>
using namespace std;


int main() {
    srand(time(NULL)); //For generate random price of item each launch of program
    int numOfSalesman = 5;
    int numOfItems = 10;


    //2d array to store salesman's list of items prices as rows. One row for each salesman
    int** salesmansArray = new int*[numOfSalesman];
    for(int i = 0; i < numOfSalesman; i++) {
        salesmansArray[i] = new int[numOfItems];
    }


    //Filling the arrays
    for(int i = 0; i < numOfSalesman; i++) {
        for(int j = 0; j < numOfItems; j++) {
            salesmansArray[i][j] = rand() % 20; //Generating random prices (from 0 to 19)
        }
    }


    //Printing the result
    for(int i = 0; i < numOfSalesman; i++) {
        cout << "salesman " << i << ": ";
        for(int j = 0; j < numOfItems; j++) {
            cout << salesmansArray[i][j] << " ";
        }
        cout << endl;
    }


    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