topfive.cpp 641 B

12345678910111213141516171819202122232425262728
  1. // topfive.cpp -- handling an array of string objects
  2. #include <iostream>
  3. #include <string>
  4. using namespace std;
  5. const int SIZE = 5;
  6. void display(const string sa[], int n);
  7. int main()
  8. {
  9. string list[SIZE]; // an array holding 5 string object
  10. cout << "Enter your " << SIZE << " favorite astronomical sights:\n";
  11. for (int i = 0; i < SIZE; i++)
  12. {
  13. cout << i + 1 << ": ";
  14. getline(cin,list[i]);
  15. }
  16. cout << "Your list:\n";
  17. display(list, SIZE);
  18. // cin.get();
  19. return 0;
  20. }
  21. void display(const string sa[], int n)
  22. {
  23. for (int i = 0; i < n; i++)
  24. cout << i + 1 << ": " << sa[i] << endl;
  25. }