Really need help, can someone program this without USEING STOI or SUBSTR. got ma
ID: 664955 • Letter: R
Question
Really need help, can someone program this without USEING STOI or SUBSTR. got many error using code block because it does not support STOI and said that SUBSTR was not decalred in the scope when using it like this:
int main()
{
string data[100];
int n = 20;
int d,p;
ifstream myfile;
myfile.open("")
Heap heap;
while(true)
{
for (int i=0; i <100; i++)
{ myfile >> data[i];
////////////////////THIS GIVE MANY ERRORS/////////////////////////////
/////////////////////////stoi is not a memeber of std and substr was not declared in this scope/////////////////////////////////
d=std::stoi(substr(1,3));
p = std::stoi(substr(4,2))
}
}
PLEASE HELP!!!!!!!!!!!!!!!!!!!!!
Scenario: I run a ticket selling business for the big football games. I have customers calling asking for ball game tickets or packets and I will say business is good. Now my customers often (very often) will make several requests, that is buying packets for different groups of folks (their relatives, friends, office workers, companies, and lots of other folks who know that they (my customer) knows how to get tickets and maybe good tickets).
I deal with my customers on a first come first serve bases. I also rank my customers by their request based on a secret ranking procedure (you know, stuff like how fast they pay, the number of tickets they order, the type of tickets they order, how often they order etc etc the secret part). Each ticket packet request is assigned a ranking number or a priority. The bigger the number, the earlier request is process. Equal numbered requests are handled on a FIFO. Since this needs to be a rather fast process, I need a rather fast data structure for adding fetching and deleting request, so we are trying out the ‘priority heap’ data structure to see how well it works. Your job is to implement the Priority Heap only. My quality analysis department will test to see if this is a viable data structure or not. Maybe the final will have you evaluate this and other data structures for this problem?
I have an input file of data to test your program. The file name is ‘HeapPriortyNbrs.dat’. The input format is ‘idNbr-priority’. Ex 135-3 or 292-13. One input per line.
Output: After reading in 100 requests, print out the first 20 request and delete them from the heap.
Read in the next 100 request and print out the next 20 requests and delete them
Read in the rest of the request and print out the next 20 request and delete them.
Note: Don’t print the heap output down the page but across the page.
‘HeapPriortyNbrs.dat’ data
Explanation / Answer
std::stoi(data[i].substr(1,3))
For stoi to work, include #include<string>
int stoi(string s){
int num = 0;
for(int i = 0; i < s.length() ; i++){
num = num*10 + s[i]%58;
}
return num;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.