System Software Lab 10 | Read Now

System Software VTU Lab

Program 10

a] Design, develop, and implement a C/C++/Java program to simulate a numerical calculator.

b] Design, develop and implement a C/C++/Java program to simulate page replacement technique.


System Software Lab10 Code [lab10a.c]

#include <stdio.h>

int main()
{
 char operator;
 float num1, num2, result;
 printf("Simulation of a Simple Calculator\n\n");
 printf("Enter two numbers \n");
 scanf("%f %f", &num1,&num2);

 fflush(stdin);
 printf("\nEnter the operator [+,-,*,/] \n");
 scanf("%s", &operator);

 switch(operator)
 {
  case '+': result = num1 + num2;  break;
  case '-': result = num1 - num2;  break;
  case '*': result = num1 * num2;  break;
  case '/': result = num1 / num2;  break;
  default : printf("Error in operation");     break;
 }
 printf("\n%.2f %c %.2f = %.2f\n", num1, operator, num2, result);
}

Output

System Software

System Software LAB 10B Code [lab10b.c]

#include<stdio.h>

int main()
{
      int reference_string[10], page_faults = 0, m, n, s, pages, frames;
      printf("\nEnter Total Number of Pages:\t");
      scanf("%d", &pages);
      printf("\nEnter values of Reference String:\n");
      for(m = 0; m < pages; m++)
      {
            printf("Value No. [%d]:\t", m + 1);
            scanf("%d", &reference_string[m]);
      }
      printf("\nEnter Total Number of Frames:\t");
      scanf("%d", &frames);
      int temp[frames];
      for(m = 0; m < frames; m++)
            temp[m] = -1;
      for(m = 0; m < pages; m++)
      {
            s = 0;
            for(n = 0; n < frames; n++)
            {
                  if(reference_string[m] == temp[n])
                  {
                        s++;
                        page_faults--;
                  }
            }
            page_faults++;
            if((page_faults <= frames) && (s == 0))
                  temp[m] = reference_string[m];
            else if(s == 0)
                  temp[(page_faults - 1) % frames] = reference_string[m];
            printf("\n");
            for(n = 0; n < frames; n++)
                  printf("%d\t", temp[n]);
      }
      printf("\nTotal Page Faults:\t%d\n", page_faults);
      return 0;
}

Output

System Software

Leave a Reply

Your email address will not be published. Required fields are marked *

WhatsApp Icon Join For Job Alerts