473,799 Members | 2,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Telephone directory help

1 New Member
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("p hone.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 2252
weaknessforcats
9,208 Recognized Expert Moderator Expert
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
12273
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 poor man's DBMS, a broken email server and various other /application/ servers to try and crack the Internet and IS markets. In the case where they didn't spend their own money to get companies to
4
7540
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 there is a Telephone & a Computer System . the telephone is also connected with the computer system, so when the telphone rings, the Computer can act as a CLI & could identify, which number the call is coming from. it gets that number, matches it...
5
8023
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; char telnum; struct PersonTag *next;
2
1699
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 adds/images. Thank You
1
1370
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
890
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. Thank you..
4
1617
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 symbols and then reformat accordingly? Examples of what needs to be corrected: 555-555-1212 555/555-1212 (555)5551212 555.555.1212
0
2867
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 = "(&(objectCategory=Person)(objectClass=user)(!(userAccountControl:1.2.840.113556.1.4.803:=2))(samaccountname=" + UserName.ToString.Trim + "))" 'search.Filter = "(&(!(userAccountControl:1.2.840.113556.1.4.803:=2))( objectCategory=person)(samaccountname=" +...
5
6183
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 user. I'll be happy to get even a little help - if you know something that relate and can help me!! Thanks. http://www.codeproject.com/script/Forums/Images/smiley_wink.gif http://www.codeproject.com/script/Forums/Images/smiley_confused.gif
0
9541
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10482
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10251
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10225
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5463
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.