– Assignment: Read book of “CppEssentials.pdf” chapter 5 pages... – Do the following exercises (taken from “exercises” page...

advertisement
–
Assignment: Read book of “CppEssentials.pdf” chapter 5 pages 65 until 79.
–
Do the following exercises (taken from “exercises” page 80 of book “CppEssentials.pdf”):
1. Define a function to input a list of names and store them as dynamicallyallocated strings in an array, and a function to output them:
void ReadNames (char *names[], const int size);
void WriteNames (char *names[], const int size);
Write another function which sorts the list using bubble sort:
void BubbleSort(char *names[], const int size);
Bubble sort involves repeated scans of the list, where during each scan adjacent
items are compared and swapped if out of order. A scan that involves no
swapping indicates that the list is sorted.
2. Rewrite the following function using pointer arithmetic:
char* ReverseString (char *str)
{
int len = strlen(str);
char *result = new char[len + 1];
for (register I = 0; I < len; ++i)
result[i] = str[len – i – 1];
result[len] = ‘\0’;
return result;
}
Download