Ace My Grades
Sign In
Sign In
Reset Password
Register
  • Home
  • Tutorials
    • Accounting
    • Business
    • Law
    • Finance
    • Health Care
    • Management
    • Science
    • Political Science
    • Computer Science
  • My Account
  • Contact Us
$24.00 $15.00
Sorting Arrays With String And Integer | Complete Solution
William Thompson
1

Description

Sorting Arrays With String And Integer

Modify the program of Programming Challenge 1 to allow the user to enter name–score pairs. For each student taking a test, the user types a string representing the name of the student, followed by an integer representing the student’s score. Modify both the sorting and average-calculating functions so they take arrays of structures, with each structure containing the name and score of a single student. In traversing the arrays, use pointers rather than array indices.

I have a the first part written. Struggled with the second part and just gave up.

//Test Scores #1
#include <iostream>
#include <iomanip>
using namespace std;

//Prototypes
void arrSelectSort(float *, int);
void showArrPtr(float *, int);
void showAverage(float, int);

int main()

{
float *scores,
total=0.0,
average;
int numScores;

//Number of test scores.
cout << “How many test scores would you like to enter?”;
cin >> numScores;

while (numScores <= 0)
{
cout << “Zero or negative numbers not accepted.n”;
cin >> numScores;
}

scores = new float[numScores];

//Gather test scores
cout << “Enter the test scores below.n”;
for (int count = 0; count < numScores; count++)
{
cout << “Test score #” << ( count + 1 ) << “: “;
cin >> scores[count];
while (scores[count] <= 0)
{
cout << “Zero or negative numbers not accepted.n”;
cout << “Test Score #” << (count + 1) << “: “;
cin >>scores[count];
}
}

//Calculate the total
for (int count = 0; count < numScores; count++)
{
total += scores[count];
}

//sort & display elements of the array pointers
arrSelectSort ( scores, numScores );
cout << “The test scores in ascending order are: n”;
showArrPtr ( scores, numScores );
showAverage( total, numScores );

delete [] scores;

return 0;

}

//Functions
void arrSelectSort(float *array, int size)
{
int scan, minIndex;
float minElem;
for (scan = 0; scan < ( size – 1 ); scan++)
{
minIndex = scan;
minElem = array[scan];
for (int index = scan + 1; index < size; index++)
{
if ( array[index] < minElem)
{
minElem = array[index];
minIndex = index;
}
}
array[minIndex] = array[scan];
array[scan] = minElem;
}
}

void showArrPtr(float *array, int size)
{
for (int count=0; count< size; count++)
cout << array[count] << ” “;
cout << endl;
}

void showAverage(float total, int numScores)
{
float average;
average = total / numScores;
cout << fixed << showpoint << setprecision(2);
cout << “Average Score: ” << average << endl;
}

Take This Course $24.00 $15.00

Lessons

Sorting Arrays With String And Integer | Complete Solution

Take a course to view this content

Related Courses

$25.00 $18.00
CIS 333 | Lab 5 Answers | Complete Solution | Rated A+
William Thompson
3
$25.00 $18.00
CIS 333 | Lab 4 Answers | Complete Solution | Rated A+
William Thompson
3
$25.00 $18.00
CIS 333 | Lab 2 Answers | Complete Solution | Rated A+
William Thompson
4
$30.00 $21.00
CIS 333 | Week 8 Assignment 2 – Identifying Potential Risk, Response and Recovery | Complete Solution | Rated A+
William Thompson
5
Ace My Grades © 2021
  • Home
  • Checkout
  • Blog
  • Privacy Policy
  • Contact Us
  • FAQ