Image

Imagetransmogrify wrote in Imagecpp

arrays

i'm having some trouble with this array program i've been working on. if anyone could provide some help, it would be greatly appreciated.


/*
You are to give statistics about the math SAT score for 19 students. Each SAT score(an integer in the range of 200 to 800) is associated with a student
id number which can be any integer. You can have 2 arrays- one for the score and one for the ids or you can store the data in a 2 dimensional array
with one column indicating scores and another ids. You are to determine
A. the average score
B. the maximum score and the associated id
C. the minimum score and the associated id
D. the number of scores in the 6 groupings of the 200-299 range, 300-399 range, 400-499 range, etc.
E. the score and the associated id of the 10th score in numerical order

You are also required to print the scores with their corresponding id.s in numerical order with the lowest score first. To sort the data write a function
which uses either a selection, insertion or a shell sort. Note each score must have its id.

To generate the scores and ids you might use a random number generator.
An SAT score in the correct range might be generated using
200+rand()%601. */

#include <iostream.h>
#include <stdlib.h>
#include <time.h>

void createArray (int refArray[19][2]);    //prototype for array
double avgScore (int refArray[19][2]);     //prototype for average
void sort (int refArray[19][2]);           //prototype for selection sort
void groupsRange (int refArray[19][2]);    //prototype for ranges
void printList (int refArray[19][2]);      //prototype for cout of array

int main()                          //main

{
	
	int max, min;	
	int student [19][2];
	srand (time(NULL));
	max = student[18][2];
	min = student [0][1];
	cout << student[9][1] << "Got the score of: " << student[9][1] << endl;

	return 0;
}

void createArray (int refArray[19][2])      //function definition to create the array
{
	for(int i=0; i<19; i++)
	refArray [19][1] = 200+rand()%601;
	refArray [19][0] = rand()%5000000;
	
}

double avgScore (int refArray[19][2])      //function definition average
{
	int avg, total = 0;
	for (int i = 0; i<19; i++)
	total += refArray[19][1];
	avg = total / 19;	

return avg;	
}

void sort (int refArray[19][2])     //function definition selection sort
{
	int temp;
	for (int i=0; i<18; i++)
    {
        int minIndex = i;
  
        for (int j=i+1; j<19; j++)
        {
            if (refArray[j] < refArray[minIndex])
            {
                minIndex = j;
            }
        }
    
        if (minIndex > i)
        {
            temp = refArray[i][1];
			refArray[i][1] = refArray[minIndex][1];
			refArray[minIndex][1] = temp;
        }
    }
}

void groupsRange (int refArray[19][2])           //function definition range
{
	int score;
	if (score >= 0 && score <=99)
		cout << refArray [19][2] << endl;
	if (score >= 100 && score <=199)
		cout << refArray [19][2] << endl;
	if (score >= 200 && score <=299)
		cout << refArray [19][2] << endl;
	if (score >= 300 && score <=399)
		cout << refArray [19][2] << endl;
	if (score >= 400 && score <=499)
		cout << refArray [19][2] << endl;
	if (score = 500)
		cout << refArray [19][2] << endl;
}

void printList (int refArray[19][2])        //function definition print array
{

cout << refArray[19][2] << endl;

}



cross-posted in Imagecoders_haven