Menu

Saturday, August 13, 2016

Friday, August 5, 2016

Greetings from the owner of this blog


Hello, I am the owner of this blog, my main reason for making this blog is for students especially Computer Science students to use these codes as reference in order to increase their base knowledge on the logic of programming, hopefully. 

The second reason for making this blog is because it is a requirement to gain 8% of my midterm grade or 4% of my overall a major subject of mine. 

Third reason is to experience making a blog and use this experience to further improve my knowledge and skills.
Even though my posts are amateurish, I do hope it can help develop the insights in programming of those reading my posts.
Thank you and Good Luck.
P.S. : I don't own this pic(obviously)
Update: It's 20% of my midterm now.
Image Source


Writing a Program

Programming can either be Heaven or Hell depending on how much you know and how much you understand. As a CS student, majority of my course mates are still having hard time in programming. While browsing through their codes, I began to understand that they have no idea about what the program should do so that it would generate the desired output, in other words, they were trying to get the output without trying to understand the statement problem. In programming, one should not rush to the ending, we should first understand the problem statement, then know its inputs, then processes, and last is to find the desired output. I will prove my  example, the problem statement is "The sum of x and y is equal to 5. The value of y is 3.  Find x. If sum of x and y is equal to 5 then print 'Correct' else print 'Incorrect' ". By using this problem statement, we can assume that the inputs are:
x
y=3
sum=5

And the processes:
To find x
x=sum-y
To check if sum of x and y is equal to 5 and then print 'Correct' else print 'Incorrect':
if(x+y==sum)
print "Correct"
else
print "Incorrect"

Now that we have both the inputs and processes we can use it to write a code on any programming language. My personal favorite is PHP so I will use PHP in writing the code. The code should be:
<?php
$y=3;
$sum=5;
$x=$sum-$y;
if($x+$y==$sum)
echo"Correct";
else
echo"Incorrect"; 
?>
By using this code I got:
Easy right? Try it yourself. Experiencing starts with trying. Even talent can be overcome by hard work. Good luck :)

Wednesday, August 3, 2016

FCFS SCHEDULING CODES

PHP Program

FCFS(First Come First Serve) Scheduling 
And
Gantt Chart
PHP Program


<!--
   job[10][0]=id
   job[10][1]=bt
   job[10][2]=at
   job[10][3]=ft
   job[10][4]=tt
   job[10][5]=wt
-->
<?php
    $count=1;
    $count2=0;
    $count3=0;
    $flag=0;
    $ATT=0;
    $AWT=0;
    $hold=0;
    $hold2=0;
        if(isset($_POST["submit"]))
        {
            $count=$_POST['count'];
        }
        if(isset($_POST["solve"]))
        {
            for($x=1;$x<=$count;$x++)
            {
             $count=$_POST['count'];
             $job[$x][0]=$x;
             $job[$x][1]=$_POST['bt'.$x];
             $job[$x][2]=$_POST['at'.$x];
             $flag=1;
            }
        }
?>
<form method="post">
Number of Jobs:<input type="text" name="count" id="count" placeholder="count" value="<?php echo $count; ?>"><br><br>
<input type="submit" id="submit" placeholder="submit" name="submit" value="Submit">
<br>
<input type="submit" name="solve" id="solve" placeholder="solve" value="Solve">
<br>
<br>
<?php
if($flag==1)
    { 
     for($x=1;$x<=$count;$x++)
      {
        if($count2<=$job[$x][2])
        {
            $count2=$job[$x][2];
        }
        $hold=$count2+$job[$x][1];
        for($y=$count2;$y<$hold;$y++)
         {
            $count2++;
         }
         $job[$x][3]=$count2;
         $job[$x][4]=$job[$x][3]-$job[$x][2];
         $job[$x][5]=$job[$x][4]-$job[$x][1];
         $ATT=$ATT+$job[$x][4];
         $AWT=$AWT+$job[$x][5];  
      }      
    $ATT=$ATT/$count;                      
    $AWT=$AWT/$count;
    $job[0][3]=0;
    for($x=1;$x<=$count;$x++)
    {
?>
Job:<?php echo $job[$x][0]; ?> :
<?php
          for($y=1;$y<=$job[$x][3];$y++)
           {  
              if($job[$x][2]>$job[$x-1][3])
              {
                $hold2=$job[$x][2];  
              }
              else
              {
                $hold2=$job[$x-1][3];
              } 
              if(($y>$hold2 AND $x!=1) OR $x==1)
              {
?>
        <font style="background-color:#62<?php echo $x;?>4<?php echo $x;?>5" color="#62<?php echo $x;?>4<?php echo $x;?>5" > <?php echo $x;?> </font>
<?php } else { ?>
        <font style="background-color:#FFFFFF" color="#FFFFFF"><?php echo $x;?></font>  
<?php  
    }    
}
?>                                          
<br>
<?php
    } 
?>
<br>
<br>
Average Turnaround Time: <?php echo $ATT; ?> <br>
Average Waiting Time: <?php echo $AWT; ?> <br>    

 <table border="1">
        <tr>
            <th>JobID</th>
            <th>Burst Time</th>
            <th>Arrival Time</th>
            <th>Finish Time</th>
            <th>Turnaround Time</th>
            <th>Waiting Time</th>
        </tr>
        <?php
        for($x=1;$x<=$count;$x++)
        {
        ?>
        <tr>
        <th><?php echo $job[$x][0]; ?></th>
        <th><?php echo $job[$x][1]; ?></th>
        <th><?php echo $job[$x][2]; ?></th>
        <th><?php echo $job[$x][3]; ?></th>
        <th><?php echo $job[$x][4]; ?></th>
        <th><?php echo $job[$x][5]; ?></th>
        </tr> 
 <?php }} else { ?>
 <table border="1">
        <tr>
            <th>JobID</th>
            <th>Arrival Time</th>
            <th>Burst Time</th>
        </tr>
        <?php
        for($x=1;$x<=$count;$x++)
        {
        ?>
        <tr>
        <th><?php echo $x ?></th>
        <th><input type="text" id="at<?php echo $x; ?>" name="at<?php echo $x; ?>" placeholder="at<?php echo $x; ?>"></th>
        <th><input type="text" id="bt<?php echo $x; ?>" name="bt<?php echo $x; ?>" placeholder="bt<?php echo $x; ?>"></th>
        </tr> 
 <?php }} ?>
 </table>

</form>  

FCFS SCHEDULING WITH ARRIVAL TIME CODES

PHP Program

FCFS(First Come First Serve) Scheduling with Arrival Time
And
Gantt Chart

<!--
   job[10][0]=id
   job[10][1]=bt
   job[10][2]=at
   job[10][3]=ft
   job[10][4]=tt
   job[10][5]=wt
-->
<?php
    $count=1;
    $count2=0;
    $count3=0;
    $flag=0;
    $ATT=0;
    $AWT=0;
    $hold=0;
    $hold2=0;
        if(isset($_POST["submit"]))
        {
            $count=$_POST['count'];
        }
        if(isset($_POST["solve"]))
        {
            for($x=1;$x<=$count;$x++)
            {
             $count=$_POST['count'];
             $job[$x][0]=$x;
             $job[$x][1]=$_POST['bt'.$x];
             $job[$x][2]=$_POST['at'.$x];
             $flag=1;
            }
        }
?>
<form method="post">
Number of Jobs:<input type="text" name="count" id="count" placeholder="count" value="<?php echo $count; ?>"><br><br>
<input type="submit" id="submit" placeholder="submit" name="submit" value="Submit">
<br>
<input type="submit" name="solve" id="solve" placeholder="solve" value="Solve">
<br>
<br>
<?php
if($flag==1)
    { 
     for($x=1;$x<=$count;$x++)
      {
        if($count2<=$job[$x][2])
        {
            $count2=$job[$x][2];
        }
        $hold=$count2+$job[$x][1];
        for($y=$count2;$y<$hold;$y++)
         {
            $count2++;
         }
         $job[$x][3]=$count2;
         $job[$x][4]=$job[$x][3]-$job[$x][2];
         $job[$x][5]=$job[$x][4]-$job[$x][1];
         $ATT=$ATT+$job[$x][4];
         $AWT=$AWT+$job[$x][5];  
      }      
    $ATT=$ATT/$count;                      
    $AWT=$AWT/$count;
    $job[0][3]=0;
    for($x=1;$x<=$count;$x++)
    {
?>
Job:<?php echo $job[$x][0]; ?> :
<?php
          for($y=1;$y<=$job[$x][3];$y++)
           {  
              if($job[$x][2]>$job[$x-1][3])
              {
                $hold2=$job[$x][2];  
              }
              else
              {
                $hold2=$job[$x-1][3];
              } 
              if(($y>$hold2 AND $x!=1) OR $x==1)
              {
?>
        <font style="background-color:#62<?php echo $x;?>4<?php echo $x;?>5" color="#62<?php echo $x;?>4<?php echo $x;?>5" > <?php echo $x;?> </font>
<?php } else { ?>
        <font style="background-color:#FFFFFF" color="#FFFFFF"><?php echo $x;?></font>  
<?php  
    }    
}
?>                                          
<br>
<?php
    } 
?>
<br>
<br>
Average Turnaround Time: <?php echo $ATT; ?> <br>
Average Waiting Time: <?php echo $AWT; ?> <br>    

 <table border="1">
        <tr>
            <th>JobID</th>
            <th>Burst Time</th>
            <th>Arrival Time</th>
            <th>Finish Time</th>
            <th>Turnaround Time</th>
            <th>Waiting Time</th>
        </tr>
        <?php
        for($x=1;$x<=$count;$x++)
        {
        ?>
        <tr>
        <th><?php echo $job[$x][0]; ?></th>
        <th><?php echo $job[$x][1]; ?></th>
        <th><?php echo $job[$x][2]; ?></th>
        <th><?php echo $job[$x][3]; ?></th>
        <th><?php echo $job[$x][4]; ?></th>
        <th><?php echo $job[$x][5]; ?></th>
        </tr> 
 <?php }} else { ?>
 <table border="1">
        <tr>
            <th>JobID</th>
            <th>Arrival Time</th>
            <th>Burst Time</th>
        </tr>
        <?php
        for($x=1;$x<=$count;$x++)
        {
        ?>
        <tr>
        <th><?php echo $x ?></th>
        <th><input type="text" id="at<?php echo $x; ?>" name="at<?php echo $x; ?>" placeholder="at<?php echo $x; ?>"></th>
        <th><input type="text" id="bt<?php echo $x; ?>" name="bt<?php echo $x; ?>" placeholder="bt<?php echo $x; ?>"></th>
        </tr> 
 <?php }} ?>
 </table>
</form>