Halo....I'm new here......
Can somebody help me with this question?
Its a assignment but I REALLY DON HAV ANY IDEA HOW TO DO IT!!!!
So....Plz help......

Write C++ code for the following algorithm:

1) Determine job's reqeusted memory size
2) if job_size>size_of_large_partition
then reject job
print appropriate message
Go to step 1 to handle next job
else continute with step 3
3) Set counter to 1
4)Do while counter<=number_of_partition in memory
if job_size>mem_partition_size(counter)
then counter = counter + 1
else
if mem_partition_status(counter) = "free"
then load job into mem_partition(counter)
change
mem_partition_status(counter) to "busy"
go to step 1
else
counter = counter + 1
End do
5) No partition available at this time, put job in waiting queue
6) Go to step 1

P/S: This is a algorithm to load a job in a fixed partition....
Plz...I begged for your help!!!!!

Recommended Answers

All 6 Replies

Well, it looks pretty straightforward. Do you know any C++?

Well, it looks pretty straightforward. Do you know any C++?

Well...I did study C++ b4....
But not that good....*Sigh*.....
Can you help me?

Please....... :sad:

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.

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.

#include<iostream.h>
 
void main()
{
        loop1 ;
        if(job_size>largest_size)
           cout<<"Not enough space" ;
           goto loop1 ;
 
        int counter = 1 ;
 
        do
        {
              if (job_size>mem_partition_size(counter) )
                 counter = counter + 1 ;
              else
              if (mem_partition_status = "free")
              {
                 mem_partition_status(counter) = "busy" ;
                 goto loop1 ; 
              else
                 counter = counter + 1 ;
 
}

You wan this isn't it?
Pretty bad huh? :sad:
This is the best I can do.....
mem_partition_size(counter) is a class right?
Hope you can help......
Thank You very much.....

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";
            }
        }
    }
}

Oh....Arigatogozaimasu!!!!!!
Thank You so much!!!!!!
I'm saved!!!!
Thanks!
I'll try to understand it.....
BUT if I don understand can I ask you back?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.