Write a program to keep track of business contacts. Specification 1- Create a Bu
ID: 3827731 • Letter: W
Question
Write a program to keep track of business contacts.
Specification
1- Create a BusinessContact class with the following fields:
- firstName:String
- lastName:String
- phoneNumber:String
- emailAddress:String
- company:String
2- Store the records in memory in an array.
3- Store the records on disk in the text file contacts.txt.
4- Create a menu that allows for the following operations:
- Add a Contact
- Delete a Contact
- View a Contact
- Display the Contact List
5- Automatically read the text file and store the records in an array when the program begins.
6- Automatically write the records to the file when the program ends.
Attach your .h and .cpp source code files.
Explanation / Answer
// BusninessContact.h
#ifndef BUSINESSCONTACT_H
#define BUSINESSCONTACT_H
class BusninessContact{
public:
string first_name;
string last_name;
string phone_num;
string email_id;
string company;
BusninessContact(string f,string l,string p,string e,string c){
first_name = f;
last_name = l;
phone_num = p;
email_id = e;
company = c;
}
};
// main.cpp
#include <bits/stdc++.h>
#include "BusninessContact.h"
using namespace std;
int main(){
int n;
ifstream infile;
try {
infile.open("contacts.txt",'r');
BusninessContact** bc = new BusninessContact*[1000];
int size = 0;
for (int i = 0; i < 1000; i++)
bc[i] = new BusninessContact[1];
bool* del = new bool[1000];
for (int i = 0; i < 1000; i++)
del[i] = false;
while (!infile.eof()){
string f,string l,string p,string e,string c;
infile >> f >> l >> p >> e >> c;
BusninessContact *bc = new BusninessContact(f,l,p,e,c);
bc[size] = bc;
size += 1;
}
infile.close();
int n;
while (true){
cout << "1. Add a Contact " << endl;
cout << "2. Delete a Contact " << endl;
cout << "3. View a Contact " << endl;
cout << "4. Display the Contact List " << endl;
cout << "5. EXIT " << endl;
cout << "Choose a option : ";
cin >> n;
if (n == 1){
cout << "enter first name, last name, phone number, email address and company ";
string f,string l,string p,string e,string c;
cin >> f >> l >> p >> e >> c;
BusninessContact *bc = new BusninessContact(f,l,p,e,c);
bc[size] = bc;
size += 1;
}
if (n == 2){
string email;
cout << "Enter the email Address of the Employee you want to delete : ";
cin >> email;
for (int i = 0; i < size; i++){
if (bc[i]->email_id == email){
del[i] = true;
break;
}
}
}
if (n == 3){
string email;
cout << "Enter the email Address of the Employee you want to search : ";
cin >> email;
for (int i = 0; i < size; i++){
if (bc[i]->email_id == email && del[i] == false){
cout << "INFORMATION OF THE CONTACT " << endl;
cout << "FIRST NAME : " << bc[i]->first_name << endl;
cout << "LAST NAME : " << bc[i]->last_name << endl;
cout << "PHONE NUMBER : " << bc[i]->phone_num << endl;
cout << "EMAIL ID : " << bc[i]->email_id << endl;
cout << "COMPANY : " << bc[i]->company << endl;
break;
}
}
}
if (n == 4){
cout << "Display the Contact List " << endl;
for (int i = 0; i < size; i++){
cout << "FIRST NAME : " << bc[i]->first_name << endl;
cout << "LAST NAME : " << bc[i]->last_name << endl;
cout << "PHONE NUMBER : " << bc[i]->phone_num << endl;
cout << "EMAIL ID : " << bc[i]->email_id << endl;
cout << "COMPANY : " << bc[i]->company << endl;
cout << endl;
}
}
else
break;
}
ofstream outfile;
outfile.open("output.txt",'w');
for (int i = 0; i < size; i++){
BusninessContact* bc = bc[i];
outfile << bc->first_name << " " << bc->last_name << " " << bc->phone_num << " " << bc->email_id << " " << bc->company << endl;
}
outfile.close();
}
catch (std::ifstream::failure e) {
std::cerr << "The File ---- output.txt ---- is not Here ";
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.