* So i got this 2 questions, homework in school i got to cout what it asks, but my professor says i did not follow all the instructions: I should mention i'm a newbie to c++ and also to this language, English.
Does anyone have a similar code to this questions ? My professor said that i did not write the function. and that for the second question i did not use it as if it was 2D. Please Help!! i have a test tomorrow on this.
1) Write a Function that will return the average salary in a file of Data records. The Function will receive the file name as string and check if the file does not exist, return -1 otherwise return the average salary. (Do Not write the complete program)
struct Data { char name[20]; double Salary; int age; } // In this order
2) Create a function that will find and return the mean of an M by N, 2 dimensional integer array. The function receives no arguments and will randomly set N and M from 1-10. It will create the 2 dimensional array and randomly initialize it with values from 3-55. (Assume all headers are Included)
1 2 3 4
//also not sure if 2D is like this on an array
int a[N*M];
M = srand()%53 + 3;
M = srand()%53 + 3;
so in other words what i had to do is write them as prototypes so not inside main? is that what the question is asking me to do. Thanks man by the way you are the man. save my life. lol
One more question if you dont mind, Why use signed or unsigned ? my professor has not explained that yet but i would like to know from a wise person like you.
int getMean(void)
{
srand(time(NULL));
int M = 1 + rand()% 10;
int N = 1 + rand()% 10;
int mean = 0;
unsignedint ** Array = newunsignedint * [M];
for(unsignedint i = 0 ; i < M ; ++i)
{
Array[i] = newunsignedint[N];
for(unsignedint j = 0; i < N ; ++j)
{
Array[i][j] = 3 + rand()% 53;
// this one does not compile it says: Thread 1: EXC_BAD_ACCESS
}
}
for(int i = 0 ; i < M ; ++i)
delete[] Array[i];
delete[] Array;
//If i put only this without the for loop above would it still delete the array?
return mean;
}