Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Write the program in C++ language using simple terms that can be understo

ID: 3716986 • Letter: P

Question

Please Write the program in C++ language using simple terms that can be understood by beginners. Thank you!?

PLEASE DON'T GOOGLE IT !!

( IMPORTANT: Use a text file "contacts.txt" as an input to populate the string array )?

18. 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" Programming Challenges 611 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 from the list: Geri Palmer, 555-8787 example, if the user enters "Palmer" the program should display the following names Ron Palmer, 555-2783

Explanation / Answer

Please find the code below with detailed inline comments.

#include <iostream>
#include <string>
#include <fstream>
#define SIZE 100

using namespace std;

int main() {
ifstream inFile;
  
string contacts[SIZE];
int k=0;
  
inFile.open("contacts.txt");
string str;
  
if (!inFile) {
cout << "Unable to open file";
exit(1); // terminate with error
}
  
while (inFile >> str) {
if(k >= 100) {
cout << "Maximum size exceeded...";
} else {
contacts[k ++] = str;
}
}
  
string input;
  
cout << "Enter a string to be searched: ";
getline(cin, input);
  
for(int i=0; i<k; i++) {
if (contacts[i].find(input) != string::npos) {
cout << contacts[i] << endl;
}
}
inFile.close();
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote