In: Computer Science
c++ program
You are to use a Heap data structure for this assignment
I currently work for an investment/insurance company and I’m looking for clients to call, ones with funds. I need to have a schedule that shows the list of customers to call and the order to be called. The list of customers names and phone numbers are in the file ‘NamesAndPhoneV2.txt’. A second file contains a net worth value for each client. The files are separated for security and protection reasons, but the dollar value are in sync with the client list. (ie first client matches with the first dollar value listed etc.). The file is ‘NamesandPhoneWorth.txt’. There are less than 75 clients you need to handle.
Format ‘NamesAndPhoneV2’
personName phonenumber ;one
per line
example: Tom
Jones 234-2425
Format ‘NameandPhoneWorth.txt’
$xxxxxxx.xx
example: $12340000.00
I need a list of clients to call each week. Since I am new, I will need to develop some finesse with my communications and develop some style in talking with clients. So I will need to start with the least valued clients first and finish with the more valued ones last. I will call one client per day each day of the week. So I need a list for the first two weeks (5 clients each week). The list needs to be the client’s name, his phone number and his net worth listed in the order to be call. Generate a list for week one and a list for week two. I also would like a list of the last five clients to call, which will be the clients with most net worth. That just gives me a goal to work towards.
NamesAndPhoneV2.txt
Taylor marie 939-1512
james wilis thomas 261-8342
Hewy Lewy Dewy 623-9921
Stone Rock 544-2372
lea high lee 266-8324
stephens reynolds 696-9231
mack russell 123-1234
Lewis Michelle Tee 828-2148
john marshall 888-2891
Mister Rogers 924-7221
Hasey Moto 823-8000
Snow White 111-9999
Oe vey 177-1423
Twoseeor knocksee 823-8321
Legg T. 587-2839
Znot Noz Oozey 531-4353
Hofstra M. 601-3225
Malioneyh P. J. 287-4344
Morier G. E. 544-2319
Cray Z. Cyco 134-7242
Hauser Yauser 606-2940
Hack N Zakkers 231-4449
LessGo Eat 233-1984
Fanny Pac Jac 842-3242
Trigger Phanger 421-3435
Sid MacGriddy 882-2424
Currie W. D. 701-4281
Antoney Wenner 999-3255
Hoos R. Dadie 818-3821
Chipoff E Oblock 773-4152
Booger Runs 822-7724
Smelly Tau 707-7281
Tobe Ore Knott 613-2414
Bee Yond Lawz 634-2454
Tyson Chicken 602-3152
TooB OrNot 283-5214
SixOne Other 843-2343
Big Tow 384-5624
Juan Legged 882-6246
Tau Jam 532-6871
Zeventh Heaven 834-2563
Man Oh Mann 313-7422
E Lec Shaun 709-7424
Sticky Finger McRidder 829-9853
Mighty Mouse 222-2222
G P Morier 832-4562
Six One Another 829-8221
Pha Seed Doe 243-9233
Lu C Kant 247-7345
Thor Thumb 833-6391
Big I KanC 878-0129
Knot Dun Uet 729-5223
Ah C Mowtoe 334-8294
Lase Won 928-2824
NamesAndPhonWorth.txt
$19571000000.00
$10136000000.00
$12627000000.00
$27983000000.00
$28093000000.00
$20349000000.00
$16529000000.00
$11272000000.00
$26749000000.00
$17856000000.00
$2179000000.00
$14666000000.00
$25010000000.00
$1648000000.00
$5060000000.00
$14546000000.00
$25461000000.00
$21331000000.00
$15572000000.00
$31668000000.00
$6364000000.00
$4152000000.00
$26904000000.00
$24397000000.00
$286000000.00
$14729000000.00
$29986000000.00
$6266000000.00
$24056000000.00
$10528000000.00
$13875000000.00
$16135000000.00
$24911000000.00
$7515000000.00
$13566000000.00
$11627000000.00
$24086000000.00
$13939000000.00
$1455000000.00
$2226000000.00
$114000000.00
$24073000000.00
$24876000000.00
$1210000000.00
$20764000000.00
$19714000000.00
$25499000000.00
$14498000000.00
$2056000000.00
$9109000000.00
$5156000000.00
$6016000000.00
$29252000000.00
$18338000000.00
SOLUTION -
I have solve the problem in C++ code with comments and screenshot for easy understanding :)
CODE -
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
struct Person{
string name, number;
double bounty;
};
// for min_heap
bool comp1(struct Person &a,struct Person &b){
return a.bounty < b.bounty;
}
// for max_heap
bool comp2(struct Person &a,struct Person &b){
return a.bounty > b.bounty;
}
int main()
{
ifstream in1, in2;
in1.open("NamesAndPhoneV2.txt");
in2.open("NamesandPhoneWorth.txt");
vector<Person> list1,list2;
string line1,line2;
cout<<"Data Read from the files given: "<<endl;
while(getline(in1,line1) && getline(in2,line2)){
//cout<< line1 <<" "<< line2 << endl;
Person p;
vector<string> words;
stringstream ss(line1);
string temp;
while(ss >> temp){
words.push_back(temp);
}
for(int i = 0; i < words.size()-1; i++){
p.name += words[i] + " ";
}
p.number = words[words.size()-1];
p.bounty = stod(line2.substr(1,line2.length()));
cout<< fixed << setprecision(2) <<
p.name<<" "<<p.number<<"
"<<p.bounty<<endl;
list1.push_back(p);
list2.push_back(p);
//cout<< fixed << setprecision(2) <<
stod(p.bounty)<<endl;
}
// using the heap data structure
make_heap(list1.begin(),list1.end(), comp2);
int j = 1;
int t = 2;
cout <<"\nAfter heapifying:"<<endl<<endl;
while(t--){
cout<<"week #"<<j++<<" Top 5 Names For calling:
"<<endl;
int i = 0;
while(list1.size() && i < 5){
auto item = list1.front();
cout << fixed << setprecision(2) << item.name
<<" "<< item.number <<" "<< item.bounty
<< endl;
list1.erase(list1.begin());
make_heap(list1.begin(),list1.end(), comp2);
i++;
}
cout<<endl;
}
make_heap(list2.begin(),list2.end(), comp1);
cout<<"Complete List of Names for calling:
"<<endl;
while(list2.size()){
auto item = list2.front();
cout << fixed << setprecision(2) << item.name
<<" "<< item.number <<" "<< item.bounty
<< endl;
list2.erase(list2.begin());
make_heap(list2.begin(),list2.end(), comp1);
}
return 0;
}
SCREENSHOT-
// Program
OUTPUT -
IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I
WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK
YOU!!!!!!!!----------