Question

In: Computer Science

c++ program You are to use a Heap data structure for this assignment I currently work...

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

Solutions

Expert Solution

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!!!!!!!!----------


Related Solutions

In this programming project, you will be implementing the data structure min-heap. You should use the...
In this programming project, you will be implementing the data structure min-heap. You should use the C++ programming language, not any other programming language. Also, your program should be based on the g++ compiler on general.asu.edu. All programs will be compiled and graded on general.asu.edu, a Linux based machine. If you program does not work on that machine, you will receive no credit for this assignment. You will need to submit it electronically at the blackboard, in one zip file,...
C++ Implement the array based Binary Heap data structure as discussed in class. This structure should...
C++ Implement the array based Binary Heap data structure as discussed in class. This structure should have a couple of constructures (default constructor, and a constructor that takes an array pointer and a size), a method for inserting items into the heap, a method for removing items from the heap, and a method that returns the number of items currently stored in the heap. This implementation should be templated so that it can store any type of data (you may...
The assignment: C++ program or Java You need to use the following programming constructs/data structures on...
The assignment: C++ program or Java You need to use the following programming constructs/data structures on this assignment. 1. A structure named student which contains:   a. int ID; student id; b. last name; // as either array of char or a string c. double GPA;    2. An input file containing the information of at least 10 students. 3. An array of struct: read the student information from the input file into the array. 4. A stack: you can use the...
Explain this code: The structure used is max heap using array. C++ (i is the index...
Explain this code: The structure used is max heap using array. C++ (i is the index of the element to be deleted) void del(int i) {    int left,right,temp;    arr[i]=arr[n-1];    n=n-1;    left=2*i+1; /*left child of i*/    right=2*i+2; /* right child of i*/    while(right < n)    {        if( arr[i]>=arr[left] && arr[i]>=arr[right] )            return;        if( arr[right]<=arr[left] )        {            temp=arr[i];            arr[i]=arr[left];   ...
I need specific codes for this C program assignment. Thank you! C program question: Write a...
I need specific codes for this C program assignment. Thank you! C program question: Write a small C program connect.c that: 1. Initializes an array id of N elements with the value of the index of the array. 2. Reads from the keyboard or the command line a set of two integer numbers (p and q) until it encounters EOF or CTL - D 3. Given the two numbers, your program should connect them by going through the array and...
Solve in C++ program. Modify the use of queue data structure such that the array used...
Solve in C++ program. Modify the use of queue data structure such that the array used to implement the queue is dynamically allocated for a fast food autoservice
I have to code the assignment below. I cannot get the program to work and I...
I have to code the assignment below. I cannot get the program to work and I am not sure what i am missing to get the code to work past the input of the two numbers from the user. My code is listed under the assignment details. Please help! Write a Java program that displays the prime numbers between A and B. Inputs: Prompt the user for the values A and B, which should be integers with B greater than...
C++ Heap Tree:  Make a program called "priority_queue" that has the following operations using a heap and...
C++ Heap Tree:  Make a program called "priority_queue" that has the following operations using a heap and simulating a prioritized row of integers with higher priority value. I would appreciate if someone could help me with this code It has to include the following on the code: push Description: Add data to prioritized row Entry: An integer, which you want to add to the prioritized row Exit: Nothing Precondition: n is an integer Postcondition: The prioritized row contains new data. pop...
Language C++ Implement a Priority Queue with a Binary HEAP. Use a Max Heap. Create a...
Language C++ Implement a Priority Queue with a Binary HEAP. Use a Max Heap. Create a class called Node: Have a Name and Priority.Data set - 10 is the highest priority, 1 is lowest priority. Enqueue and dequeue in the following order. Function  Name, Priority Enqueue  Joe, 3 Enqueue  Fred,1 Enqueue Tuyet,9 Enqueue  Jose, 6 Dequeue Enqueue  Jing, 2 Enqueue  Xi, 5 Enqueue  Moe, 3 DequeueEnqueue  Miko, 7 Enqueue Vlady, 8 Enqueue Frank, 9 Enqueue  Anny, 3 DequeueEnqueue  Xi, 2 Enqueue  Wali, 2 Enqueue  xChe, 6 Enqueue  xVerra, 8 Dequeue Dequeue Dequeue Dequeue...
hi i need to do a C++ program. You are going to practice the use of...
hi i need to do a C++ program. You are going to practice the use of array by implementing the interface of Shuttle Puzzle. Here is an example of how you play the Shuttle Puzzle. Say that you start with a board with 7 holes and there are 3 black and 3 white marbles on the board in this configuration: W W W . B B B The dot (.) represents the empty hole withouth any marble. The objective of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT