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 81 82 83 84 85 86 87 88
|
#include <iostream>
#include <conio.h>
#include <string>
using namespace std;
void searchString(char[], char);
void modString(char[], int, char);
void firstDisplay(char[], unsigned int);
void lastDisplay(char[], unsigned int);
void first_lastDisplay(char[], unsigned int, unsigned int);
void null_Str(char[]);
int main()
{
int index_position, first_index, last_index;
char selection, key;
char str[50];
do{
cout << "Please enter a string: ";
cin.getline(str, 50);
cout << "Your string reads: " << str << endl;
cout << "\nMake your selection: ";
cout << "\n1. Search for a character in the string";
cout << "\n2. Change a character within the string";
cout << "\n3. Display the first n characters of the string";
cout << "\n4. Display the last n character of the string";
cout << "\n5. Display all characters that lie between two given indices";
cout << "\n6. Null the string";
cout << "\n7. Exit";
cout << "\nYour selection: ";
cin >> selection;
if (selection == '1')
{
cout << "\nPlease enter a character to serach for: ";
cin >> key;
searchString(str, key);
}
else if (selection == '2')
{
cout << "\nWhat is the index of the character you want to chage? ";
cin >> index_position;
cout << "What character do you want in that position? ";
cin >> key;
modString(str, index_position, key);
}
else if (selection == '3')
{
cout << "\nHow many characters from the beginning of the string do you want to display? ";
cin >> first_index;
firstDisplay(str, first_index);
}
else if (selection == '4')
{
cout << "\nHow many characters from the end of the string do you want to display? ";
cin >> last_index;
lastDisplay(str, last_index);
}
else if (selection == '5')
{
cout << "\nPlease enter the beginning index: ";
cin >> first_index;
cout << "\nPlease enter the end index: ";
cin >> last_index;
first_lastDisplay(str, first_index, last_index);
}
else if (selection == '6')
{
null_Str(str);
}
}while (selection != '7');
if (selection == '7')
cout << "\nPress any key to continue.";
_getch();
return 0;
}
void functions below but i don't think it will be necessary.
|