THIS IS THE PROGRAM TO FIND THE MAX AND MIN USING STRUCTURES, CAN YOU EXPLAIN WHAT TYPEDEF STRUCT MEANS AND WHAT OTHER DECLARATION WE COULD DO FOR A STRUCTURE , PLUS THIS CODE { minmaxst out;
}AND {nmaxst mmstr = findmm(argc-1, x)}
it looks like that program simply sorts the contents of an array, and minmaxst is a buffer, the findmm is the sorting subroutine and the for loop is the sort.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
oh, forgot to answer your question, typedef structure tells the compiler to declare a structure named minmaxst, minmaxst out means to create a minmaxst variable named out, minmaxst mmstr = findmm(argc-1, x) means run the subroutine findmm, with the variables argc - 1, and x, then return the minmaxst
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
THIS IS THE PROGRAM TO FIND THE MAX AND MIN USING STRUCTURES, CAN YOU EXPLAIN WHAT TYPEDEF STRUCT MEANS AND WHAT OTHER DECLARATION WE COULD DO FOR A STRUCTURE , PLUS THIS CODE { minmaxst out;
}AND {nmaxst mmstr = findmm(argc-1, x)}
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
typedef struct {
double *array;
int numberPoints;
double maxValue;
double minValue;
} minmaxst;
minmaxst findmm(int numpoints, double *inArray)
{
minmaxst out;
out.array = new double[numpoints];
out.maxValue = inArray[0];
out.minValue = inArray[0];
out.numberPoints = numpoints;
for (int i = 0; i < numpoints; i++)
{
out.array[i] = inArray[i]; //load up array
if (inArray[i] < out.minValue)
out.minValue = inArray[i];
if (inArray[i] > out.maxValue)
out.maxValue = inArray[i];
}
return out;
}
int main(int argc, char *argv[])
{
if (argc < 3)
return 0;
double *x = new double[argc - 1];
for (int i = 1; i < argc; i++)
x[i-1] = atof(argv[i]);
minmaxst mmstr = findmm(argc-1, x);
cout << mmstr.maxValue << " " << mmstr.minValue << endl;
delete x;
delete mmstr.array;
system ("pause");
return 0;
}
it looks like that program simply sorts the contents of an array, and minmaxst is a buffer, the findmm is the sorting subroutine and the for loop is the sort.
oh, forgot to answer your question, typedef structure tells the compiler to declare a structure named minmaxst, minmaxst out means to create a minmaxst variable named out, minmaxst mmstr = findmm(argc-1, x) means run the subroutine findmm, with the variables argc - 1, and x, then return the minmaxst
thank you very very very much, that really helped me a lot, and thanks for the fast reply