Go Back   Armenian Knowledge Base > Technical sections > Languages, Compilers, Interpreters > C/C++

Reply
 
Thread Tools

sorting
Old 12.04.2006, 02:59   #1
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 43
Posts: 15
Rep Power: 0
Default sorting

hi guys how would i sort this in ascending order im not understanding the *Ptr



// This program Enter test scores and sort them in oder and Averages them

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
double *score, total = 0, average;
int TestScores, count;


cout << "How many Test Scroes do you wish to enter ";
cin >> TestScores;
score = new double[TestScores]; // Allocate memory

// Get the Test Scores
cout << "Enter each students test scores.\n";
for (count = 0; count < TestScores; count++)
{
cout << "Student " << (count + 1) << ": ";
cin >> score[count];
}

// Calculate the total Scores
for (count = 0; count < TestScores; count++)
{
total += score[count];
}

// Calculate the average Test Scores
average = total / TestScores;

// Display the results
cout << fixed << showpoint << setprecision(2);

cout << "Average Score: " << average << endl;

// Free dynamically allocated memory
delete [] score;

return 0;
}

Re: sorting
Old 12.04.2006, 08:58   #2
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 40
Posts: 1,082
Rep Power: 0
Default Re: sorting

Code:
	for (int i=0; i<TestScores; ++i)
		for (int j=i; j<TestScores; ++j)
			if (score[i] < score[j])
			{
				double tmpscore = score[i];
				score[i] = score[j];
				score[j] = tmpscore;
			}
__________________
http://sssilver.googlepages.com/blog...ner_300x30.jpg

http://www.hra.am/img/Gulyan1.gif

You must spread before giving to Silver again.

Last edited by Silver; 12.04.2006 at 10:31.

ba hla im@ :)
Old 12.04.2006, 10:12   #3
Ego coder
 
AvDav's Avatar
 
Join Date: 07 2004
Location: Yerevan, Armenia
Age: 44
Posts: 3,738
Rep Power: 5
Default ba hla im@ :)

Code:
std::sort(source, source+TestScores-1);
chtob snyat kamen s dushi i ne pokazatsya prezritelnim v predeleax doljen skazat chto:
p.s.: I have a feeling that bubble sort needs n^2/2 comparisons not n^2.
__________________
Каждый сам кузнец своего счастья, и несчастья тоже.

Re: sorting
Old 12.04.2006, 10:39   #4
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 40
Posts: 1,082
Rep Power: 0
Default Re: sorting

AvDav++
__________________
http://sssilver.googlepages.com/blog...ner_300x30.jpg

http://www.hra.am/img/Gulyan1.gif

You must spread before giving to Silver again.

Re: sorting
Old 13.04.2006, 00:43   #5
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 43
Posts: 15
Rep Power: 0
Default Re: sorting

how would i got about displaying the sort ?

Re: sorting
Old 13.04.2006, 03:02   #6
Грустно...
 
Agregat's Avatar
 
Join Date: 08 2002
Location: Там, где всегда идут дожди
Age: 43
Posts: 21,717
Rep Power: 9
Default Re: sorting

Проверка на деление на ноль обязательбна
__________________
http://аvitya.livejournal.com
Хотели, как лучше, а получилось даже хуже...
Лозунг шахматиста: На каждый шах - ответим матом!
Reply




Реклама:
реклама
Buy text link .

All times are GMT. The time now is 10:15.
Top

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.