vector<process*> Delete(vector<process*> DeleteQ, int ID); vector<process*> DeleteW(vector<process*> DeleteWQ, int IDW);

Similar documents
Linked List using a Sentinel

Matt Ramsay CS 375 EXAM 2 Part 1

Computer Programming

Strings and Stream I/O

Spring 2008 Data Structures (CS301) LAB

Lecture Notes CPSC 224 (Spring 2012) Today... Java basics. S. Bowers 1 of 8

My First Command-Line Program

CS2141 Software Development using C/C++ C++ Basics

CS 216 Fall 2007 Midterm 1 Page 1 of 10 Name: ID:

Come and join us at WebLyceum

UNIX Input/Output Buffering

Streams. Rupesh Nasre.

CS 103 Unit 14 - Streams

Chapte t r r 9

Sheet 3. void SetPayRate(float rate); float CalcGrossPay(); void Validation(ifstream & in); //employee.h. //operator overloading. #include <fstream.

Introduction. Lecture 5 Files and Streams FILE * FILE *

Introduction to the C programming language

Jordan University of Science & Technology Department of Computer Science CS 211 Exam #1 (23/10/2010) -- Form A

Introduction to the C programming language

Lecture 5 Files and Streams

C++ Namespaces, Exceptions

DYNAMIC ARRAYS; FUNCTIONS & POINTERS; SHALLOW VS DEEP COPY

Operating Systems. Engr. Abdul-Rahman Mahmood MS, PMP, MCP, QMR(ISO9001:2000) alphapeeler.sf.net/pubkeys/pkey.htm

Programming with Haiku

Communication With the Outside World

CS Operating Systems Lab 3: UNIX Processes

CS 370 Operating Systems

Lab 1: First Steps in C++ - Eclipse

TR On Using Multiple CPU Threads to Manage Multiple GPUs under CUDA

Processes. Operating System Concepts with Java. 4.1 Sana a University, Dr aimen

FILE IO AND DATA REPRSENTATION. Problem Solving with Computers-I

If take all four previous run times into consideration, the prediction is

STL. Prof Tejada Week 14

BSc (Hons) Computer Science. with Network Security. Examinations for / Semester1

Image Steganalysis Image Steganography

Recursion. Contents. Steven Zeil. November 25, Recursion 2. 2 Example: Compressing a Picture 4. 3 Example: Calculator 5

Computer Systems Assignment 2: Fork and Threads Package

C++ Structures Programming Workshop 2 (CSCI 1061U)

BOOLEAN EXPRESSIONS CONTROL FLOW (IF-ELSE) INPUT/OUTPUT. Problem Solving with Computers-I

Lecture No.07. // print the final avaerage wait time.

typedef Labeling<unsigned char,short> LabelingBS; typedef Labeling<unsigned char,short>::regioninfo RegionInfoBS;

[CSE10200] Programming Basis ( 프로그래밍기초 ) Chapter 9. Seungkyu Lee. Assistant Professor, Dept. of Computer Engineering Kyung Hee University

More on Func*ons Command Line Arguments CS 16: Solving Problems with Computers I Lecture #8

Sonoma State University Computer Science Department CS 115 Fall 2010 Watts. Project 3 Part 1

s s tr t r s t st t t rt r t s r 2 st t t t s 2 r r r t t r r t t t s r t t s ss r2 r t t s s t t t r s q r t r t rs

CS 2301 Exam 3 B-Term 2011

Reading from and Writing to Files. Files (3.12) Steps to Using Files. Section 3.12 & 13.1 & Data stored in variables is temporary

Given the C++ declaration statement below, which of the following represents the value of exforsys? e) None of the above. 1K

Strings and Streams. Professor Hugh C. Lauer CS-2303, System Programming Concepts

Pointers and Strings Chapters 10, Pointers and Arrays (10.3) 3.2 Pointers and Arrays (10.3) An array of ints can be declared as

- It computes the Standard Deviation by calculating the difference of each channel (R,G,B and A) of a pixel.

C:\Temp\Templates. Download This PDF From The Web Site

DELHI PUBLIC SCHOOL TAPI

CS 103 Unit 14 - Streams

Data Structures. Lecture 04 Sohail Aslam AL 1

Lab 8. Follow along with your TA as they demo GDB. Make sure you understand all of the commands, how and when to use them.

Lab: Supplying Inputs to Programs

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

Topic 8: Lazy Evaluation

1. Which of the following best describes the situation after Line 1 has been executed?

Multiple Choice (Questions 1 14) 28 Points Select all correct answers (multiple correct answers are possible)

primitive arrays v. vectors (1)

3/12/2018. Structures. Programming in C++ Sequential Branching Repeating. Loops (Repetition)

Unit 14. Passing Arrays & C++ Strings

CS 150 Lab 10 Functions and Random Numbers

Installing and Using Xcode

What Is A Process? Process States. Process Concept. Process Control Block (PCB) Process State Transition Diagram 9/6/2013. Process Fundamentals

CS 103 Unit 15. Doubly-Linked Lists and Deques. Mark Redekopp

Concurrency. Stefan D. Bruda. Winter 2018

A Quick Look at C for C++ Programmers

Data Structures Lab II. Binary Search Tree implementation

Multiple Choice (Questions 1 13) 26 Points Select all correct answers (multiple correct answers are possible)

CALIFORNIA STATE UNIVERSITY, SACRAMENTO College of Business Administration. MIS Information Systems II. C++ Solution to Homework 4

THE STANDARD TEMPLATE LIBRARY (STL) Week 6 BITE 1513 Computer Game Programming

Announcements. CSCI 334: Principles of Programming Languages. Lecture 18: C/C++ Announcements. Announcements. Instructor: Dan Barowy

A SHORT COURSE ON C++

CSCE 110 PROGRAMMING FUNDAMENTALS

C++ Lab 03 - C++ Functions

Advanced Flow Control CS 16: Solving Problems with Computers I Lecture #5

Programación de Computadores. Cesar Julio Bustacara M. Departamento de Ingeniería de Sistemas Facultad de Ingeniería Pontificia Universidad Javeriana

CS Operating system Summer Midterm I -- July 11, 2017 You have 115 min (10:00am-11:55pm). Good Luck!

Topics. Functions. Functions

Overloading Functions & Command Line Use in C++ CS 16: Solving Problems with Computers I Lecture #6

CS 251 Practice Final Exam R. Brown May 1, 2015 SHOW YOUR WORK No work may mean no credit Point totals will be adjusted to a 120 point scale later

LAB #8. Last Survey, I promise!!! Please fill out this really quick survey about paired programming and information about your declared major and CS.

ECE 462 Object-Oriented Programming using C++ and Java Design Issues and Multiple Inheritance in C++

Functions. CS111 Lab Queens College, CUNY Instructor: Kent Chin

Program template-smart-pointers-again.cc

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

1 #include <iostream> 2 #include <fstream> 3 #include <string> 4 #include <cstring> // for string tokenizer and c-style string processing 5 #include

Lecture No.04. Data Structures

Grades. Notes (by question) Score Num Students Approx Grade A 90s 7 A 80s 20 B 70s 9 C 60s 9 C

Program Organization and Comments

C++ Lab 04 - File I/O, Arrays and Vectors

Review Questions for Final Exam

C programming for beginners

Installing and Using Dev-C++

CS302 - Data Structures using C++

2) F_TEST.CPP) //f_test.cpp

CS 240 Data Structure Spring 2018 Exam I 03/01/2018

Transcription:

Matt Ramsay & Robert Brown CS 470 Process Management Project 2/15/02 File: main.cpp Uncommented Code: /*********************************** ** Matthew Ramsay Robert Brown ** ** CS470 Dr. Deborah Hwang ** ** Process Management Program ** ***********************************/ #include <iostream.h> #include <stdio.h> #include <stdlib.h> #include <vector> #include <fstream.h> #include "pmpclass.h" using namespace std; /************************** ** Function Prototypes ** **************************/ vector<process*> Delete(vector<process*> DeleteQ, int ID); vector<process*> DeleteW(vector<process*> DeleteWQ, int IDW); /**************** ** Main Code ** ****************/ int main(int argc, char* argv[]) if (argc!= 3) cout << "You schmuck! This program was hard enough to write, you can at least call it correctly!\n"; exit(1); vector<process*> ReadyQ; vector<process*> WaitQ;

vector<process*> DeleteQ; ifstream in; char option; int n,b,p,temp,waitid; char *q = argv[2]; int quantum = atoi(q); process * tempprocess = NULL; process * tempp = NULL; in.open(argv[1]); while(1) in >> option; if(in.eof()) exit(1); switch(option) case 'C' : case 'c' : in >> n; in >> b; if(readyq.empty()) p = 0; p = ReadyQ[0]->id; cout << option << " " << n << " " << b << " " << p << endl; ReadyQ.push_back(new process(n,b,p,quantum)); tempprocess = ReadyQ.back(); cout << "PID " << tempprocess->id << " " << tempprocess->burst << " put on Ready Queue" << endl;

case 'D' : case 'd' : in >> n; cout << option << " " << n << endl; if(readyq.size()!= 0) ReadyQ = Delete(ReadyQ,n); WaitQ = DeleteW(WaitQ,n); case 'I' : case 'i' : cout << option << endl;

case 'W' : case 'w' : in >> n; cout << option << " " << n << endl; cout << "PID " << ReadyQ[0]->id << " " << ReadyQ[0]->burst << " placed on wait queue" << endl; ReadyQ[0]->waitNumber = n; ReadyQ[0]->activeTime = quantum; tempp = ReadyQ[0]; ReadyQ.erase(ReadyQ.begin()); WaitQ.push_back(tempP); case 'E' : case 'e' : in >> n; waitid = n; cout << option << " " << n << endl;

case 'X' : case 'x' : cout << option << endl << endl; cout << "Current state of simulation: " << endl; cout << "No processes currently running" << endl; cout << "Current Process: PID " << ReadyQ[0]->id << " " << ReadyQ[0]->burst << endl; if(readyq.size() == 1) cout << "Ready Queue: empty" << endl; cout << "Contents of Ready Queue: " << endl; for(int m = 1; m < ReadyQ.size(); m++) cout << " PID " << ReadyQ[m]->id << " " << ReadyQ[m]->burst << endl; if(waitq.size() == 0) cout << "Wait Queue: empty" << endl; cout << "Contents of Wait Queue: " << endl; for(int n = 0; n < WaitQ.size(); n++)

cout << " PID " << WaitQ[n]->id << " " << WaitQ[n]->burst << " waiting on EID " << WaitQ[n]->waitNumber << endl; exit(1); if(waitq.size()!= 0) for(int i = 0; i < WaitQ.size(); i++) if(waitq[i]->waitnumber == waitid) tempp = WaitQ[i]; WaitQ.erase(WaitQ.begin() + i); cout << "PID " << tempp->id << " " << tempp->burst << " put on Ready Queue" << endl; ReadyQ.push_back(tempP); if(readyq[0]->activetime == 0) ReadyQ[0]->activeTime = quantum; cout << "PID " << ReadyQ[0]->id << " " << ReadyQ[0]->burst << " put on Ready Queue" << endl; tempp = ReadyQ[0]; ReadyQ.erase(ReadyQ.begin()); ReadyQ.push_back(tempP); if (ReadyQ.size()!= 0) if(readyq[0]->burst == 0) n = ReadyQ[0]->id; ReadyQ = Delete(ReadyQ,n); ReadyQ = DeleteW(ReadyQ,n); cout << endl;

in.close(); return 0; /**************** ** Functions ** ****************/ vector<process*> Delete(vector<process*> DeleteQ, int ID) int k; if(deleteq.size()!= 0) for(int j = 0; j < DeleteQ.size(); j++) k = DeleteQ[j]->parentNumber; if(deleteq[j]->parentnumber == ID) cout << "PID " << DeleteQ[j]->id << " deleted!" << endl; DeleteQ.erase(DeleteQ.begin() + j); DeleteQ = Delete(DeleteQ, k); return DeleteQ; if(deleteq[j]->id == ID) cout << "PID " << DeleteQ[j]->id << " deleted!" << endl; DeleteQ.erase(DeleteQ.begin() + j); return DeleteQ; return DeleteQ; vector<process*> DeleteW(vector<process*> DeleteWQ, int IDW) int k; if(deletewq.size()!= 0) for(int j = 0; j < DeleteWQ.size(); j++) k = DeleteWQ[j]->parentNumber; if(deletewq[j]->parentnumber == IDW)

cout << "PID " << DeleteWQ[j]->id << " deleted!" << endl; DeleteWQ.erase(DeleteWQ.begin() + j); DeleteWQ = Delete(DeleteWQ, k); return DeleteWQ; if(deletewq[j]->id == IDW) cout << "PID " << DeleteWQ[j]->id << " deleted!" << endl; DeleteWQ.erase(DeleteWQ.begin() + j); return DeleteWQ; return DeleteWQ;