sorting

L

littlegirl

hi guys how would i sort this in ascending order im not understandin
the *Pt

// This program Enter test scores and sort them in oder and Average
the

#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 memor

// Get the Test Score
cout << "Enter each students test scores.\n"
for (count = 0; count < TestScores; count++

cout << "Student " << (count + 1) <
": "
cin >> score[count]


// Calculate the total Score
for (count = 0; count < TestScores; count++

total += score[count]


// Calculate the average Test Score
average = total / TestScores

// Display the result
cout << fixed << showpoint << setprecision(2)

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

// Free dynamically allocated memor
delete [] score

return 0
 
R

Rolf Magnus

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

What are you not understanding about pointers?
To sort the array, you can use std::sort from the <algorithm> header. It
takes iterators (which is just a regular pointer for arrays) to the first
and one past the last element of the sequence to be sorted.
// 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;

This is quite a confusing way of defining those variables. It's considered
bad style. Write each one in its own line.

Btw: It's good practice to define local variables just where they are needed
for the first time, not all at the beginning of the function.
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;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,832
Latest member
UtaHetrick

Latest Threads

Top