rite a program, which will ask the user how manynames(one word, no spaces)they wish to enter.The programwill then read that many names, store them in a two dimensional array of characters (one row per name), print them in the order they were entered, then sort them in increasing alphabetical order, and print them in sorted order.Thesort will be done without regard to the case of the letters (i.e. case insensitive sort). The printing of each name MUST be done with the characters as they were typed, you cannot change the case.The maximum number of names to be handled will be 20.The maximum number of printable characters in a name is 15.Use a two dimensionalarray to store the names.Create a function to read in all the names.Create a function to do the sort (modify the bubble sort discussed in class and in the text book).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <iostream>
using namespace std;
#include "ReadLine.h"
#include "Bubblesort.h"
void main ()
{
int i;
int NumNames;
char * pName[20][16];
char ** pNames;
cout << "How many names would you like?" << endl;
cin >> NumNames;
cin.ignore();
pNames = new char *[NumNames];
cout << "Enter" << NumNames << "names" << endl;
for (i = 0; i < NumNames; i++)
{
cout << (i + 1) << ") ";
pNames[i] = ReadLine();
}
cout << "\n\tYou entered the following names" << endl;
for (i = 0; i < NumNames; i++)
cout << (i + 1) << ") " << pName[i] << endl;
Bubblesort(pNames[], NumNames);
cout << "Here are your sorted names:" << endl;
for (int i = 0; i < NumNames; i++) {
cout << pNames[i] << " ";
}
cout << endl;
}
| |
Bubblesort.cpp
#include <string.h>
#include "Bubblesort.h"
void Bubblesort(char ** pNames[], int NumNames) {
int i;
char ** temp;
bool IsSorted;
do {
IsSorted = true;
NumNames--;
for (i = 0; i < NumNames; i++)
//Checking for ascending order.
if (pNames[i] > pNames[i + 1]) {
temp = pNames[i];
pNames[i] = pNames[i + 1];
pNames[i + 1] = temp;
IsSorted = false;
}
else;
} while (!IsSorted);
}
Bubblesort.h
#ifndef BUBBLE_SORT_H
#define BUBBLE_SORT_H
void Bubblesort (char ** pNames[], int NumnNames);
#endif
I don't know what is wrong from here
there is an error on 31.