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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
// Test the reverseCopy function
cout << "Reverse \"Bolton\", should see \"notloB\"\n";
reverseCopy(word, words[3], sizeof(word) - 1);
cout << word << endl << endl;
// Test the limit on the reverseCopy function
cout << "Reverse \"cytogeneticists\", should see \"tsicitenegotyc\"\n";
reverseCopy(word, "cytogeneticists", sizeof(word) - 1);;
cout << word << endl << endl;
cout << "Reverse \"Frida\", change case, and replace 'D' with 'Z', should see \"AZIRf\".\n";
replaceCopy(caseChangeCopy(reverseCopy(word, words[4], sizeof(word) - 1), word, sizeof(word) - 1), word, 'D', 'Z', sizeof(word) - 1);
cout << word << endl << endl;
cout << "Enter your entire name: ";
read(words[5], sizeof(words[5]));
cout << words[5] << endl << endl;
cout << "Reverse your name and change case.\n";
cout << caseChangeCopy(reverseCopy(word, words[5], sizeof(word) - 1), word, sizeof(word) - 1) << endl;
int wait;
cin >> wait;
return 0;
}
// Add your function definitions here
char* copy(char* destination, const char* source, int num)
{
for (int i = 0; i < num; ++i)
{
destination[i] = source[i];
}
destination[num] = '\0';
return destination;
}
char* reverseCopy(char* destination, const char* source, int num)
{
for (int i = 0; i < num; ++i)
{
destination[i] = source[i];
destination[i] = source[num - i - 1];
}
destination[num] = '\0';
return destination;
}
char* caseChangeCopy(char* destination, const char* source, int num)
{
for (int i = 0; i < num; ++i)
{
destination[i] = source[i];
if (islower(source[i]))
{
destination[i] = toupper(source[i]);
}
else if (isupper(source[i]))
{
destination[i] = tolower(source[i]);
}
}
destination[num] = '\0';
return destination;
}
char* replaceCopy(char* destination, const char* source, char target, char replace, int num)
{
for (int i = 0; i < num; ++i)
{
destination[i] = source[i];
if (source[i] == target)
{
destination[i] = replace;
}
}
destination[num] = '\0';
return destination;
}
|