
can I have an working example in c++ thx
#include <iostream>
#include <fstream>
#include <cstring>
#include <iomanip>
using namespace std;
class phoneBook
{
char name[20],phno[15];
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(20)<<name;
cout<<setw(15)<<phno;
}
int main(){
phoneBook rec;
fstream file;
file.open("phone.txt", ios::ate | ios::in | ios::out | ios::binary );
char c,ch,nm[20],telno[6];
int choice,cnt,found=0;
do{
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();
file.write((char *) &rec, sizeof(rec));
cout<<"Record Added Succesfully\n";
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();
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";
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";
break;
case 5 : //Update Telephone No.
cout<<"\n\nEnter Name : ";
cin>>nm;
file.seekg(0,ios::beg);
found=0;
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:
break;
}
cout<<"do you want to exit(y/n): ";
cin>>c;
}while(c=='n'||c=='N');
file.close();
}
can I have an working example in c++ thx 1. A record keeper that can store...
Lab #2 Address Book Unsorted List (C++) Using classes, design an online address book to keep track of the names (first and last), addresses, phone numbers, and dates of birth. The menu driven program should perform the following operations: Load the data into the address book from a file Write the data in the address book to a file Search for a person by last name or phone number (one function to do both) Add a new entry to the...
***PLEASE AVOID USING A "CLASS" IN SOLUTION*** thank you.
Please use Visual Studio to write a C# program to allow user to
store contact information.
1. User should be able to type in name, E-mail and phone number
in the text boxes and click Add button to save the contact record.
Every time when user add record, user should be able to see all the
information displayed in the right side display text box. (allow up
to 10 records)
2....
C++ In this assignment, you will write a class that implements a contact book entry. For example, my iPhone (and pretty much any smartphone) has a contacts list app that allows you to store information about your friends, colleagues, and businesses. In later assignments, you will have to implement this type of app (as a command line program, of course.) For now, you will just have to implement the building blocks for this app, namely, the Contact class. Your Contact...
C++ i want Lab#3 done can u make clear code so I could understand it. Lab#2The objective of this lab is compare the populations of various cities that lie in between Toledo and Dayton on I-75. Write a program that produces a bar illustrating the populations. The program should read the name of the city and its population from a file. Have the program continue this process until the end of file is reached. For each city, your program should...
C++ need help programming something like this?
This project will help you show your mastery of arrays, C-strings, classes, and libraries. Write a program to handle a user's rolodex entries. (A rolodex is a system with tagged cards each representing a contact. It would contain a name, address, and phone number. In this day and age, it would probably have an email address as well.) Typical operations people want to do to a rolodex entry are: 1) Add entry 2)...
%20Capstone%20Project%20using%20Access.pdf t-content-rid-24664575-2/courses/209275/CIS%201 1 509620D Part 2 If your last name begins with the letter A-G: create a report that displays only the people who have paid at least $500 this year. Include the person's name, address, city, phone number, and YTD paid sorted by YTD paid (descending), then their last name. If your last name begins with the letter H-M: create a report that displays only the people who have a balance of more than $100. Include the person's name,...
can you please follow all the instructions ? The answers that I got has either missing range for loop or one funtion . Read the instructions carefully. At least 10% will be deducted if the instructions are not followed. For general lab requirements, see General Lab Requirements. Do not prompt the user for input during the execution of your program. Do not pause at the end of the execution waiting for the user's input. Notes 1. Your program should use...
I need help with this assignment in C++,
please!
*** The instructions and programming style details
are crucial for this assignment!
Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...
This program will store a roster of most popular videos with kittens. The roster can include at most 10 kittens.You will implement structures to handle kitten information. You will also use functions to manipulate the structure. (1) Create a structure kitten. The structure should contain the following attributes: name; string color; string score; integer Important! The name of the structure and each of its field must match exactly for the program to work and be graded correctly. (2) Create a...