CPU scheduling (Round Robin) Program in C


#include<stdio.h>
#include<conio.h>
main()
{
  int st[10],bt[10],wt[10],tat[10],n,tq;
  int i,count=0,swt=0,stat=0,temp,sq=0;
  float awt=0.0,atat=0.0;
  clrscr();
  printf(“Enter number of processes:”);
  scanf(“%d”,&n);
  printf(“Enter burst time for sequences:”);
  for(i=0;i<=n;i++)
   {
     scanf(“%d”,&bt[i]);
     st[i]=bt[i];
   }
   printf(“Enter time quantum:”);
   scanf(“%d”,&tq);
   while(1)
   {
     for(i=0,count=0;i<=n;i++)
     {
       temp=tq;
       if(st[i]==0)
       {
  count++;
  continue;
       }
       if(st[i]=>tq)
 st[i]=st[i]-tq;
       else
 if(st[i]>=0)
 {
   temp=st[i];
   st[i]=0;
 }
 sq=sq+temp;
 tat[i]=sq;
     }
     if(n==count)
     break;
   }
   for(i=0;i<=n;i++)
   {
    wt[i]=tat[i]-bt[i];
    swt=swt+wt[i];
    stat=stat+tat[i];
   }
   awt=(float)swt/n;
   atat=(float)stat/n;
   printf(“Process_no Burst time Wait time Turn around time
“);
   for(i=0;i<=n;i++)
    printf(“%d  %d  %d  %d
“,i+1,bt[i],wt[i],tat[i]);
    printf(“Avg wait time is %f
Avg turn around time is %f”,awt,atat);
    getch();
}

chdir Example program in C, chdir Demo in C, program using chdir function in C



 #include<stdio.h>   
#include<dos.h>
#include<stdlib.h>
#include<process.h>

 const char * const path = "d:/popsys/test";  
const char * const file = "lernc.txt";

int main () {
printf ("Changing directory to <%s>\n", path);

if (chdir (path) == -1) {
printf ("chdir failed - %s\n", strerror (errno));
}else {
printf ("chdir done !!!\n");
printf ("directory content of '%s'\n\n", path);
system ("ls -l");
printf ("\n");
printf ("checking the content of '%s'\n", file);
system ("cat lernc.txt");
}
return 0;
}

adapter design pattern example in C++, adapter design in C plus plus, CSquareShapeAdapter Class in C++, using CSquareShapeAdapter in C++


#include <iostream.h>
  
class CRoundShape
{
public:
virtual ~CRoundShape() { }
virtual void m_doRound() const=0;
};

class CSquareShape
{
public:
virtual ~CSquareShape() { }
virtual void m_doSquare() const=0;
};

class CRound_Hole
{
public:
void m_insert(const CRoundShape & shape) const
{
shape.m_doRound();
}
};

class CSquareShapeAdapter : public CRoundShape
{
private:
CSquareShape & square_shape;
public:
CSquareShapeAdapter(CSquareShape & shape) : square_shape(shape){ }
void m_doRound() const
{
square_shape.m_doSquare();
}
};

class CDisplayMessage : public CSquareShape
{
public:
void m_doSquare() const
{
std::cout << "http://animesh-programmingmania.blogspot.com/" << std::endl;
}
};

void display_message(const CRoundShape & shape)
{
CRound_Hole().m_insert(shape);
}

int main()
{
CDisplayMessage shape;
display_message(CSquareShapeAdapter(shape));
return 0;
}