Write a program which consists of four functions called from the main( ). The first function will display the user heading; the second function will prompt the user to fill an array of strings (a two dimensional array of char) with a number of words and indicate the preference for an ascending or descending sort. The third function will perform the desired sort using the Exchange Sorting technique; the last function will output the contents of the sorted array to the screen. All variables should be defined in main ( ) and passed as needed to the other functions. Use a null string (“”) value to terminate data entry in your Input_Words function. This function should also assign a value to a variable (e.g. num_words) that tracks the number of words to be sorted. DO NOT allow the user to input more than the maximum number of words.

Submit a cover sheet, Variable Definition Table, Pseudocode, Source Code Skeleton, Skeleton Complile, Source Code and RUNs (ascending and descending). The RUN should be SIMILAR to the following:

Ordering an Array Using the Exchange Sort

This program will allow the user to enter up to 25 words (<=20 chars) and specify the order of sorting (ascending or descending). The sorted array's contents output to the Screen.

Enter the words as requested, press <enter> in response
to another word to terminate data entry.

Enter Word Number 1 .......... Zebra
Enter Word Number 2 .......... House
Enter Word Number 3 .......... Apple
Enter Word Number 4 .......... Cat
Enter Word Number 5 ..........

Press "A" for Ascending or "D" for Descending ....... A


The Array's Contents in Ascending Order are:

Word Number 1 is Now .......... Apple
Word Number 2 is Now .......... Cat
Word Number 3 is Now .......... House
Word Number 4 is Now .......... Zebra

Write a program which consists of four functions called from the main( ). The first function will display the user heading; the second function will prompt the user to fill an array of strings (a two dimensional array of char) with a number of words and indicate the preference for an ascending or descending sort. The third function will perform the desired sort using the Exchange Sorting technique; the last function will output the contents of the sorted array to the screen. All variables should be defined in main ( ) and passed as needed to the other functions. Use a null string (“”) value to terminate data entry in your Input_Words function. This function should also assign a value to a variable (e.g. num_words) that tracks the number of words to be sorted. DO NOT allow the user to input more than the maximum number of words.

Submit a cover sheet, Variable Definition Table, Pseudocode, Source Code Skeleton, Skeleton Complile, Source Code and RUNs (ascending and descending). The RUN should be SIMILAR to the following:

Ordering an Array Using the Exchange Sort

This program will allow the user to enter up to 25 words (<=20 chars) and specify the order of sorting (ascending or descending). The sorted array's contents output to the Screen.

Enter the words as requested, press <enter> in response
to another word to terminate data entry.

Enter Word Number 1 .......... Zebra
Enter Word Number 2 .......... House
Enter Word Number 3 .......... Apple
Enter Word Number 4 .......... Cat
Enter Word Number 5 ..........

Press "A" for Ascending or "D" for Descending ....... A


The Array's Contents in Ascending Order are:

Word Number 1 is Now .......... Apple
Word Number 2 is Now .......... Cat
Word Number 3 is Now .......... House
Word Number 4 is Now .......... Zebra

People here will help, but no one is going to do this entire assignment for you. You need to ask a specific question.

http://www.daniweb.com/forums/announcement8-2.html

1 down, 3 to go

void displayUserHeading ( void ) {
  // something here
}
int main ( ) {
  displayUserHeading();
  return 0;
}

1 down, 3 to go

void displayUserHeading ( void ) {
  // something here
}
int main ( ) {
  displayUserHeading();
  return 0;
}

Im going to try to use integers so where u typed "something here" would i type in my integers 1-10?

ok nothing is working so far!!!!!! feel like pulling out my hair at the point!

ok nothing is working so far!!!!!! feel like pulling out my hair at the point!

Post what you have so far and we can go from there.

// arrays.cpp : This program will be sorting integers in ascending or descending order.
//

#include "stdafx.h"
#include "arrays.h"
#define MAX_LOADSTRING 100
#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    const int ARRAY_SIZE = 10; // size of array a
    int a[ARRAY_SIZE];

    int temp; // temporary location used to swap array elements

    for (int i = 0; i < ARRAY_SIZE; ++i)
    {
        cout << "Enter value #" << (i + 1) << " ";
        cin >> a[i];
    }

    // bubble sort
    // loop to control number of passes
    for (int k = 0; k < ARRAY_SIZE - 1; ++k)

        // loop to control number of comparisons per pass
        for(int j = 0; j < ARRAY_SIZE - 1; ++j)

            // compare side-by-side elements and swap item
            // if first element is greater than second element
            if(a[j] > a[j+1])
            {
                temp = a[j];
                a[j] = a[j+1];
                a[j+1] = temp;
            }



    cout << "The sorted array in ascending order\n";
    // output sorted array
    for (int p = 0; p < ARRAY_SIZE; ++p)
        cout << "  " << a[p];

    cout << endl;

    _getch ();

    return 0;
}

im not sure what i did but hey im trying as this is my first time writing a program and taking this course. any of your help will be greatly appreciated!!!!! :)

-monika

Edited 3 Years Ago by Dani: Formatting fixed

my first post has the requirments that i needed for this program. heck im not even sure if i met all of them!

my first post has the requirments that i needed for this program. heck im not even sure if i met all of them!

You don't have any functions.

Write a program which consists of four functions called from the main( ). The first function will display the user heading; the second function will prompt the user to fill an array of strings (a two dimensional array of char) with a number of words and indicate the preference for an ascending or descending sort. The third function will perform the desired sort using the Exchange Sorting technique; the last function will output the contents of the sorted array to the screen.

// arrays.cpp : This program will be sorting integers in ascending or descending order.
//

#include "stdafx.h"
#include "arrays.h"
#define MAX_LOADSTRING 100
#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
const int ARRAY_SIZE = 10; // size of array a
int a[ARRAY_SIZE];

int temp; // temporary location used to swap array elements

for (int i = 0; i < ARRAY_SIZE; ++i)
{
cout << "Enter value #" << (i + 1) << " ";
cin >> a[i];
}

// bubble sort
// loop to control number of passes
for (int k = 0; k < ARRAY_SIZE - 1; ++k)

// loop to control number of comparisons per pass
for(int j = 0; j < ARRAY_SIZE - 1; ++j)

// compare side-by-side elements and swap item
// if first element is greater than second element
if(a[j] > a[j+1])
{
temp = a[j];
a[j] = a[j+1];
a[j+1] = temp;
}



cout << "The sorted array in ascending order\n";
// output sorted array
for (int p = 0; p < ARRAY_SIZE; ++p)
cout << " " << a[p];

cout << endl;

_getch ();

return 0;
}

I don't see any code for function 1, the header function. Lines 18 - 22 should be in the second function (filling in the array data). Lines 24 - 38 should be in function 3 (the sort function). Lines 42 - 45 should be in the fourth function (display function). So you need to create these function and create the corrresponding function headers, which I imagine will go in the arrays.h file. You'll call these four functions from main. Decide what parameters each function needs and what they need to return. Comment out the bulk of the function implementation (just give the correct return type), make sure you can call each function successfully from main, and that it compiles and runs. When it does, then start uncommenting the function implementation code.

exactly my point! i have absolutely no clue what im doing and what im missing

#include <iostream>
#include <string>
using namespace std;

void DisplayHeader();
// function 2 declaration
// function 3 declaration
// function 4 declaration


int main ()
{
     // code to declare 2-dimensional char array
     DisplayHeader();
     // call to function 2
     // call to function 3
     // call to function 4
     return 0;
}


void DisplayHeader()
{
     cout << "Ordering an Array Using the Exchange Sort\n\n";
     cout << "This program will allow the user to enter up to 25 words.";
     // cout statements for the rest of the header.
}


// function 2 implementation

// function 3 implementation

// function 4 implementation
}

Read the project specifications carefully several times. Most of your answers of what goes where are answered in there. You'll be referring to it a lot. Start with this skeleton. Get rid of the implementation code you've written so far, at least for now. Start with empty functions that do nothing. The first function is done for you except it's not complete. Add the rest of the cout statements to DisplayHeader(). This function only contains cout statements as far as I can tell. You need to write the specifications for the other functions. Do so one function at a time, compiling after each attempt. Don't move on till it compiles and runs without error.

This article has been dead for over six months. Start a new discussion instead.