C/C++ :: Round Robin Execution With Gantt Chart - Arrival Time And Burst Time
Mar 10, 2015
This is a round robin execution. with gantt chart. arrival time and burst time. I think there is an error in my formula to get the right answer,i cant resolve it but my program is running. What is the code or the right formula??
#include<stdio.h>
int main(){
int i,j=0,n,time,remain,flag=0,ts;
int sum_wait=0,sum_turnaround=0,at[10],bt[10],rt[10];
int ganttP[50],ganttStartTime[50];
printf("Enter no of Processes : ");
scanf("%d",&n);
remain=n;
I've recently completed a fully functional round robin algorithm for a class, however upon running a myriad of test cases I found where mine fails. I think it best to show with an example:
Currently what happens is this, it runs perfectly from process 1 through process 3. However once it reaches process 4 it does the appropriate thing and adjusts my total processing time (q variable) to the arrival time of process 4. Great! But then, it rolls over to check the queue again and it's bringing in process 5, changing q to it's arrival time. Then it proceeds to swap them in and out due to them both now being in the queue and time quantums/slices running out.
My question is this: How/where do I put a lock on the while loop that runs the simulated scheduler (round robin in this instance) to not grab the next process when there's a time gap in between each process.
This specifically is the two lines that I can't seem to get working as they should:
if(arrival[i]>q) q=arrival[i];
FULL CODE BELOW
#include <iostream> using namespace std; void RR(int n, int burst[], int arrival[], int throughput) {
Task1 started in : 2 in milliseconds Task1 finished in : 4015 in milliseconds.
The problem is, that if i count the time with an external device, just like the timer of my watch or my cellphone s,the total time is 4,8 or 4,9 seconds, which i wouldn t expect that to happen.
The first thing i ve thought, is that it takes the ThreadPool about 800msec or 1 sec to create the thread so as to execute this task, but even if it is so, shouldn t the stopwatch count the time precisely?So , why is there a deviation between an external timer and the stopwatch ?
#include<iostream> #include<ctime> #include<boost/progress.hpp> using namespace std; class parent { public: virtual void dynamic_display(){
[Code] ....
I am getting the following as output
Calculating....Static Function is called1times The number of processor clicks is0time is0 Calculating....Dynamic function is called1times The number of processor clicks is0time is0 Static Function is called2times Dynamic function is called2times Static Function is called3times Dynamic function is called3times
I am actually trying to calculate the time to execute a statically binding method and a dynamically binded one.consider only the first four lines in my output. Why am i not getting the actual result.
I wrote program for Sequential matrix multiplication .But after execution for any input value( ex. 100,150,400) it shows the execution time is 0.000 msec.
#include <stdio.h> #include <math.h> #include <sys/time.h> void print_results(char *prompt, int N, float *a); int main(int argc, char *argv[])
I like to read the table and get the all PNAME into the combo box.
Using the below code i can read the table, but while loop takes 2 seconds to read 10 records in the Profilemaster table. How can i reduce the reading time?
My Code is void MainScreen::OnreadProfileName() { CDatabase database; CString SqlString; CString sDsn; CString pname;
how I would easily round a double or a float to the nearest cent. It was easy enough to do it in visual basic or java, But i cannot figure out how to do it in C.
Its as if im not inputting the values into the dynamic arrays in int main.
#include <iostream> using namespace std; void Calc(int a_anScores[], int a_anPerc[], int a_nTotal){ for( int iii = 0; iii < a_nTotal; ++iii){ a_anScores[iii] = (a_anScores[iii] * (a_anPerc[iii]/100)); } int nGrade=0;
I have created this code with the classes for time and message. Basically the point of this code is to give the information of the sender, recipient, time, and message and im having issues with the time part.
I am trying to make this while loop cut out / self break after 3 seconds. It is part of a simple game I am creating that gives the users 3 seconds to react otherwise it moves on to the next part.
All I need is it to end after 3 seconds, the rest of the code is working fine.
This sort of thing:
long startTime = System.currentTimeMillis(); //fetch starting time while(false||(System.currentTimeMillis()-startTime)<10000) If it IS for C, then I implemented it wrong or something.
I suspect it is a logical error but I can't pinpoint it. The assignment is to input a time of day in 24 hour format, pattern match with scanf, and print out the closest arrival and departure times for that time. The arrival and departure times are in minutes past midnight in a constant array. I am getting no bugs but the program is not giving correct values.
/* filename: hw25.c * Purpose: Finds the closest arrival and departure times */ #include <stdio.h> #include <stdlib.h> #define N 8 #define HOUR 60 void find_closest_flight(int desired_time, int *departure_time, int *arrival_time);
I just spent 3 hours writing and debugging 37 lines of code. Is this normal or am I "below average" in coding abilities. I come from a C background and decided to write C++ code that I finally got right as shown below for the specific example:
I think it was more the learning along the way that consumed atleast 75% of my time for this specific case. But then again, I read that programming always entails learning along the way and so its somehow no excuse for the long time taken in this specific case.
So as a matter of interest, what pace do all of you operate on, on average? i.e. LOC/day, Debugs per day or any other indicator of productivity?
I tried to write a simple program to calculate monthly yield, APR, and principle in various directions. Anyway, here's some code to get the APR from the principle and monthly yield. When I run it though, it spits 0 at me every time! What the problem is; the other functions work just fine and the code line for the APR calculation is just what it ought to be - I see neither a math nor tech problem here.
Here is the offending function:
Code: void calculateAPR() { int principle, monthlyYield, apr; cout<<" Please input the principle:"; cin>>principle; cin.ignore();
I am looking for simple code that subtract two time interval. I have time t1=5hour 30 minute and other time in 24 hour format. This code i written but it not working as expected. it not printing 5:30 minute subtract
Code: main() { intTime1; intTime2; int hour=10; int minute=5; int second=13; int h;int m; doubleNtime;
The issue is that I am trying to run a code which can trigger different timers at the same time. That is, when 3 is typed by the user, the firstimer is triggered. If before expiration another 3 is introduced, the second timer will be launched, and the difference between both triggers will be shown. Under this circumstance, timer_gettime only works once. I tried all the things I could imagine but still, it_value_tv_sec and _nsec return zero after the first expiration.
-Theoretically, and following the manuals, once the timer is restarted the gettime function should work as it does the first time. -I have also tried to removed the timer and start it again, but in this case the timers are still being triggered, but the gettime outputs(even the first time) are nonsense.
Here is the code I am testing: [CODE]#include<stdio.h>
I created a program to display time continuously so it auto updates every sec but the issue is i cant integrate the code in the main program because to make time update continuously it needs a loop a infinite loop so none of the rest program gets to work. My q is : is it possible to display time continuously and make the rest of program continue normally? like a multi thread program because i want to display time every sec in the bottom of program. By the way this is console app not gui
Write a program to convert the time from 24-hour notation and vice versa. Your program must be menu driven, giving the user the choice of converting the time between the two notations. Furthermore your program must contain at least the following function : a function to convert the time from 24-hour notation to 12-h notation, a function to convert the time from 12-hour notation to 24-hour notation, a function to display the choices, function(s) to get the input, and function(s) to display the results.
I have a code to check the last time modification of a file using "gmtime". Is it possible to remove the seconds in the result?
Here is my code:
struct tm* clock;// create a time structure struct stat attrib;// create a file attribute structure stat("test.txt", &attrib);// get the attributes of afile.txt clock = gmtime(&(attrib.st_mtime));// Get the last modified time and put it into the time structure