Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. In man(), define an integer pointer variable, and use this pointer and new to

ID: 3610568 • Letter: 1

Question

1.   In man(), define an integerpointer variable, and use this pointer andnew to dynamically allocate an integer array with10 elements. Then generate 10 random numbers in range (0, 99)using rand() and assign them to the array elements. Use loopto calculate the sum and averageof all these numbers, and output the results. Note that atthe end of the program, you need to use delete todeallocate the array memory. 2.   Define a struct workerwhich has two properties: id andwage. id is in integer type, and wage is in thedouble type. Create an array with 6 elements usingworker in main(), and assign the workers' ids from1 to 6, and assign the 6 workers' wage from 1100 to 1600; thendefine a new function and pass the worker array to it. In thefunction, you will double the workers' wage. Finally, inmain(), output the workers' new wage results. Note: It's required to modify the workers' wage in a newfunction other than main(). 1.   In man(), define an integerpointer variable, and use this pointer andnew to dynamically allocate an integer array with10 elements. Then generate 10 random numbers in range (0, 99)using rand() and assign them to the array elements. Use loopto calculate the sum and averageof all these numbers, and output the results. Note that atthe end of the program, you need to use delete todeallocate the array memory. 2.   Define a struct workerwhich has two properties: id andwage. id is in integer type, and wage is in thedouble type. Create an array with 6 elements usingworker in main(), and assign the workers' ids from1 to 6, and assign the 6 workers' wage from 1100 to 1600; thendefine a new function and pass the worker array to it. In thefunction, you will double the workers' wage. Finally, inmain(), output the workers' new wage results. Note: It's required to modify the workers' wage in a newfunction other than main().

Explanation / Answer

#include<iostream>
using namespace std;

int main(){
    double sum=0,avg;
    int *ptr;
    ptr =new int[10];
    int i;
   
    for(i=0;i<10;i++)
    ptr[i] =rand() %100;
   
    for(i=0;i<10;i++)
    sum += ptr[i];
   
    avg = sum/10;
    cout<<"Sum is:"<<sum<<endl;
    cout<<"Averageis:"<<avg<<endl;
    delete []ptr;
    system("pause");
}