Program must be written in C I am looking for design help wi

Program must be written in C++:

I am looking for design help with how to create this program. I am currently stuck. Write a program that maintains a telephone directory. The Telephone directory keeps records of people’s names and the corresponding phone numbers.The program should read an unknown number of names and phone numbers from a file “data.txt” and store them in a vector of strings. Each line in the input file contains a first name, last name and phone number in the following format xxx-xxx-xxxx.

Solution

#include<iostream>
#include<vector>
#include<fstream>
#include<string>

//to display input in format include below header file
#include<iomanip>
using namespace std;

int main()
{
   ifstream in;
   in.open(\"data.txt\");

//declare vector of strings to hold first name , last name and phone number
   vector<string> first_name;
   vector<string> last_name;
   vector<string> phone_number;
   string s1, s2, s3;
//check input file is open, if not open, display error
   if (!in)
   {
       cout << \"Can\'t open input file\" << endl;
       return -1;
   }
   while (!in.eof())
   {
       in >> s1 >> s2 >> s3;
       first_name.push_back(s1);
       last_name.push_back(s2);
       phone_number.push_back(s3);
   }

   //print result
   for (int i = 0; i < first_name.size(); i++)
   {
       cout << \"First Name\\t\" << \"Last Name \\t\" << \"Phone Number\" << endl;
       cout << setw(10)<<first_name[i] << \"\\t\"<<setw(10) << last_name[i] <<\"\\t\"<< setw(10) << phone_number[i] << endl;
   }
}

-----------------------------------------------------------------------------------

//output

First Name Last Name Phone Number
Jonson skjkj 789-9890-578
First Name Last Name Phone Number
Samantha dkklklio 345-868-89
First Name Last Name Phone Number
James sa 689-9875-867
First Name Last Name Phone Number
Bella s 556-5679-097

Program must be written in C++: I am looking for design help with how to create this program. I am currently stuck. Write a program that maintains a telephone d
Program must be written in C++: I am looking for design help with how to create this program. I am currently stuck. Write a program that maintains a telephone d

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site