Skip to content

Commit e6d6c2f

Browse files
committed
add function to handle string
1 parent a3cdf8f commit e6d6c2f

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

topfive.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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];
10+
cout << "Enter your " << SIZE << " favority astronomical sights:\n";
11+
for (int i = 0; i < SIZE; i++) {
12+
cout << i + 1 << ": ";
13+
getline(cin, list[i]);
14+
}
15+
16+
cout << "Your list:\n";
17+
display(list, SIZE);
18+
19+
return 0;
20+
}
21+
22+
void display(const string sa[], int n)
23+
{
24+
for (int i = 0; i < n; i++) {
25+
cout << i + 1 << ": " << sa[i] << endl;
26+
}
27+
}

0 commit comments

Comments
 (0)