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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
#include <iostream>
using namespace std;
// constant
const int size = 10;
// function prototype
void initialize (char text [size], int& current);
void move (int& current, int distance);
void insert (char text [size], int& current, char ch);
void replace (char text [size], int& current, char ch);
void print (char text [size], int& current);
int main()
{
char text [size];
int function;
int current;
int distance;
char ch;
//Calls the functions
initialize (text, current);
move (current, distance);
insert (text, current, ch);
replace (text, current, ch);
print (text, current);
while (function != 'q')
{
cout << "Enter p (print) , m (move) , i (insert) , r (replace) or q (quit): ";
cin >> function;
if (function == 'm')
{
cout << "How far do you want to move? ";
cin >> distance ;
cout << "Current index changed to :" << current << endl;
}
if (function == 'p')
{
cout << "The current array is :" << text << endl;
}
if (function == 'i')
{
cout << "Enter the charactter to insert :";
cin >> ch;
cout << "Character" << ch << "placed at index " << current << endl;
}
if (function == 'r')
{
cout << "Enter the character to replace :";
cin >> ch;
cout << "Character" << ch << "placed at index " << current << endl;
}
}
system("PAUSE");
return 0;
}
void initialize (char text [size], int& current)
{
current = 0;
int z;
for (z = 0; z < size; z++)
text [z] = '*';
}
void move (int& current, int distance)
{
if (distance < size)
cout << "Current index changed to: " << current << endl;
else if (distance - current > size)
cout << "Error Outside of Boundary " << distance << endl;
}
void insert (char text [size], int& current, char ch)
{
int i;
for( i - size; i > current; i --)
{
text [i] = text[i--];
text[current] = ch;
}
}
void replace (char text [size], int& current, char ch)
{
text [current] =ch;
cout << "Character" << ch << "placed at index " << current << endl;
current++;
}
void print (char text [size], int current)
{
int z;
for (z = 0; z < size; z++)
cout << text [z] << " ";
}
|