#include #include using namespace std; int Find (string s, char c) { /* return position of the first instance of c, or the length of the string if isn't there */ int pos; for (pos = 0; pos < (int)s.size(); pos++) { if (s[pos] == c) { return pos; } } return pos; // indicates not found } int main () { // insert code here... string firstName, lastName; firstName = "John"; lastName = "Doe"; string reversedName = lastName + ", " + firstName; cout << reversedName << endl; string fruit = "banana"; cout << "length = " << fruit.size() << endl; cout << "first 'n' at location " << fruit.find('n') << endl; cout << "my find, first 'n' at location " << Find(fruit,'n') << endl; cout << "first character = '" << fruit[0] << "'\n"; cout << "last character = '" << fruit[fruit.size()-1] << "'\n"; fruit[2] = 'x'; cout << fruit << endl; cout << "fruit is now \"" << fruit << "\"\n"; cout << "first 'n' now at location " << fruit.find('n') << endl; /* cout << "fruit[6] = '" << fruit[6] << "'\n"; cout << "fruit[100] = '" << fruit[100] << "'\n"; cout << "fruit[-6] = '" << fruit[-6] << "'\n"; cout << "fruit.at(-6) = '" << fruit.at(-6) << "'\n"; */ return 0; }