# include <iostream>
# include <cstdlib>
# include <ctime>
# include “string1.h”
using namespace std;
const int arSize = 10;
const int maxLen = 81;
int main(){
String name;
cout << “Hi,what’s your name?\n>>”;
cin >> name;
cout << name << “, please enter up to ” << arSize
<< ” short sayings <empty line to quit>:\n”;
String sayings[arSize];
char temp[maxLen];
int i;
for (i = 0; i < arSize; i++){
cout << i + 1 << “: “;
cin.get(temp, maxLen);
while (cin && cin.get() != ‘\n’)
continue;
if (!cin || temp[0])
break;
else
sayings[i] = temp;
}
int total = i;
if (total > 0){
cout << “Here are your sayings:\n”;
for (i = 0; i < total; i++)
cout << sayings[i] << “\n”;
//use pointers to keep track of shortest ,first strings
String* shortest = &sayings[0]; //initialize to first object
String* first = &sayings[0];
for (i = 1; i < total; i++){
if (sayings[i].length() < shortest->length())
shortest = &sayings[0];
if (sayings[i] < *first)
first = &sayings[i];
}
cout << “Shortest sayin:\n” << *shortest << endl;
cout << “First alphabetically:\n” << *first << endl;
srand(time(0));
int choice = rand() % total; //pick index at random
String* favorite = new String(sayings[choice]);
cout << “My favorite saying:\n” << *favorite << endl;
delete favorite;
}
else
cout << “Not much to say,eh?\n”;
cout << “Bye.\n”;
return 0;
}