ScholarMatic | 24/7 Homework Help

ScholarMatic Will Help You Write Your Essays and Term Papers

Answered » You can buy a ready-made answer or pick a professional tutor to order an original one.

This is a sorting program that outputs in ascending order.

by | Nov 28, 2023 | engineering

This is a sorting program that outputs in ascending order. It works perfectly except the last input is outputted as 0, please help .

#include <iostream>

#include <fstream>

using namespace std;

void Swapper(double numbers[],int index)

{

  int swapHolder;

  if (numbers[index] > numbers[index+1])

  {

    swapHolder= numbers[index+1];                //how to swap the two numbers

    numbers[index+1]=numbers[index];

    numbers[index]=swapHolder;

  }

}

int main()

{

  ifstream infile;

  ofstream outfile;

  infile.open(“input.txt”);                      //general input file setup

  outfile.open(“output.txt”);

  int thenum=100;

  double numbers[thenum];

  int count;

  int numofnum;

  int swapHolder= -1;

  count = 0;

  while (!infile.eof()){

    infile >> numbers[count];                    //getting data from file stored into the array

    count ++;

  }

  numofnum= count;

  int ending= numofnum;

  int length= numofnum;

  for (int counter = length -1; counter > 0; counter–)         //repeating loop so that it does not stop after one swoop but goes back and run the swoop verification again

  {

    for ( int index = 0; index < ending -1; index ++)           //repeating loop until the entered array number reaches the final swap

    {

      Swapper(numbers,index);

    }

    ending–;

                              //as the highest number is now at the end there is no need to compare until the last number anymore, just go one less

  }

  for (int index=0; index < numofnum; index ++)              //displaying output of each stored array place

  {

    cout<< numbers[index] <<endl;

  }

}

ScholarMatic: Explanation & Answer

Your ready answer from a verified tutor is just a click away for as little as $14.99


  

Click Order Now to get 100% Original Answer Customized to your instructions!

HOME TO CERTIFIED WRITERS

Why Place An Order With Us?

  • Certified Editors
  • 24/7 Customer Support
  • Profesional Research
  • Easy to Use System Interface
  • Student Friendly Pricing

Have a similar question?

PLAGIRAISM FREE PAPERS

All papers we provide are well-researched, properly formatted and cited.

TOP QUALITY

All papers we provide are well-researched, properly formatted and cited.

HIGHLY SECURED

All papers we provide are well-researched, properly formatted and cited.

ScholarMatic: Get Started

Assignment Writing Service

Feel safe and secure when placing an order on our portal!
Fruitful cooperation begins with solid guarantees, and we are professional enough to promise perfect results. Let’s get it started!