-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ4.cpp
63 lines (59 loc) · 1.79 KB
/
Q4.cpp
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
/*
* Phone Number List
*
* Write a program that has an array of at
* least 10 string objects that hold people’s
* names and phone numbers. You may make up
* your own strings, or use the following:
*
* "Alejandra Cruz, 555-1223"
* "Joe Looney, 555-0097"
* "Geri Palmer, 555-8787"
* "Li Chen, 555-1212"
* "Holly Gaddis, 555-8878"
* "Sam Wiggins, 555-0998"
* "Bob Kain, 555-8712"
* "Tim Haynes, 555-7676"
* "Warren Gaddis, 555-9037"
* "Jean James, 555-4939"
* "Ron Palmer, 555-2783"
*
* The program should ask the user to enter a name
* or partial name to search for in the array.
* Any entries in the array that match the string
* entered should be displayed. For example, if
* the user enters “Palmer” the program should
* display the following names from the list:
*
* Geri Palmer, 555-8787
* Ron Palmer, 555-2783
*
**/
#include <iostream>
using namespace std;
int main()
{
int ARRAY_SIZE = 11;
string users[] = { "Alejandra Cruz, 555-1223",
"Joe Looney, 555-0097",
"Geri Palmer, 555-8787",
"Li Chen, 555-1212",
"Holly Gaddis, 555-8878",
"Sam Wiggins, 555-0998",
"Bob Kain, 555-8712",
"Tim Haynes, 555-7676",
"Warren Gaddis, 555-9037",
"Jean James, 555-4939",
"Ron Palmer, 555-2783" };
string user_string;
cout << "Enter a name to search for: ";
getline(cin, user_string);
for (int i = 0; i < ARRAY_SIZE; i++)
{
if (users[i].find(user_string, 0) < users[i].size())
{
cout << users[i].find(user_string, 0) << endl;
cout << users[i] << endl;
}
}
}