please help me with homework almost done

I need help sorting it from lowest to highest but then on the left column still having it say which test it is
here is what I have so far. I am really new at c++ so if you could help me that would be awesome. =)
// compiler directives
#include <iostream>
#include<iomanip>
#include<stdio.h>

using namespace std;

// constant identifiers
const int MAXSIZE = 10;

// function prototypes
void GetData(int TestScoresf[]);
void ComputeAvg(int TestScoresf[],float &Avgf);
void PrintReport(int TestScoresf[],float Avgf);

// main program
int main()
{
// local identifiers
int TestScores[MAXSIZE];
float Avg = 0;
//Input modale
GetData(TestScores);
//processing module
ComputeAvg(TestScores,Avg);
//output module
PrintReport(TestScores,Avg);

system ("PAUSE");
return 0 ;
}//end main

// function definitions
void GetData (int TestScores[ ])
{
for (int i=0; i <MAXSIZE; i++)
{
cout<<"please enter the test score #"<<i+1<<":\t";
cin>>TestScores[i];
}



return;
}

// end GetData

void ComputeAvg( int TestScoresf[],float&Avgf)

{

float sum = 0;
for(int i=0; i <MAXSIZE; i++)
{
sum = sum+ TestScoresf[i];
}
Avgf =(sum)/MAXSIZE;
return;
} //end ComputeAvg

void PrintReport (int TestScoresf[], float Avgf)
{
int temp;
for (int i = 0; i < MAXSIZE; i++)
{
for (int j = i + 1; j < MAXSIZE; j++)
{
if (TestScoresf[j] < TestScoresf[i])
{
temp = TestScoresf[i];
TestScoresf[i] = TestScoresf[j];
TestScoresf[j] = temp;

cout<<setw(23)<<"Test#"<<setw(15)<<"TestScore";
cout<<"\n\n";
for(int i = 0; i <MAXSIZE; i ++)
{
cout<<setw(26)<<i+1<<setw(20)<<TestScoresf[i]<<endl;
}
cout<<"\n\n"<<fixed<<showpoint<<setprecision(20);
cout<<"test score average:\t"<<Avgf<<endl;

}

// end print Report
void printsorted (int TestScoresf[]);
int temp;
for (int i = 0; i < MAXSIZE; i++)
{
for (int j = i + 1; j < MAXSIZE; j++)
{
if (TestScoresf[j] < TestScoresf[i])
{
temp = TestScoresf[i];
TestScoresf[i] = TestScoresf[j];
TestScoresf[j] = temp;
}
}

{


return ;
cout<<"sorted"<<TestScoresf<<endl;

}
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// compiler directives
#include <iostream>
#include<iomanip>
#include<stdio.h>
#include <algorithm>//added
#include <utility>

using namespace std;

// constant identifiers
const int MAXSIZE = 2;

// function prototypes
void GetData(std::pair<int,int> TestScores[ ]);
void ComputeAvg(std::pair<int,int> TestScores[ ],float &Avgf);
void PrintReport(std::pair<int,int> TestScores[ ],float Avgf);
bool pred(std::pair<int,int> i, std::pair<int,int> j);// needed to sort 

// main program
int main()
{
	// local identifiers
	std::pair<int,int> TestScores[MAXSIZE];
	float Avg = 0;
	//Input modale
	GetData(TestScores);
	//processing module
	ComputeAvg(TestScores,Avg);
	//output module
	PrintReport(TestScores,Avg);

	std::pair<int,float> h[10];


	system ("PAUSE");
	return 0 ;
}//end main

// function definitions
void GetData (std::pair<int,int> TestScores[ ])
{
	for (int i=0; i <MAXSIZE; i++)
	{
		int t;
		cout<<"please enter the test score #"<<i+1<<":\t";
		cin>>t;
		TestScores[i] = std::pair<int,int>(i+1,t);
	}
	return;
}

// end GetData

void ComputeAvg( std::pair<int,int> TestScores[ ],float&Avgf)
{
	float sum = 0;
	for(int i=0; i <MAXSIZE; i++)
	{
		sum = sum + TestScores[i].second;
	}
	Avgf =(float)(sum)/MAXSIZE;
	return;
} //end ComputeAvg

void PrintReport (std::pair<int,int> TestScores[ ], float Avgf)
{
// std::sort algorithm function : sort a range of elements using the pred function to compare
	std::sort(TestScores,TestScores+MAXSIZE,pred); 

	cout<<setw(23)<<"Test#"<<setw(15)<<"TestScore";
	cout<<"\n\n";

	for(int i = 0; i <MAXSIZE; i ++)
	{ 
		cout<<setw(26)<<TestScores[i].first<<setw(20)<<TestScores[i].second<<endl;
	}
	cout<<"\n\n"<<"test score average:\t"<<setprecision(3)<<Avgf<<endl;

		
}
bool pred(std::pair<int,int> i, std::pair<int,int> j)
{
	return  i.second < j.second;
}
Last edited on
Topic archived. No new replies allowed.