Well, it looks pretty straightforward. Do you know any C++?
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Okay. But I am not going to write anything. I will go with you step by step, and you write the program.
First of all, you write the main function in C++, and post it in your next reply. Nothing fancy, just the main function.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Okay. Study this.
#include<iostream>
const int TOTAL_PARTITIONS_IN_MEMORY = 10;
enum STATUS{ FREE = 0, BUSY = 1 };
int main()
{
// This is the array that stores the memory partition size
int memory_partition_size[ TOTAL_PARTITIONS_IN_MEMORY ] = { 1 };
// This is the array that stores the memory partition status
// It is initialized to be free at the beginning
STATUS memory_partition_status[ TOTAL_PARTITIONS_IN_MEMORY ] = { FREE };
// initializing the memory partition sizes so as a partition is
// double the size of the previous partition
for (int i = 1 ; i < TOTAL_PARTITIONS_IN_MEMORY ; i++ )
{
memory_partition_size[ i ] = memory_partition_size[ i-1 ] * 2;
}
// here we go until infinity or
// the user enters a negative number or 0
// whichever comes first.
int job_size = 0;
while ( true )
{
std::cout << "Enter the job size in bytes " ;
std::cin >> job_size;
if ( job_size <= 0)
{
std::cout << "Only Positive Non-zero Job Sizes allowed\n";
std::cout << "Exiting program\n";
break;
}
// Check if the job size is greater than the largest partion size.
// The largest partition is the size of the final partition.
if (job_size > memory_partition_size[TOTAL_PARTITIONS_IN_MEMORY - 1] )
{
// If it is larger then inform that to the user and get the next job
std::cout << "Job Size is larger than the maximum partition size\n";
continue;
}
// The partition can fit a memory partition. Now find that partition.
for ( int i = 0 ; i < TOTAL_PARTITIONS_IN_MEMORY; i++ )
{
if
(
// The job fits the partition
job_size <= memory_partition_size[ i ]
&&
// The partition is free
memory_partition_status[ i ] == FREE
)
{
// Set the partition as busy and tell the user.
memory_partition_status[ i ] = BUSY;
std::cout << "Job assigned to partition number "<< i <<
std::endl;
// Go to the other job
break;
}
else if(i < TOTAL_PARTITIONS_IN_MEMORY-1)
{
continue;
}
else if ( i == TOTAL_PARTITIONS_IN_MEMORY-1 )
{
std::cout << "All possible partitions are busy\n";
std::cout << "Putting job to queue\n";
}
}
}
}
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115