473,395 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Telephone directory help

I am having a bit of trouble writing a function for a telephone directory. I need to create a program that upon prompt of first and last name it needs to output the corresponding number from a dat file or indicates that the name isnt in the file. then after each lookup i need to ask whether to look up another number or exit.

this is the code I have so far, I am not very good with functions so...
[HTML]
#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>

using namespace std;

string number( string first, string last);
void phone(string first, string last, string& phone);

int main()
{

//Declare
string name;
string number;
ifstream phoneIn;
string fname;
string first;
string last;
string phone;
string fullname;
float x;
char s;
string findname;

//Open Input File

phoneIn.open("phone.dat");

if (!phoneIn)
{
cout << "Unable to Open Input File." << endl;
return 1;
}


{
//Prompt for First and Lastname
cout << "Enter Owner's First name or type s or S to exit" <<endl;
cin >> first;
cout << "Enter Owner's Last name or type s or S to exit." << endl;
cin >> last;

findname = first + " " + last;

cout << findname << " Phone Number is: " << number(findname) << endl;
cin.get();
cin.get();
return 0;
}

void phone()
{
while (phoneIn)
{
phoneIn >> first >> last >> number;
fullname = first + " " + last;
cout << fullname << " " << number << endl;
phone[fullname] = number;
}
return;
}



return 0;
}
[/HTML]

thanks in advance
Nov 3 '07 #1
1 2227
weaknessforcats
9,208 Expert Mod 8TB
You call number(findname) but there is no number() function. There is a
phone() function that isn't used.

When you search your data file, out need to re-position to the beginning foe each search otherwise the second search will resume where the first one left off.

I would use cin.getline() to fetch the disc records one at a time. That way you can be certain that the first name and alst name are in the same record. The >> operator does not insure that. All it does is fetch the next item, wherever it is. You might consider opening the file in the phone() function so ti positions to the beginning for each search. Use a return type to indicate a) the file didn;t open, b) the search was successful, c)the search was unsuccessful. The return values can be test in main() where the call was made.

Consider using enums for these return values rather than hard-coded ones.

The phone() function has not arguments so it can't see phoneIn defined in main(). It needs an ifstream& argument.

Post again when you are farther along.
Nov 3 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

383
by: John Bailo | last post by:
The war of the OSes was won a long time ago. Unix has always been, and will continue to be, the Server OS in the form of Linux. Microsoft struggled mightily to win that battle -- creating a...
4
by: Iftikhar Hussain | last post by:
Hello Everyone Nice to be back here, well all u guys have helped in past & now I would like a favor again. first what i want to develop is as follows: An application for rescue station, where...
5
by: yenra | last post by:
Can anyone help me in making this program?!... I need to make a telephone directory using structure definition.. typedef struct AddressTag{ char surname; char givenname; char middleinitial;...
2
by: Compustudent | last post by:
Hi, I am trying to find out if there is a pre written script to submit a query to a telephone directory site (like whitepages.com) and will the bring back just the results and strip away all the...
1
by: Gulcim | last post by:
Hi Please help me! How can I transfer users' telephone numbers from sql database to active directory users properties. Do Anybody know script about it? I have nearly 5000 users in sql database.
0
by: Gulcim | last post by:
Hi Please help me! How can I transfer users' telephone numbers from sql database to active directory users properties. Do Anybody know script about it? I have nearly 5000 users in sql database....
4
by: Pat_RI | last post by:
I need to reformat a cell that contains telephone numbers to a format of (###) ###-#### but the original cells have various symbols such as / . - \ () etc is there a way to replace all of these...
0
by: tlontz | last post by:
I am trying to retrieve the telephone_number from active directory using the following script: Dim search As New DirectorySearcher("") search.Filter =...
5
by: rikigr4 | last post by:
Hi All, I am looking for code written in .NET that provides connection between application and telephone. So that - the telephone will return a code according to input code that it get's from the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.