THIS IS FOR C++ Problem Write a program to keep track of business contacts. Spec
ID: 3714841 • Letter: T
Question
THIS IS FOR C++
Problem
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.
Explanation / Answer
Executable Code:
#include <bits/stdc++.h>
using namespace std;
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;
}
};
int main(){
int n;
ifstream infile;
try {
infile.open("input.txt",'r');
BusninessContact** record = new BusninessContact*[1000];
int size = 0;
for (int i = 0; i < 1000; i++)
record[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);
record[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);
record[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 (record[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 (record[i]->email_id == email && del[i] == false){
cout << "INFORMATION OF THE CONTACT " << endl;
cout << "FIRST NAME : " << record[i]->first_name << endl;
cout << "LAST NAME : " << record[i]->last_name << endl;
cout << "PHONE NUMBER : " << record[i]->phone_num << endl;
cout << "EMAIL ID : " << record[i]->email_id << endl;
cout << "COMPANY : " << record[i]->company << endl;
break;
}
}
}
if (n == 4){
cout << "Display the Contact List " << endl;
for (int i = 0; i < size; i++){
cout << "FIRST NAME : " << record[i]->first_name << endl;
cout << "LAST NAME : " << record[i]->last_name << endl;
cout << "PHONE NUMBER : " << record[i]->phone_num << endl;
cout << "EMAIL ID : " << record[i]->email_id << endl;
cout << "COMPANY : " << record[i]->company << endl;
cout << endl;
}
}
else
break;
}
ofstream outfile;
outfile.open("input.txt",'w');
for (int i = 0; i < size; i++){
BusninessContact* bc = record[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 ---- input.txt ---- is not Here ";
}
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.