Question: 0down votefavorite The program, is basically sussposed to iterate a file containing the elements Harry Keeling (202)806-4830 Frank James (301)123-3459 Arthur Paul (202)865-9090 Todd Shurn

0down votefavorite

The program, is basically sussposed to iterate a file containing the elements

Harry Keeling (202)806-4830 Frank James (301)123-3459 Arthur Paul (202)865-9090 Todd Shurn (410)560-8909 Richard Okpala 202 388 410 

what my current program is outputting the phonenumber if firstname and lastname is present in file but if its nothow do i output phone number isnt here my current code.

#include

#include

#include

using namespace std;

void lookup_name(ifstream&, string&, string&, string&); // prototype

int main()

{

ifstream myfile;

string name, lastname, phonenumber;

char choice;

do

{

myfile.open("infile.txt");

cout << "What is the First name? " << endl;

cin >> name;

cout << "what is your last name?" << endl;

cin >> lastname;

lookup_name(myfile, name, lastname, phonenumber);

cout << "Do you want to lookup another name

cin >> choice;

} while (choice == 'Y');

return 0;

}

void lookup_name(ifstream& myfile, string& name, string& lastname, string& phonenumber)

{

string name1, name2, fullname, secondname, dummy;

for (int i = 0; i < 5; i++) {

myfile >> name1 >> name2;

fullname = name1 + name2;

secondname = name + lastname;

if (fullname == secondname) {

myfile >> phonenumber;

cout << phonenumber << endl;

myfile.close();

break;

}

else if (fullname != secondname) {

myfile >> dummy;

phonenumber = dummy;

}

if (dummy == phonenumber) {

cout << "not present"<

myfile.close();

break;

}

}

c++ code

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!