No idea how to do this problem...

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 7
Reputation: fivetoesonefoot is an unknown quantity at this point 
Solved Threads: 0
fivetoesonefoot fivetoesonefoot is offline Offline
Newbie Poster

No idea how to do this problem...

 
0
  #1
Nov 9th, 2004
hey i was wondering if someone could help me with this problem. i am so incredibly and utterly confused. here it is...

write a simple phone directory program that looks up phone numbers in a file containing a list of names and phone numbers (called input.txt). the user should be prompted to enter a first and last name and the program then outputs the corresponding number, or indicates that the name isn't in the directory. after each lookup, the program should ask the user whether they want to look up another number, and then either repeat the process or exit the program. the data on the file should be organized so that each line contains a first name, last name and a phone number seperated by blanks.
use functional decomposition to solve th problem and code the solution using functions as appropriate (use a function to get the name from the user and another to check the list to locate the phone number). use appropriate comments.

if someone would help me, i would be GREATLY indebted!!!! please!!!!!

~Megan
Reply With Quote Quick reply to this message  
Join Date: Dec 2003
Posts: 2,414
Reputation: alc6379 has a spectacular aura about alc6379 has a spectacular aura about alc6379 has a spectacular aura about 
Solved Threads: 123
Team Colleague
alc6379's Avatar
alc6379 alc6379 is offline Offline
Cookie... That's it

Re: No idea how to do this problem...

 
0
  #2
Nov 9th, 2004
What part are you stuck on? Do you need help designing it?

Most people here won't write your code for you, but can help you get started with some suggestions. Let us know what you're stuck on, and we'll try to give you a nudge in the right direction...
Alex Cavnar, aka alc6379
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 7
Reputation: fivetoesonefoot is an unknown quantity at this point 
Solved Threads: 0
fivetoesonefoot fivetoesonefoot is offline Offline
Newbie Poster

Re: No idea how to do this problem...

 
0
  #3
Nov 9th, 2004
well i dont know how to make it look @ the names in the list, then find out if they match what's on the list. that's a big problem. i think if i get this figured out i can do the rest....thankies!
if someone would help me, i would be GREATLY indebted!!!! please!!!!!

~Megan[/QUOTE]
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 14
Reputation: Tresa is an unknown quantity at this point 
Solved Threads: 0
Tresa Tresa is offline Offline
Newbie Poster

Re: No idea how to do this problem...

 
-1
  #4
Nov 10th, 2004
here is an example for u!

#include <iostream.h>
#include <fstream.h>
#include <string.h>
#include <iomanip.h>
#include <conio.h>

class phoneBook{
char name[20],phno[6];
public:
void getdata();
void showdata();
char *getname(){ return name; }
char *getphno(){ return phno; }
void update(char *nm,char *telno){
strcpy(name,nm);
strcpy(phno,telno);
}
};

void phoneBook :: getdata(){
cout<<"\nEnter Name : ";
cin>>name;
cout<<"Enter Phone No. : ";
cin>>phno;
}

void phoneBook :: showdata(){
cout<<"\n";
cout<<setw(15)<<name;
cout<<setw(8)<<phno;
}


void main(){
phoneBook rec;
fstream file;
file.open("phone.dat", ios::ate | ios::in | ios::out | ios::binary);
char ch,nm[20],telno[6];
int choice,found=0;
while(1){
clrscr();
cout<<"\n*****Phone Book*****\n";
cout<<"1) Add New Record\n";
cout<<"2) Display All Records\n";
cout<<"3) Search Telephone No.\n";
cout<<"4) Search Person Name\n";
cout<<"5) Update Telephone No.\n";
cout<<"6) Exit\n";
cout<<"Choose your choice : ";
cin>>choice;
switch(choice){
case 1 : //New Record
rec.getdata();
cin.get(ch);
file.write((char *) &rec, sizeof(rec));
break;

case 2 : //Display All Records
file.seekg(0,ios::beg);
cout<<"\n\nRecords in Phone Book\n";
while(file){
file.read((char *) &rec, sizeof(rec));
if(!file.eof())
rec.showdata();
}
file.clear();
getch();
break;

case 3 : //Search Tel. no. when person name is known.
cout<<"\n\nEnter Name : ";
cin>>nm;
file.seekg(0,ios::beg);
found=0;
while(file.read((char *) &rec, sizeof(rec)))
{
if(strcmp(nm,rec.getname())==0)
{
found=1;
rec.showdata();
}
}
file.clear();
if(found==0)
cout<<"\n\n---Record Not found---\n";
getch();
break;

case 4 : //Search name on basis of tel. no
cout<<"\n\nEnter Telephone No : ";
cin>>telno;
file.seekg(0,ios::beg);
found=0;
while(file.read((char *) &rec, sizeof(rec)))
{
if(strcmp(telno,rec.getphno())==0)
{
found=1;
rec.showdata();
}
}
file.clear();
if(found==0)
cout<<"\n\n---Record Not found---\n";
getch();
break;

case 5 : //Update Telephone No.
cout<<"\n\nEnter Name : ";
cin>>nm;
file.seekg(0,ios::beg);
found=0;
int cnt=0;
while(file.read((char *) &rec, sizeof(rec)))
{
cnt++;
if(strcmp(nm,rec.getname())==0)
{
found=1;
break;
}
}
file.clear();
if(found==0)
cout<<"\n\n---Record Not found---\n";
else
{
int location = (cnt-1) * sizeof(rec);
cin.get(ch);
if(file.eof())
file.clear();

cout<<"Enter New Telephone No : ";
cin>>telno;
file.seekp(location);
rec.update(nm,telno);
file.write((char *) &rec, sizeof(rec));
file.flush();
}
break;
case 6 ://Exit
goto out;
}
}
out:
file.close();
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 7
Reputation: fivetoesonefoot is an unknown quantity at this point 
Solved Threads: 0
fivetoesonefoot fivetoesonefoot is offline Offline
Newbie Poster

Re: No idea how to do this problem...

 
0
  #5
Nov 10th, 2004
holy crap....how long did that take you? THANKS SOOOO MUCH!!! i owe you big time, if there is anything you need, ANYTHING ask!! thankies again
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,823
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 748
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: No idea how to do this problem...

 
0
  #6
Nov 11th, 2004
>how long did that take you?
The real question is how long will it take him to realize that doing your homework for you was a mistake.

>i owe you big time
No, you don't. The code you were given would get me fired, and it'll probably get you a bad grade if your teacher has any brain at all.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: No idea how to do this problem...

 
0
  #7
Nov 11th, 2004
now why did you alert him to the fact that he shouldn't just submit that code as his assigment?

Don't we want people who're too lazy to do their own work to get burned?
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,823
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 748
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: No idea how to do this problem...

 
0
  #8
Nov 11th, 2004
>Don't we want people who're too lazy to do their own work to get burned?
I try to avoid such things whenever possible. But you might be a sadistic prick while I'm not. Everyone is different.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: No idea how to do this problem...

 
0
  #9
Nov 11th, 2004
let them burn once so they never burn again. One bad grade won't hurt anything but his pride but he may learn from it to think for himself.

Not sadistic, just realism.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,823
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 748
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Senior Bitch

Re: No idea how to do this problem...

 
0
  #10
Nov 11th, 2004
>but he may learn from it to think for himself.
Then again, he may never come back because all we helped him do is get bad grades. Then he'll probably try again on another forum with similar success. I'd rather have someone here, where I can guide their progress, rather than elsewhere, screwing up and not learning the right lessons from it.
New members chased away this month: 3
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC