Giter Site home page Giter Site logo

roerohan / miscellaneous Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 16.0 17.91 MB

Code for Assignments and Other Random Scripts

C++ 0.25% C 0.43% Python 0.17% JavaScript 0.12% Java 86.73% R 0.01% Jupyter Notebook 12.13% Dockerfile 0.01% TypeScript 0.01% HTML 0.12% PHP 0.01% Shell 0.01% CSS 0.01% Makefile 0.02%
hacktoberfest hacktoberfest2019 c cpp javascript miscellaneous miscellaneous-scripts java python python3

miscellaneous's Introduction

Miscellaneous

Code for Assignments and Other Random Scripts.

Hacktoberfest 2019

English

Append your names below if you sent a PR for Hacktoberfest 2019!

Español

Agrega tu nombre abajo, si enviaste un pull request (PR) por Hacktoberfest 2019!

Name Github profile
Rohan Mukherjee roerohan
fonkamloic fonkamloic
Matthew Castrillon-Madrigal matthewcm
lost1122 lost1122
flori4nk flori4nk
Saurav Hiremath sauravhiremath
Link RedstoneTek
atom atom
Deepanshu Chauhan cdeepanshu
Xaca Rana 🐸 xaca
Lakshay Almadi lakshayalmadi
Kuhoo Sharma KUHOO-S

miscellaneous's People

Contributors

atomc avatar carelessfinch avatar cdeepanshu avatar dependabot[bot] avatar flori4nk avatar fonkamloic avatar kuhoo-s avatar lakshayalmadi avatar lost1122 avatar matthewcm avatar roerohan avatar sanjana-r avatar sauravhiremath avatar shreshth-malik avatar theprogrammerdavid avatar xaca avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

miscellaneous's Issues

Add code for Banker's Algorithm

Write the code for Banker's algorithm in C.

The code must take the required matrices as input and not initialize them instead.

Add code for Scheduling Algorithms in C

Add code for all scheduling algorithms in OS.

Must be menu driven program comprising of all algorithms
Must contain pre-emptive and non-preemptive algorithms (wherever applicable)

The algorithms must be in C programming language

Website with AngularJS and Node.js

Build a Website on any one of the following topics using the following:

  • HTML
  • CSS
  • JS
  • AngularJS
  • Node.js
  • MongoDB

Put the client and server in different folders

Sustainable Development Goals

  • End poverty in all its forms everywhere

  • End hunger, achieve food security and improved nutrition and promote sustainable
    agriculture

-Ensure healthy lives and promote well-being for all at all ages

  • Ensure inclusive and equitable quality education and promote lifelong learning opportunities
    for all

  • Achieve gender equality and empower all women and girls

  • Ensure availability and sustainable management of water and sanitation for all

  • Ensure access to affordable, reliable, sustainable and modern energy for all

  • Promote sustained, inclusive and sustainable economic growth, full and productive
    employment and decent work for all

  • Build resilient infrastructure, promote inclusive and sustainable industrialization and foster
    innovation

  • Reduce inequality within and among countries

  • Make cities and human settlements inclusive, safe, resilient and sustainable

  • Ensure sustainable consumption and production patterns

  • Take urgent action to combat climate change and its impacts

  • Conserve and sustainably use the oceans, seas and marine resources for sustainable
    development

  • Protect, restore and promote sustainable use of terrestrial ecosystems, sustainably manage
    forests, combat desertification, and halt and reverse land degradation and halt biodiversity loss

  • Promote peaceful and inclusive societies for sustainable development, provide access to
    justice for all and build effective, accountable and inclusive institutions at all levels

  • Strengthen the means of implementation and revitalize the Global Partnership for
    Sustainable Development

Fix Menu Driven Program for OS Scheduling Algorithms (in C)

#include<stdio.h>
#include<stdlib.h>
typedef struct process {
char name[5];
int bt;
int at;
int prt;
int wt, ta;
int flag;
}
processes;
void bubble_sort(processes proc[], int n) {
processes t;
int i, j;
for (i = 1; i < n; i++)
for (j = 0; j < n - i; j++) {
if (proc[j].at > proc[j + 1].at) {
t = proc[j];
proc[j] = proc[j + 1];
proc[j + 1] = t;
}
}
}
int get_Processes(processes P[]) {
int i, n;
printf("\n Enter total no. of processes : ");
scanf("%d", & n);
for (i = 0; i < n; i++) {
printf("\n PROCESS [%d]", i + 1);
printf(" Enter process name : ");
scanf("%s", & P[i].name);
printf(" Enter burst time : ");
scanf("%d", & P[i].bt);
printf(" Enter arrival time : ");
scanf("%d", & P[i].at);
printf(" Enter priority : ");
scanf("%d", & P[i].prt);
}
printf("\n PROC.\tB.T.\tA.T.\tPRIORITY");
for (i = 0; i < n; i++)
printf("\n %s\t%d\t%d\t%d", P[i].name, P[i].bt, P[i].at, P[i].prt);
return n;
}
// FCFS Algorithm
void FCFS(processes P[], int n) {
processes proc[10];
int sumw = 0, sumt = 0;
int x = 0;
float avgwt = 0.0, avgta = 0.0;
int i, j;
for (i = 0; i < n; i++)
proc[i] = P[i];
bubble_sort(proc, n);
printf("\n\n PROC.\tB.T.\tA.T.");
for (i = 0; i < n; i++)
printf("\n %s\t%d\t%d", proc[i].name, proc[i].bt, proc[i].at);
sumw = proc[0].wt = 0;
sumt = proc[0].ta = proc[0].bt - proc[0].at;
for (i = 1; i < n; i++) {
proc[i].wt = (proc[i - 1].bt + proc[i - 1].at + proc[i - 1].wt) - proc[i].at;;
proc[i].ta = (proc[i].wt + proc[i].bt);
sumw += proc[i].wt;
sumt += proc[i].ta;
}
avgwt = (float) sumw / n;
avgta = (float) sumt / n;
printf("\n\n PROC.\tB.T.\tA.T.\tW.T\tT.A.T");
for (i = 0; i < n; i++)
printf("\n %s\t%d\t%d\t%d\t%d", proc[i].name, proc[i].bt, proc[i].at, proc[i].wt, proc[i].ta);
printf("0\t");
for (i = 1; i <= n; i++) {
x += proc[i - 1].bt;
printf("%d ", x);
}
printf("\n\n Average waiting time = %0.2f\n Average turn-around = %0.2f.", avgwt, avgta);
}
//Shortest Job First - Pre-emptive
void SJF_P(processes P[], int n) {
int i, t_total = 0, tcurr, b[10], min_at, j, x, min_bt;
int sumw = 0, sumt = 0;
float avgwt = 0.0, avgta = 0.0;
processes proc[10], t;
for (i = 0; i < n; i++) {
proc[i] = P[i];
t_total += P[i].bt;
}
bubble_sort(proc, n);
for (i = 0; i < n; i++)
b[i] = proc[i].bt;
i = j = 0;
avgwt = (float) sumw / n;
avgta = (float) sumt / n;
printf("\n\n Average waiting time = %0.2f\n Average turn-around = %0.2f.", avgwt, avgta);
}
//SJF Non Pre-emptive
void SJF_NP(processes P[], int n) {
processes proc[10];
processes t;
int sumw = 0, sumt = 0;
int x = 0;
float avgwt = 0.0, avgta = 0.0;
int i, j;
for (i = 0; i < n; i++)
proc[i] = P[i];
bubble_sort(proc, n);
for (i = 2; i < n; i++)
for (j = 1; j < n - i + 1; j++) {
if (proc[j].bt > proc[j + 1].bt) {
t = proc[j];
proc[j] = proc[j + 1];
proc[j + 1] = t;
}
}
printf("\n\n PROC.\tB.T.\tA.T.");
for (i = 0; i < n; i++)
printf("\n %s\t%d\t%d", proc[i].name, proc[i].bt, proc[i].at);
sumw = proc[0].wt = 0;
sumt = proc[0].ta = proc[0].bt - proc[0].at;
for (i = 1; i < n; i++) {
proc[i].wt = (proc[i - 1].bt + proc[i - 1].at + proc[i - 1].wt) - proc[i].at;;
proc[i].ta = (proc[i].wt + proc[i].bt);
sumw += proc[i].wt;
sumt += proc[i].ta;
}
avgwt = (float) sumw / n;
avgta = (float) sumt / n;
printf("\n\n PROC.\tB.T.\tA.T.\tW.T\tT.A.T");
for (i = 0; i < n; i++)
printf("\n %s\t%d\t%d\t%d\t%d", proc[i].name, proc[i].bt, proc[i].at, proc[i].wt, proc[i].ta);
printf("0\t");
for (i = 1; i <= n; i++) {
x += proc[i - 1].bt;
printf("%d ", x);
}
printf("\n\n Average waiting time = %0.2f\n Average turn-around = %0.2f.", avgwt, avgta);
}
// Priority - Preemptive
void Priority_P(processes P[], int n) {
int i, t_total = 0, tcurr, b[10], j, x, min_pr;
int sumw = 0, sumt = 0;
float avgwt = 0.0, avgta = 0.0;
processes proc[10], t;
for (i = 0; i < n; i++) {
proc[i] = P[i];
t_total += P[i].bt;
}
bubble_sort(proc, n);
for (i = 0; i < n; i++)
b[i] = proc[i].bt;
i = j = 0;
printf(" %d", tcurr);
avgwt = (float) sumw / n;
avgta = (float) sumt / n;
printf("\n\n Average waiting time = %0.2f\n Average turn-around = %0.2f.", avgwt, avgta);
}
//Priority Non Pre-emptive
void Priority_NP(processes P[], int n) {
processes proc[10];
processes t;
int sumw = 0, sumt = 0;
float avgwt = 0.0, avgta = 0.0;
int i, j;
int x = 0;
for (i = 0; i < n; i++)
proc[i] = P[i];
bubble_sort(proc, n);
for (i = 2; i < n; i++)
for (j = 1; j < n - i + 1; j++) {
if (proc[j].prt > proc[j + 1].prt) {
t = proc[j];
proc[j] = proc[j + 1];
proc[j + 1] = t;
}
}
printf("\n\n PROC.\tB.T.\tA.T.");
for (i = 0; i < n; i++)
printf("\n %s\t%d\t%d", proc[i].name, proc[i].bt, proc[i].at);
sumw = proc[0].wt = 0;
sumt = proc[0].ta = proc[0].bt - proc[0].at;
for (i = 1; i < n; i++) {
proc[i].wt = (proc[i - 1].bt + proc[i - 1].at + proc[i - 1].wt) - proc[i].at;;
proc[i].ta = (proc[i].wt + proc[i].bt);
sumw += proc[i].wt;
sumt += proc[i].ta;
}
avgwt = (float) sumw / n;
avgta = (float) sumt / n;
printf("\n\n PROC.\tB.T.\tA.T.\tW.T\tT.A.T");
for (i = 0; i < n; i++)
printf("\n %s\t%d\t%d\t%d\t%d", proc[i].name, proc[i].bt, proc[i].at, proc[i].wt, proc[i].ta);
printf("0\t");
for (i = 1; i <= n; i++) {
x += proc[i - 1].bt;
printf("%d ", x);
}
printf("\n\n Average waiting time = %0.2f\n Average turn-around = %0.2f.", avgwt, avgta);
}
//Round Robin Scheduling
void RR(processes P[], int n) {
int pflag = 0, t, tcurr = 0, k, i, Q = 0;
int sumw = 0, sumt = 0;
float avgwt = 0.0, avgta = 0.0;
processes proc1[10], proc2[10];
for (i = 0; i < n; i++)
proc1[i] = P[i];
bubble_sort(proc1, n);
for (i = 0; i < n; i++)
proc2[i] = proc1[i];
printf("\n Enter quantum time : ");
scanf("%d", & Q);
for (k = 0;; k++) {
if (k > n - 1)
k = 0;
if (proc1[k].bt > 0)
printf(" %d %s", tcurr, proc1[k].name);
t = 0;
while (t < Q && proc1[k].bt > 0) {
t++;
tcurr++;
proc1[k].bt--;
}
if (proc1[k].bt <= 0 && proc1[k].flag != 1) {
proc1[k].wt = tcurr - proc2[k].bt - proc1[k].at;
proc1[k].ta = tcurr - proc1[k].at;
pflag++;
proc1[k].flag = 1;
sumw += proc1[k].wt;
sumt += proc1[k].ta;
}
if (pflag == n)
break;
}
printf(" %d", tcurr);
avgwt = (float) sumw / n;
avgta = (float) sumt / n;
printf("\n\n Average waiting time = %0.2f\n Average turn-around = %0.2f.", avgwt, avgta);
}
int main() {
processes P[10];
int ch, n;
do {
printf("\n\n SIMULATION OF CPU SCHEDULING ALGORITHMS\n");
printf("\n Options:");
printf("\n 0. Enter process data.");
printf("\n 1. FCFS");
printf("\n 2. SJF (Pre-emptive)");
printf("\n 3. SJF (Non Pre-emptive)");
printf("\n 4. Priority Scheduling (Pre-emptive)");
printf("\n 5. Priority Scheduling (Non Pre-emptive)");
printf("\n 6. Round Robin");
printf("\n 7. Exit\n Select : ");
scanf("%d", & ch);
switch (ch) {
case 0:
n = get_Processes(P);
break;
case 1:
FCFS(P, n);
break;
case 2:
SJF_P(P, n);
break;
case 3:
SJF_NP(P, n);
break;
case 4:
Priority_P(P, n);
break;
case 5:
Priority_NP(P, n);
break;
case 6:
RR(P, n);
break;
case 7:
exit(0);
}
} while (ch != 7);
return 0;
}

The program has some errors, which needs to be fixed.

P.S. Do not upload the compiled object file with the fixed code.

Code Cleanup!

Clean-up bad code wherever you find in the repository.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.