Skip to main content
0 online
katiedid katiedidFounder

random

#include <>

#include <>
#include "boolean.h">

const char skip = ' ';
const int max_list_size= 5;
const float inputSentinel = -999.0;

void print_greeting();
void get_data(float list[ ], int &length);
void print_list(float list[ ], int length);
void sort_list(float list[ ], int length);
int find_minimum(float list[ ], int first, int length);

void swap(float &x, float &y);
boolean end_of_input(float data);

int main()
{
int length = max_list_size;
float list[max_list_size];

print_greeting();
get_data(list, length);
cout << setw(10) << skip << "Listed numbers: " << endl;
cout << endl;
print_list(list, length);
sort_list(list, length);
cout << setw(10) << skip << "Sorted list: " << endl;
cout << endl;
print_list(list, length);
return 0;
}

void get_data(float list[ ], int &length)
{
int logical_length = 0;
float data;

cout << "Enter a real number (-999 to stop input): ";
cin >> data;

while((logical_length < length) && ! end_of_input(data))
{
list[logical_length] = data;
++logical_length;
cout << "Enter a real number (-999 to stop input): ";
cin >> data;
}
if (! end_of_input(data) && (logical_length == length))
cout << "There is more data." << endl;
length = logical_length;
}

void print_list(float list[ ], int length)
{
cout << endl;
for (int j = 0; j < length; ++j)
cout << setw(12) << skip << '<' << j + 1 << '>' << setw(6)
<< list[j]
<< endl;
}

void sort_list(float list[ ], int length)
{
int min_index = 0;
for (int j=0; j < length - 1; ++j)
{
min_index = find_minimum(list, j, length);
if (min_index !=j)
swap(list[j], list[min_index]);
}
}

int find_minimum(float list[ ], int first, int length)
{
int min_index = first;
for (int j = first + 1; j < length; ++j)
if (list[j] < list[min_index])
min_index = j;
return min_index;
}

void swap(float &x, float &y)
{
float temp = x;
x = y;
y = temp;
}

boolean end_of_input(float data)
{
return data == input_sentinel;
}

katiedid katiedidFounder

after the #include should be "iostream.h" and "inmanip.h" for whatever reason. this may work (doubtful) in case you need something later on. lol.

ok4now ok4nowOG 2002

i swear u must have the same prof! lol...this looks very close to my assignment.

Welcome Back to eZabel

It's been a while. Here's what's new.

eZabel Lore

A complete history of our community — stats, Hall of Fame, legendary threads, and more.

View the Lore →

Everything Preserved

All 225,969 pieces of content from 2000–2014 are here — forums, messages, journals, photos, polls, and events.

💎

Gems

Spot something you love — a legendary comment, a classic thread, a great photo? Log in and click the diamond icon to mark it as a Gem. Add a note about why it's special. The best stuff surfaces on the Gems page.