Code:
//******************************************************************
// Activity program
// This program outputs the phone number for a given name,
//if the name is found in a file
//******************************************************************
#include <iostream>
using namespace std;
void GetFirstName and GetLastName( string, string) // Function prototypes
void PrintPhoneNumber (int )
void PrintQuestion (char)
int main()
{
string FirstName; // The outside temperature
string LastName;
int PhoneNumber
char question;
GetFirstName and GetLastName(FirstName,LastName); // Function call
PrintPhoneNumber(PhoneNumber);
PrintQuestion(question); // Function call
// Declare and open input file
ifstream inData; // Input file of readings
inData.open("phonedir.dat");
if ( !inData ) // Did input file open correctly?
{ // no
cout << "Can't open input file." << endl;
return 1; // Terminate program
}
return 0;
}
//******************************************************************
void GetFirstName and GetLastName ( string FirstName, string LastName ) // Reference parameter
// This function prompts for a first name and last name to be entered
{
cout << "Enter first name" << endl;
cin >> FirstName;
cout << "Enter Last name " << endl;
cin >> LastName;
}
//******************************************************************
void Printphonenumber( string PhoneNumber ) // Value parameter
// This Function outputs the corresponding number or indicates that the name
// is not in the directory.
if the first and last name are found in the file, then output corresponding number.
else
cout << "The name could not be found in the directory
//*******************************************************************
void (PrintQuestion) (char)
//This function prints a question asking the user to find another number.
//If no, terminate program.
cout << "Do you want to lookup another number? (Enter Y or N)" <<
cin >> question;
if (question == 'Y')
//repeat process
{
GetFirstName and GetLastName(FirstName,LastName); // Function call
PrintPhoneNumber(PhoneNumber);
}
if (question== 'N')
return 1; //Terminate Program