Question

Objective: Write a C++ -program that will implement 4 Memory Management algorithms A) Best-Fit B) First-Fit C) Next-Fit D) Worst-Fit Your program must do the followin 1. Program Input a. User will input to the program, Number of partitions, and Memory Sizes for each partition/partitions b. User will input the name for each process, and the amount of memory the process needs 2. For each algorithm, your program should have a data structure(class) that will include the job status (Run/Wait), and the partition number assigned to the job (if the job was allocated) You can create an array or list of the class to represent the job queue 3. Program output a. Calculate and display a list of initial memory allocation, i.e which partitions contain which process after the first round of allocation b. Program will calculate and display the memory waste for each partition. c. A list of Processes not assigned to any partitiorn

The second picture that I attached is the input and output. I already did the code but I also have to add the partition number assigned to the job (if the job was allocated). Can you please do that for me? I copied and pasted my code below.

#include <iostream>

#include <string.h>

#include <stdio.h>

using std::cout;

using std::cin;

using std::endl;

unsigned int memorySize;

// Function prototypes

unsigned int FirstFit(struct Partition *, int, struct Job *, int);

unsigned int BestFit(struct Partition *, int, struct Job *, int);

unsigned int NextFit(struct Partition *, int, struct Job *, int);

unsigned int WorstFit(struct Partition *, int, struct Job *, int);

// Partition struct descriptor

struct Partition

{

unsigned int size;

int number;

bool free;

unsigned int hole;

char jobName[7];

};

// Job struct descriptor

struct Job

{

char name[4];

unsigned int size;

bool running; // Run/Wait

int partitionNumber;

};

int main()

{

Partition *partitions;

Job *jobs;

int numPartitions;

int numJobs;

unsigned int totalPartitionSize = 0;

// Prompt user for information needed

cout << "Input memory size: ";

cin >> memorySize;

cout << "Input number of partitions (max. 5): ";

cin >> numPartitions;

// Allocate memory for partitions

partitions = new Partition[numPartitions];

// Initialize each partition

for (int i = 0; i < numPartitions; i++)

{

int partitionSize;

cout << "Input size for partition " << i + 1 << ": ";

cin >> partitionSize;

totalPartitionSize += partitionSize;

// Check if enough memory available

if (totalPartitionSize > memorySize)

{

cout << "Error: Total partition size is more than memory size available" << endl;

delete[] partitions;

return -1;

}

partitions[i].size = partitionSize;

partitions[i].number = i + 1;

partitions[i].free = true;

partitions[i].hole = 0;

strncpy(partitions[i].jobName, "", sizeof(partitions[i].jobName));

}

cout << "Input number of jobs: ";

cin >> numJobs;

// Allocate memory for partitions

jobs = new Job[numJobs];

for (int i = 0; i < numJobs; i++)

{

snprintf(jobs[i].name, sizeof(jobs[i].name), "J%02d", i + 1);

cout << "Input size for " << jobs[i].name << ": ";

cin >> jobs[i].size;

jobs[i].running = false;

jobs[i].partitionNumber = 0;

}

while(true)

{

for (int i = 0; i < numPartitions; i++)

{

partitions[i].free = true;

partitions[i].hole = 0;

}

for (int i = 0; i < numJobs; i++)

{

jobs[i].running = false;

jobs[i].partitionNumber = 0;

}

int choice = 0;

while (!(choice >= 1 && choice <= 4))

{

cout << "Input memory management algorithm (1-4):" << endl;

cout << "1. First Fit" << endl;

cout << "2. Best Fit" << endl;

cout << "3. Next Fit" << endl;

cout << "4. Worst Fit" << endl;

cin >> choice;

}

unsigned int memoryWasted = 0;

if (choice == 1)

memoryWasted = FirstFit(partitions, numPartitions, jobs, numJobs);

else if (choice == 2)

memoryWasted = BestFit(partitions, numPartitions, jobs, numJobs);

else if (choice == 3)

memoryWasted = NextFit(partitions, numPartitions, jobs, numJobs);

else if (choice == 4)

memoryWasted = WorstFit(partitions, numPartitions, jobs, numJobs);

cout << "Choice was: " << choice << endl;

for(int i = 0; i < numPartitions;i++)

{

cout << partitions[i].jobName << "/" << partitions[i].hole << endl;

}

cout << "Total memory waste: " << memoryWasted << endl;

cout << "Jobs waiting: ";

int waitingCount = 0;

for (int i = 0; i < numJobs; i++)

{

if (!jobs[i].running)

{

cout << jobs[i].name;

if (i != numJobs - 1)

cout << ", ";

waitingCount++;

}

}

if (waitingCount == 0)

cout << "None" << endl;

cout << endl;

}

// Free memory

delete[] jobs;

delete[] partitions;

return 0;

}

// First fit algorithm

unsigned int FirstFit(Partition *partitions, int numPartitions, Job *jobs, int numJobs)

{

// Total memory waste

unsigned int memoryWaste = 0;

for (int i = 0; i < numJobs; i++)

{

// If job already running, skip it

if (jobs[i].running)

continue;

for (int j = 0; j < numPartitions; j++)

{

// Skip partitions that are either not free or not big enough to hold the job

if (!partitions[j].free || partitions[j].size < jobs[i].size)

continue;

// Update partition status

partitions[j].free = false;

memoryWaste += partitions[j].hole = partitions[j].size - jobs[i].size;

strncpy(partitions[j].jobName, jobs[i].name, sizeof(partitions[j].jobName));

// Update job status

jobs[i].running = true;

jobs[i].partitionNumber = partitions[j].number;

break;

}

}

return memoryWaste;

}

// Best fit algorithm

unsigned int BestFit(Partition *partitions, int numPartitions, Job *jobs, int numJobs)

{

// Total memory waste

unsigned int memoryWaste = 0;

for (int i = 0; i < numJobs; i++)

{

// If job already running, skip it

if (jobs[i].running)

continue;

int bestIndex = -1;

for (int j = 0; j < numPartitions; j++)

{

// Skip partitions that are either not free or not big enough to hold the job

if (!partitions[j].free || partitions[j].size < jobs[i].size)

continue;

if (bestIndex == -1)

bestIndex = j;

else if (partitions[j].size < partitions[bestIndex].size)

bestIndex = j;

}

if (bestIndex >= 0)

{

// Update partition status

partitions[bestIndex].free = false;

memoryWaste += partitions[bestIndex].hole = partitions[bestIndex].size - jobs[i].size;

strncpy(partitions[bestIndex].jobName, jobs[i].name, sizeof(partitions[bestIndex].jobName));

// Update job status

jobs[i].running = true;

jobs[i].partitionNumber = partitions[bestIndex].number;

}

}

return memoryWaste;

}

// Next fit algorithm

unsigned int NextFit(Partition *partitions, int numPartitions, Job *jobs, int numJobs)

{

// Total memory waste

unsigned int memoryWaste = 0;

int lastIndex = -1;

for (int i = 0; i < numJobs; i++)

{

// If job already running, skip it

if (jobs[i].running)

continue;

int curIndex = lastIndex;

for (;;)

{

curIndex++;

if (curIndex >= numPartitions)

{

if (lastIndex == -1 || lastIndex == 0)

break;

curIndex = 0;

}

else if (curIndex == lastIndex)

break;

// Skip partitions that are either not free or not big enough to hold the job

if (!partitions[curIndex].free || partitions[curIndex].size < jobs[i].size)

continue;

// Update partition status

partitions[curIndex].free = false;

memoryWaste += partitions[curIndex].hole = partitions[curIndex].size - jobs[i].size;

strncpy(partitions[curIndex].jobName, jobs[i].name, sizeof(partitions[curIndex].jobName));

// Update job status

jobs[i].running = true;

jobs[i].partitionNumber = partitions[curIndex].number;

lastIndex = curIndex;

break;

}

}

return memoryWaste;

}

unsigned int WorstFit(Partition *partitions, int numPartitions, Job *jobs, int numJobs)

{

unsigned int memoryWaste = 0;

for(int i = 0; i < numJobs; i++)

{

if(jobs[i].running)

continue;

int worstIndex = -1;

for(int j = 0; j < numPartitions; j++)

{

if((partitions[j].free && partitions[j].size < jobs[i].size) || (!partitions[j].free && partitions[j].hole < jobs[i].size))

continue;

if(worstIndex == -1)

worstIndex = j;

else if(partitions[j].free && partitions[j].size > partitions[worstIndex].size)

worstIndex = j;

else if(!partitions[j].free && partitions[j].hole > partitions[worstIndex].size)

worstIndex = j;

}

if(worstIndex >= 0)

{

if(partitions[worstIndex].free)

{

partitions[worstIndex].free = false;

memoryWaste += partitions[worstIndex].hole = partitions[worstIndex].size - jobs[i].size;

strncpy(partitions[worstIndex].jobName, jobs[i].name, sizeof(partitions[worstIndex].jobName));

jobs[i].running = true;

jobs[i].partitionNumber = partitions[worstIndex].number;

}

else

{

memoryWaste += partitions[worstIndex].hole = partitions[worstIndex].hole - jobs[i].size;

strncat(partitions[worstIndex].jobName, jobs[i].name, sizeof(partitions[worstIndex].jobName));

jobs[i].running = true;

jobs[i].partitionNumber = partitions[worstIndex].number;

}

}

}

return memoryWaste;

}

// Worst fit algorithm

/*unsigned int WorstFit(Partition *partitions, int numPartitions, Job *jobs, int numJobs)

{

// Total memory waste

unsigned int memoryWaste = 0;

for (int i = 0; i < numJobs; i++)

{

// If job already running, skip it

if (jobs[i].running)

continue;

int worstIndex = -1;

for (int j = 0; j < numPartitions; j++)

{

// Skip partitions that are either not free or not big enough to hold the job

if (!partitions[j].free || partitions[j].size < jobs[i].size)

continue;

if (worstIndex == -1)

worstIndex = j;

else if (partitions[j].size > partitions[worstIndex].size)

worstIndex = j;

}

if (worstIndex >= 0)

{

// Update partition status

partitions[worstIndex].free = false;

memoryWaste += partitions[worstIndex].hole = partitions[worstIndex].size - jobs[i].size;

strncpy(partitions[worstIndex].jobName, jobs[i].name, sizeof(partitions[worstIndex].jobName));

// Update job status

jobs[i].running = true;

jobs[i].partitionNumber = partitions[worstIndex].number;

}

}

return memoryWaste;

}*/

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I have added an int array named

int partitionNumberArray[numPartitions];

It maintains an array with partition number which is used for the Job and prints it with the final output.

The code is redundant and added to every function to support that.

If you want code optimization. you can create a function and call it from every fit function(first/best/next/worst).

#include <iostream>

#include <string.h>

#include <stdio.h>

using std::cout;

using std::cin;

using std::endl;

unsigned int memorySize;

// Function prototypes

unsigned int FirstFit(struct Partition *, int, struct Job *, int, int *);

unsigned int BestFit(struct Partition *, int, struct Job *, int, int *);

unsigned int NextFit(struct Partition *, int, struct Job *, int, int *);

unsigned int WorstFit(struct Partition *, int, struct Job *, int, int *);

// Partition struct descriptor

struct Partition

{

unsigned int size;

int number;

bool free;

unsigned int hole;

char jobName[7];

};

// Job struct descriptor

struct Job

{

char name[4];

unsigned int size;

bool running; // Run/Wait

int partitionNumber;

};

int main()

{

Partition *partitions;

Job *jobs;

int numPartitions;

int numJobs;

unsigned int totalPartitionSize = 0;

// Prompt user for information needed

cout << "Input memory size: ";

cin >> memorySize;

cout << "Input number of partitions (max. 5): ";

cin >> numPartitions;
int partitionNumberArray[numPartitions];

// Allocate memory for partitions

partitions = new Partition[numPartitions];

// Initialize each partition

for (int i = 0; i < numPartitions; i++)

{

int partitionSize;

cout << "Input size for partition " << i + 1 << ": ";

cin >> partitionSize;

totalPartitionSize += partitionSize;

// Check if enough memory available

if (totalPartitionSize > memorySize)

{

cout << "Error: Total partition size is more than memory size available" << endl;

delete[] partitions;

return -1;

}

partitions[i].size = partitionSize;

partitions[i].number = i + 1;

partitions[i].free = true;

partitions[i].hole = 0;

strncpy(partitions[i].jobName, "", sizeof(partitions[i].jobName));

}

cout << "Input number of jobs: ";

cin >> numJobs;

// Allocate memory for partitions

jobs = new Job[numJobs];

for (int i = 0; i < numJobs; i++)

{

snprintf(jobs[i].name, sizeof(jobs[i].name), "J%02d", i + 1);

cout << "Input size for " << jobs[i].name << ": ";

cin >> jobs[i].size;

jobs[i].running = false;

jobs[i].partitionNumber = 0;

}

while(true)

{

for (int i = 0; i < numPartitions; i++)

{

partitions[i].free = true;

partitions[i].hole = 0;

}

for (int i = 0; i < numJobs; i++)

{

jobs[i].running = false;

jobs[i].partitionNumber = 0;

}

int choice = 0;

while (!(choice >= 1 && choice <= 4))

{

cout << "Input memory management algorithm (1-4):" << endl;

cout << "1. First Fit" << endl;

cout << "2. Best Fit" << endl;

cout << "3. Next Fit" << endl;

cout << "4. Worst Fit" << endl;

cin >> choice;

}

unsigned int memoryWasted = 0;

if (choice == 1)

memoryWasted = FirstFit(partitions, numPartitions, jobs, numJobs,partitionNumberArray);

else if (choice == 2)

memoryWasted = BestFit(partitions, numPartitions, jobs, numJobs,partitionNumberArray);

else if (choice == 3)

memoryWasted = NextFit(partitions, numPartitions, jobs, numJobs,partitionNumberArray);

else if (choice == 4)

memoryWasted = WorstFit(partitions, numPartitions, jobs, numJobs,partitionNumberArray);

cout << "Choice was: " << choice << endl;

for(int i = 0; i < numPartitions;i++)

{
if(partitions[i].free)
continue;
cout << partitions[i].jobName << "/" <<"P"<<partitions[i].number<<"/"<<partitions[i].hole << endl;
//cout<< jobs[i].name <<"/"<<"P"<<jobs[i].partitionNumber<<"/"<<partitions[i].hole << endl;
}

cout << "Total memory waste: " << memoryWasted << endl;

cout << "Jobs waiting: ";

int waitingCount = 0;

for (int i = 0; i < numJobs; i++)

{

if (!jobs[i].running)

{

cout << jobs[i].name;

if (i != numJobs - 1)

cout << ", ";

waitingCount++;

}

}

if (waitingCount == 0)

cout << "None" << endl;

cout << endl;

}

// Free memory

delete[] jobs;

delete[] partitions;

return 0;

}

// First fit algorithm

unsigned int FirstFit(Partition *partitions, int numPartitions, Job *jobs, int numJobs,int *partitionNumberArray)

{

// Total memory waste
int pn = 0;
unsigned int memoryWaste = 0;

for (int i = 0; i < numJobs; i++)

{

// If job already running, skip it

if (jobs[i].running)

continue;

for (int j = 0; j < numPartitions; j++)

{

// Skip partitions that are either not free or not big enough to hold the job

if (!partitions[j].free || partitions[j].size < jobs[i].size)

continue;


// Update partition status

partitions[j].free = false;

memoryWaste += partitions[j].hole = partitions[j].size - jobs[i].size;

strncpy(partitions[j].jobName, jobs[i].name, sizeof(partitions[j].jobName));

// Update job status

jobs[i].running = true;

jobs[i].partitionNumber = partitions[j].number;

//cout<<" jobs[i].name : "<<jobs[i].name<<" jobs[i].partitionNumber : "<<jobs[i].partitionNumber<<" i:"<<i<<endl;

//Update Partition Number
if(pn<numPartitions)
{
partitionNumberArray[pn] = jobs[i].partitionNumber;
//cout<<"partitionNumberArray[pn] : "<<partitionNumberArray[pn]<<" pn:"<<pn<<endl;
pn++;

}

break;

}

}

return memoryWaste;

}

// Best fit algorithm

unsigned int BestFit(Partition *partitions, int numPartitions, Job *jobs, int numJobs,int *partitionNumberArray)

{

// Total memory waste
int pn = 0;
unsigned int memoryWaste = 0;

for (int i = 0; i < numJobs; i++)

{

// If job already running, skip it

if (jobs[i].running)

continue;

int bestIndex = -1;

for (int j = 0; j < numPartitions; j++)

{

// Skip partitions that are either not free or not big enough to hold the job

if (!partitions[j].free || partitions[j].size < jobs[i].size)

continue;

if (bestIndex == -1)

bestIndex = j;

else if (partitions[j].size < partitions[bestIndex].size)

bestIndex = j;

}

if (bestIndex >= 0)

{

// Update partition status

partitions[bestIndex].free = false;

memoryWaste += partitions[bestIndex].hole = partitions[bestIndex].size - jobs[i].size;

strncpy(partitions[bestIndex].jobName, jobs[i].name, sizeof(partitions[bestIndex].jobName));

// Update job status

jobs[i].running = true;

jobs[i].partitionNumber = partitions[bestIndex].number;


//Update Partition Number
if(pn<numPartitions)
{
partitionNumberArray[pn] = jobs[i].partitionNumber;
pn++;
}

}

}

return memoryWaste;

}

// Next fit algorithm

unsigned int NextFit(Partition *partitions, int numPartitions, Job *jobs, int numJobs,int *partitionNumberArray)

{

// Total memory waste
int pn = 0;
unsigned int memoryWaste = 0;

int lastIndex = -1;

for (int i = 0; i < numJobs; i++)

{

// If job already running, skip it

if (jobs[i].running)

continue;

int curIndex = lastIndex;

for (;;)

{

curIndex++;

if (curIndex >= numPartitions)

{

if (lastIndex == -1 || lastIndex == 0)

break;

curIndex = 0;

}

else if (curIndex == lastIndex)

break;

// Skip partitions that are either not free or not big enough to hold the job

if (!partitions[curIndex].free || partitions[curIndex].size < jobs[i].size)

continue;

// Update partition status

partitions[curIndex].free = false;

memoryWaste += partitions[curIndex].hole = partitions[curIndex].size - jobs[i].size;

strncpy(partitions[curIndex].jobName, jobs[i].name, sizeof(partitions[curIndex].jobName));

// Update job status

jobs[i].running = true;

jobs[i].partitionNumber = partitions[curIndex].number;

lastIndex = curIndex;

//Update Partition Number
if(pn<numPartitions)
{
partitionNumberArray[pn] = jobs[i].partitionNumber;
pn++;
}

break;

}

}

return memoryWaste;

}

unsigned int WorstFit(Partition *partitions, int numPartitions, Job *jobs, int numJobs,int *partitionNumberArray)

{

unsigned int memoryWaste = 0;
int pn=0;

for(int i = 0; i < numJobs; i++)

{

if(jobs[i].running)

continue;

int worstIndex = -1;

for(int j = 0; j < numPartitions; j++)

{

if((partitions[j].free && partitions[j].size < jobs[i].size) || (!partitions[j].free && partitions[j].hole < jobs[i].size))

continue;

if(worstIndex == -1)

worstIndex = j;

else if(partitions[j].free && partitions[j].size > partitions[worstIndex].size)

worstIndex = j;

else if(!partitions[j].free && partitions[j].hole > partitions[worstIndex].size)

worstIndex = j;

}

if(worstIndex >= 0)

{

if(partitions[worstIndex].free)

{

partitions[worstIndex].free = false;

memoryWaste += partitions[worstIndex].hole = partitions[worstIndex].size - jobs[i].size;

strncpy(partitions[worstIndex].jobName, jobs[i].name, sizeof(partitions[worstIndex].jobName));

jobs[i].running = true;

jobs[i].partitionNumber = partitions[worstIndex].number;

//Update Partition Number
if(pn<numPartitions)
{
partitionNumberArray[pn] = jobs[i].partitionNumber;
pn++;
}

}

else

{

memoryWaste += partitions[worstIndex].hole = partitions[worstIndex].hole - jobs[i].size;

strncat(partitions[worstIndex].jobName, jobs[i].name, sizeof(partitions[worstIndex].jobName));

jobs[i].running = true;

jobs[i].partitionNumber = partitions[worstIndex].number;

//Update Partition Number
if(pn<numPartitions)
{
partitionNumberArray[pn] = jobs[i].partitionNumber;
pn++;
}

}

}

}

return memoryWaste;

}

// Worst fit algorithm

/*unsigned int WorstFit(Partition *partitions, int numPartitions, Job *jobs, int numJobs)

{

// Total memory waste

unsigned int memoryWaste = 0;

for (int i = 0; i < numJobs; i++)

{

// If job already running, skip it

if (jobs[i].running)

continue;

int worstIndex = -1;

for (int j = 0; j < numPartitions; j++)

{

// Skip partitions that are either not free or not big enough to hold the job

if (!partitions[j].free || partitions[j].size < jobs[i].size)

continue;

if (worstIndex == -1)

worstIndex = j;

else if (partitions[j].size > partitions[worstIndex].size)

worstIndex = j;

}

if (worstIndex >= 0)

{

// Update partition status

partitions[worstIndex].free = false;

memoryWaste += partitions[worstIndex].hole = partitions[worstIndex].size - jobs[i].size;

strncpy(partitions[worstIndex].jobName, jobs[i].name, sizeof(partitions[worstIndex].jobName));

// Update job status

jobs[i].running = true;

jobs[i].partitionNumber = partitions[worstIndex].number;

}

}

return memoryWaste;

}*/

Add a comment
Know the answer?
Add Answer to:
The second picture that I attached is the input and output. I already did the code...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Code error help. I am getting the error: "expression must have a constant value, the...

    C++ Code error help. I am getting the error: "expression must have a constant value, the value of parameter 'n' ( declared at line 7) cannot be used as a constant" I am also getting this error at lines 65 and 66 with m and n. I do not know how to fix this. Here is my code and ive marked where the errors were with lines: #include<iostream> using namespace std; // Function to allocate memory to blocks as per...

  • How can I write this code (posted below) using vectors instead of arrays? This is the...

    How can I write this code (posted below) using vectors instead of arrays? This is the task I have and the code below is for Task 1.3: Generate twenty random permutations of the number 0, 1, 2, ..., 9 using of the algorithms you designed for Task 1.3. Store these permutations into a vector and print them to the screen with the additional information of unchanged positions and number of calls torand(). Calculate the total numbers of unchanged positions. Compare...

  • Add a menu to the existing code already written to contain the following options Change Input...

    Add a menu to the existing code already written to contain the following options Change Input voltage Add a single resistor Delete resistor Edit resistor Group add a series of resistors Display network Quit program Each item in the menu will probably end up being a function. A do-while loop and switch/case statement is probably best way to implement a menu. You need to create at least 4 functions. Existing code #include <iostream> #include <string> #include <vector> using namespace std;...

  • I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include...

    I need a detailed pseudocode for this code in C ++. Thank you #include <iostream> #include <string> #include <iomanip> using namespace std; struct Drink {    string name;    double cost;    int noOfDrinks; }; void displayMenu(Drink drinks[], int n); int main() {    const int size = 5;       Drink drinks[size] = { {"Cola", 0.65, 2},    {"Root Beer", 0.70, 1},    {"Grape Soda", 0.75, 5},    {"Lemon-Lime", 0.85, 20},    {"Water", 0.90, 20} };    cout <<...

  • I've posted 3 classes after the instruction that were given at start You will implement and...

    I've posted 3 classes after the instruction that were given at start You will implement and test a PriorityQueue class, where the items of the priority queue are stored on a linked list. The material from Ch1 ~ 8 of the textbook can help you tremendously. You can get a lot of good information about implementing this assignment from chapter 8. There are couple notes about this assignment. 1. Using structure Node with a pointer point to Node structure to...

  • C++ language I need to update this code with the following: ask the user for how...

    C++ language I need to update this code with the following: ask the user for how many structures they would like. Once you get the number, allocate an array of pointers. Once they have been created, proceed to loop through and get the data as usual, and display it back to the screen. struct record {    int age;    string name; }; int check(record r[], int n, string nm) {    for (int i = 0; i < n;...

  • Hi there. I tried to submit this before, but the copy/paste didn't copy my vectors correctly....

    Hi there. I tried to submit this before, but the copy/paste didn't copy my vectors correctly. Hello there. I am trying to implement the djikstras shortest path algorithm into my code in C++ with a vector of vectors. However, when I test I get an error "Exception thrown at 0x75FFC762 in graphMain.exe: Microsoft C++ exception: std::out_of_range at memory location 0x009CF26C" for line 115 in graph.cpp. Could you help me debug? I am so close! ----------------------------FILE NAME: pch.h--------------------------------------- // pch.cpp: source...

  • My code doesn't output correctly using a .txt file. How do I clean this up so...

    My code doesn't output correctly using a .txt file. How do I clean this up so it posts correctly? ----------------------------------------------- CODE ---------------------------------------------- #include <iostream> #include <string> #include <fstream> #include <iomanip> #include <fstream> using namespace std; struct Customer {    int accountNumber;    string customerFullName;    string customerEmail;    double accountBalance; }; void sortDesc(Customer* customerArray, int size); void print(Customer customerArray[], int size); void print(Customer customerArray[], int size) {    cout << fixed << setprecision(2);    for (int i = 0; i...

  • The following C code keeps returning a segmentation fault! Please debug so that it compiles. Also...

    The following C code keeps returning a segmentation fault! Please debug so that it compiles. Also please explain why the seg fault is happening. Thank you #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> // @Name loadMusicFile // @Brief Load the music database // 'size' is the size of the database. char** loadMusicFile(const char* fileName, int size){ FILE *myFile = fopen(fileName,"r"); // Allocate memory for each character-string pointer char** database = malloc(sizeof(char*)*size); unsigned int song=0; for(song =0; song < size;...

  • The goal is to generate some random number and output a sorted list by quicksort. what...

    The goal is to generate some random number and output a sorted list by quicksort. what do I need to add in my main to accomplish that? i also want it to output the run time. thank you #include "pch.h" #include <iostream> using namespace std; /* C implementation QuickSort */ #include<stdio.h> void swap(int* a, int* b) {    int t = *a;    *a = *b;    *b = t; } int partition(int arr[], int low, int high) {   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT