Click here to Skip to main content
15,904,348 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: scale in perfmon tool Pin
Maximilien3-Feb-08 3:15
Maximilien3-Feb-08 3:15 
GeneralRe: scale in perfmon tool Pin
George_George3-Feb-08 13:52
George_George3-Feb-08 13:52 
Generalsocket select problem Pin
hanlei00000000092-Feb-08 20:12
hanlei00000000092-Feb-08 20:12 
GeneralRe: socket select problem Pin
Mark Salsbery3-Feb-08 7:53
Mark Salsbery3-Feb-08 7:53 
GeneralAccessinng the Registry of a Remote Computer Pin
Bram van Kampen2-Feb-08 17:53
Bram van Kampen2-Feb-08 17:53 
GeneralRe: Accessinng the Registry of a Remote Computer Pin
Haroon Sarwar2-Feb-08 19:29
Haroon Sarwar2-Feb-08 19:29 
GeneralRe: Accessinng the Registry of a Remote Computer Pin
CString(0xcccccccc)4-Feb-08 4:18
CString(0xcccccccc)4-Feb-08 4:18 
QuestionProblems entering numbers into an Array & doing Bubble Sort & Selection Sort Pin
Laura Sullivan2-Feb-08 17:32
Laura Sullivan2-Feb-08 17:32 
I'm working on setting up a menu to choose which type of sort is wanted, as well as how many numbers in the array, and the numbers for the array.
Trying to figure out how to get my values into the array isn't going according to the examples in the book. I could really use help!
I've pasted my code below.
Thank you!

#include <iostream>;
using namespace std;

// Function prototypes
void selectionSort(int [], int);
void showArray(int [], int);
void sortArray(int [], int);
void showMenu ();
void displayName();
void numberOfValues(int);
void enterValues(int);

int main()
{
int choice; // To hold a menu choice

// Find out the type of sort wanted
do
{
// Display the menu and get the user's choice.
showMenu();
cin >> choice;
if (choice != 3)
{
if (choice = 1)
numberOfValues(int numbers);
enterValues();
sortArray(int [], int);
else if (choice = 2)
numberOfValues(numbers);
enterValues();
selectionSort();
}
}
}while (choice !=3);
Return 0;
}
}
//**************************************************************
// Definition of function selectionSort. *
// This function performs an ascending order selection sort on *
// array. size is the number of elements in the array. *
//**************************************************************

void selectionSort(int array[], int size)
{
// Display the values.
cout << "The unsorted values before the first selection pass are:\n";
cout << "\t\t\t ";
showArray(values, SIZE);

int startScan, minIndex, minValue;
int x = 1;
for (startScan = 0; startScan < (size - 1); startScan++)
{
minIndex = startScan;
minValue = array[startScan];
for(int index = startScan + 1; index < size; index++)
{
if (array[index] < minValue)
{
minValue = array[index];
minIndex = index;
}
}
array[minIndex] = array[startScan];
array[startScan] = minValue;
cout << "After pass #" << x << " the values are ";
showArray(array, index);
x = x + 1;
// Display the values again.
cout << "The final sorted values for this selection sort are:\n";
cout << "\t\t\t ";
showArray(array, SIZE);
}
// Display the values.
cout << "The unsorted values before the first bubble pass are:\n";
cout << "\t\t\t ";
showArray(array, SIZE);

sortArray(array, SIZE);// Sort the values.

// Display them again.
cout << "The final sorted values for this bubble sort are:\n";
cout << "\t\t\t ";
showArray(array, SIZE);
//return 0;
}
//***********************************************************
// Definition of function sortArray *
// This function performs an ascending order bubble sort on *
// array. size is the number of elements in the array. *
//***********************************************************

void sortArray(int array[], int size)
{
bool swap;
int temp;
int x = 1;

do
{
swap = false;
for (int count = 0; count < (size - 1); count++)
{
if (array[count] > array[count + 1])
{
temp = array[count];
array[count] = array[count + 1];
array[count + 1] = temp;
swap = true;
}
}
cout << "After pass #" << x << " the values are ";
showArray(array, 6);
x = x + 1;
} while (swap);
}

//*************************************************************
// Definition of function showArray. *
// This function displays the contents of array. size is the *
// number of elements. *
//*************************************************************

void showArray(int array[], int size)
{
for (int count = 0; count < size; count++)
cout << array[count] << " ";
cout << endl;

}
void showMenu ()//choose type of sort to do
{
cout << "What would you like to do?\n";
cout << "\t1\tBubble Sort\n";
cout << "\t2\tSelection Sort\n";
cout << "\t3\tQuit\n";
cout << "Enter your selection:\n";
cin >> selection;
}
void displayName()
{
cout << "This program was created by Laura Sullivan.\n";
}
void numberOfValues(int numbers)
{
int numbers; //size of array
cout << " How many values do you want in the array (enter 6, 7, 8, 9 only):\n";
cin >> numbers;
}
void enterValues()
{
int numbers; //size of array
const int SIZE = numbers;
int values[SIZE] = {numbers};
cout << "Enter your values (0 through 9), with a space between each value:\n";
cin >> values[numbers];
}
QuestionRe: Problems entering numbers into an Array & doing Bubble Sort & Selection Sort Pin
CPallini3-Feb-08 2:39
mveCPallini3-Feb-08 2:39 
GeneralHelp with a simple Paint clone in Win32 Pin
Lord Kixdemp2-Feb-08 9:59
Lord Kixdemp2-Feb-08 9:59 
GeneralRe: Help with a simple Paint clone in Win32 Pin
CPallini2-Feb-08 11:11
mveCPallini2-Feb-08 11:11 
GeneralRe: Help with a simple Paint clone in Win32 Pin
Lord Kixdemp2-Feb-08 14:16
Lord Kixdemp2-Feb-08 14:16 
QuestionSVG window Pin
neilsolent2-Feb-08 8:27
neilsolent2-Feb-08 8:27 
GeneralRe: SVG window Pin
Gary R. Wheeler3-Feb-08 0:51
Gary R. Wheeler3-Feb-08 0:51 
GeneralRe: SVG window Pin
neilsolent3-Feb-08 6:29
neilsolent3-Feb-08 6:29 
QuestionProblem with Doc-View Application Pin
Member 4431372-Feb-08 7:30
Member 4431372-Feb-08 7:30 
GeneralWell in debug version, but not in release version [Updated] [modified] Pin
followait2-Feb-08 6:50
followait2-Feb-08 6:50 
GeneralRe: Well in debug version, but not in release version [Updated] Pin
Mr. Surprise2-Feb-08 7:11
Mr. Surprise2-Feb-08 7:11 
GeneralRe: Well in debug version, but not in release version [Updated] Pin
followait2-Feb-08 21:52
followait2-Feb-08 21:52 
GeneralRe: Well in debug version, but not in release version [Updated] Pin
followait2-Feb-08 22:14
followait2-Feb-08 22:14 
GeneralRe: Well in debug version, but not in release version [Updated] Pin
Mr. Surprise3-Feb-08 1:42
Mr. Surprise3-Feb-08 1:42 
GeneralRe: Well in debug version, but not in release version [Updated] Pin
followait3-Feb-08 2:09
followait3-Feb-08 2:09 
GeneralHelp - need download location for Visual studio 6 Pin
rajas2-Feb-08 4:29
rajas2-Feb-08 4:29 
JokeRe: Help - need download location for Visual studio 6 Pin
Johpoke2-Feb-08 7:28
Johpoke2-Feb-08 7:28 
GeneralRe: Help - need download location for Visual studio 6 Pin
Mark Salsbery2-Feb-08 7:46
Mark Salsbery2-Feb-08 7:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.