Armenian Knowledge Base  

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

Reply
 
LinkBack Thread Tools
Old 12.04.2006, 03:59   #1
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 36
Posts: 15
Downloads: 0
Uploads: 0
Reputation: 0 | 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;
}
Reply With Quote
Old 12.04.2006, 09:58   #2
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 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;
			}

Last edited by Silver; 12.04.2006 at 11:31.
Reply With Quote
Old 12.04.2006, 11:12   #3
The splendid
 
AvDav's Avatar
 
Join Date: 07 2004
Location: Universe
Age: 36
Posts: 3,413
Downloads: 22
Uploads: 0
Reputation: 222 | 3
Default ba hla [email protected] :)

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.
Reply With Quote
Old 12.04.2006, 11:39   #4
Easy rider
 
Silver's Avatar
 
Join Date: 11 2005
Location: tristeza
Age: 32
Posts: 1,082
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default Re: sorting

AvDav++
Reply With Quote
Old 13.04.2006, 01:43   #5
Младенец
 
imjustagirl's Avatar
 
Join Date: 03 2006
Location: san fan
Age: 36
Posts: 15
Downloads: 0
Uploads: 0
Reputation: 0 | 0
Default Re: sorting

how would i got about displaying the sort ?
Reply With Quote
Old 13.04.2006, 04:02   #6
Грустно...
 
Agregat's Avatar
 
Join Date: 08 2002
Location: Там, где всегда идут дожди
Age: 35
Posts: 21,717
Downloads: 2
Uploads: 0
Reputation: 250 | 8
Default Re: sorting

Проверка на деление на ноль обязательбна
Reply With Quote
Sponsored Links
Reply

Thread Tools


На правах рекламы:
реклама

All times are GMT. The time now is 13:57.


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