31/03/2023

FCFS Scheduling Program in C++ With Arrival Time And Gantt Chart
First Come First Served (FCFS) is a Non-Preemptive scheduling algorithm. FCFS follow the FIFO (First In First Out) rules which means when a process comes to the CPU for execution. The CPU executes the process without checking anything like in a primitive scheduling algorithm. In other words. The First process will be executed either because the execution time of the first process is higher than others.

FCFS Scheduling Program in C++ With Arrival Time And Gantt Chart

The first process runs another process should wait for its turn. Below is the Brief description or Q&A of the FCFS Non-Preemptive scheduling algorithm.

FCFS Scheduling Program in C++ With Arrival Time And Gantt Chart


#include <stdio.h>
#include <string.h>

int strToint(char[]);

int main()
{
	/*FCFS Scheduling Program in C++ With Arrival Time And Gantt Chart*/

	cout << "=====================================";
	cout << "\nVisit - www.programmingwithbasics.com";
	cout << "\n=====================================";

	while (1)
	{
		char str[10];
		int intNum;

		printf("\n\nEnter Integer Number: ");
		scanf("%s", str);

		intNum = strToint(str);

		if (intNum == 0)
		{
			printf("\nEnter The Number Not String\n\n");
		}
		else
		{
			printf("\n\nEquivalent Integer Value: %d", intNum);
		}
	}

	return 0;
}

int strToint(char str[])
{
	int i = 0, sum = 0;

	while (str[i] != '\0')
	{
		if (str[i] < 48 || str[i] > 57)
		{
			printf("\n\nCan't Convert Into Integer");
			return 0;
		}
		else
		{
			sum = sum *10 + (str[i] - 48);
			i++;
		}
	}

	return sum;

}

return sum;

}

First Come First Serve Scheduling


  • What is the First Come First Serve (FCFS) Scheduling?
  • How to Calculate Turn-Around Time?
  • How to Calculate Waiting Time?
  • First Come First Serve Example

What is the First Come First Served (FCFS) Scheduling?



First Come First Served (FCFS) is a Non-Preemptive scheduling algorithm for process execution in an operating system and easy to understand and has poor performance (waiting time is higher), If the first process takes more time for execution than until finish first process rest of the process has to wait.

How to Calculate Turn-Around Time?


Turn Around Time = Completion Time – Arrival Time

With the help of this formula, we can calculate a Turn Around Time of all processes in Queue.

How to Calculate Waiting Time?.


Waiting Time = Turn Around Time – Burst Time

This formula is used for calculating the waiting time for the rest of the process.

FCFS Example


We are taking 5 processes whose CBT, or Burst Time Is 4, 9, 8, 3, and 7 respectively and the output is given below.

Enter The Total Number of Processes: 5

Enter CBT of Process:
4
9
8
3
7

=======================
Gantt. Chart
=======================
[P1] [P2] [P3] [P4] [P5]
--------------------------------------

0 4 13 21 24

==================================
Process CBT Waiting Time Turn Around Time
==================================

[p1] 4 0 4
[p2] 9 4 13
[p3] 8 13 21
[p4] 3 21 24
[p5] 7 24 31

Average Awating Time: 12.4

Average Turn Around Time: 18.6

The Output of FCFS Scheduling Program With Arrival Time


The Output of FCFS Scheduling Program With Arrival Time

Similar to FCFS Scheduling

30/03/2023

Preemptive Priority Scheduling Program in C++ With Arrival Time
Write a Preemptive Priority Scheduling Program in C++ With Arrival Time. Preemptive priority scheduling C++  with Gantt Chart. Preemptive scheduling hackerrank solution. Priority scheduling in OS.

Preemptive Priority Scheduling Program in C++ With Arrival Time

Preemptive Priority Scheduling Program in C++ With Arrival Time


#include <cstdio>
#include <conio.h>
#include <iostream>
/* Preemptive Priority Scheduling C++  with Gantt Chart*/
int main()
{
	int x, n, p[10], pp[10], pt[10], w[10], t[10], awt, atat, i;
	printf("Enter the Number of Process: ");
	scanf("%d", &n);
	
	printf("\n Enter Process : Time Priorities \n");
	for (i = 0; i < n; i++)
	{
		printf("\nProcess no %d : ", i + 1);
		scanf("%d  %d", &pt[i], &pp[i]);
		p[i] = i + 1;
	}

	for (i = 0; i < n - 1; i++)
	{
		for (int j = i + 1; j < n; j++)
		{
			if (pp[i] < pp[j])
			{
				x = pp[i];
				pp[i] = pp[j];
				pp[j] = x;
				x = pt[i];
				pt[i] = pt[j];
				pt[j] = x;
				x = p[i];
				p[i] = p[j];
				p[j] = x;
			}
		}
	}

	w[0] = 0;
	awt = 0;
	t[0] = pt[0];
	atat = t[0];
	for (i = 1; i < n; i++)
	{
		w[i] = t[i - 1];
		awt += w[i];
		t[i] = w[i] + pt[i];
		atat += t[i];
	}

	printf("\n\n Job \t Burst Time \t Wait Time \t Turn Around Time   Priority \n");
	for (i = 0; i < n; i++)
		printf("\n %d \t\t %d  \t\t %d \t\t %d \t\t %d \n", p[i], pt[i], w[i], t[i], pp[i]);
	awt /= n;
	atat /= n;
	printf("\n Average Wait Time : %d \n", awt);
	printf("\n Average Turn Around Time : %d \n", atat);
	getch();
}

The Output of the Priority Scheduling Program


The Output of the Priority Scheduling Program

Similar to Priority Scheduling


Shortest Job First Scheduling Program in C++ With Gantt Chart
Write a Program to Shortest Job First Scheduling Program in C++ With Gantt Chart. SJF Non-Preemptive scheduling program in C++ with Gantt chart. Shortest Job First (SJF) is a Non- primitive Scheduling Algorithm we also know SJF as Shortest Job Next (SJN). Shortest Job First (SJF) is also a pre-emptive scheduling algorithm, which means It is compulsory for the CPU to know the next process and how much time the process will take for executing.

Shortest Job First Scheduling Program in C++ With Gantt Chart

In simple word, we can say that Shortest Job First (SJF) is executed (Put on CPU priority) the only process those have a minimum time for execution.

Shortest Job First Scheduling Program in C++ With Gantt Chart


#include <bits/stdc++.h>
using namespace std;

int main()
{
	/*Shortest Job First Scheduling C++ */

	int p, i, j, sum = 0, min, index;
	float awt = 0, atat = 0;

	cout << "\nEnter The Total Number of Process: ";
	cin >> p;

	int proc[p];

	int *cbt = new int[p];
	int *wt = new int[p];
	int *gc = new int[p];
	int *tat = new int[p];
	int *tmp = new int[p];

	cout << "\nEnter CBT of Process:\n";

	for (i = 0; i < p; i++)
	{
		cin >> cbt[i];
		tmp[i] = cbt[i];
	}

	sort(cbt, cbt + p);

	cout << "\n========================================================\n";
	cout << "\t\tShortest Job First Gantt. Chart";
	cout << "\n========================================================\n";

	for (j = 0; j <= p; j++)
	{
		min = 100;
		for (i = 0; i < p; i++)
		{
			if (min > tmp[i] && tmp[i] != -1)
			{
				min = tmp[i];
				index = i;
			}
		}

		gc[j] = sum;
		wt[j] = sum;
		sum += tmp[index];
		tat[j] = sum;
		tmp[index] = -1;

		if (j == p)
			break;
		cout << 'P' << index + 1 << "  |  ";
		proc[j] = index + 1;
	}

	cout << "\n--------------------------------------------------------\n";

	sum = 0;

	for (j = 0; j <= p; j++)
	{
		if (gc[j] < 10)
			cout << 0;
		cout << gc[j] << "    ";
		sum += gc[j];
	}

	cout << endl;

	atat = (sum *1.0) / p;

	cout << "\n--------------------------------------------------------";
	cout << "\nProcess\t\tCBT\tWaiting Time\tTurn Around Time";
	cout << "\n--------------------------------------------------------\n";

	for (i = 0; i < p; i++)
	{
		cout << "P[" << proc[i] << "]\t\t" << cbt[i] << "\t" << wt[i] << "\t\t" << tat[i] << endl;
		awt = awt + wt[i];
	}

	awt = (awt *1.0) / p;

	cout << "\n\nTotal Waiting Time: " << awt;
	cout << "\n\nTotal Turn Around Time: " << atat << endl;

	return 0;
}

Shortest Job First Scheduling


  1. What is the Shortest Job First (SJF) Scheduling Algorithm?.
  2. How to Calculate Turn-Around Time?.
  3. How to Calculate Waiting Time?.
  4. SJF Scheduling Example

1. What is the Shortest Job First (SJF) Scheduling Algorithm?.


Shortest Job First (SJF) is a pre-emptive Scheduling Algorithm for execution Process in Minimum time order means, a process has a minimum time for execution execute first and then second minimum time taking process. SJF is an alternative to FCFS(First Come and First Serve) cause it reduces the average waiting time and is also good for Batch systems.

Non-Preemptive scheduling program in C++ with Gantt chart

2. How to Calculate Turn-Around Time in SJF Scheduling?.


Turn Around Time = Completion Time – Arrival Time

Total Turn Around Time = Turn Around Time / Total Number of Process

With the help of this formula, we can calculate a Turn Around Time of all processes in Queue.

3. How to Calculate Waiting Time in SJF Scheduling?.


Waiting Time = (Turn Around Time – Burst Time)

Total Waiting Time = Waiting Time / Total Number of Process.

4. SJF Scheduling Example


We are taking 4 processes whose CBT, or Burst Time Is 6, 8, 7, and 3 respectively and the output is given below.

Enter The Total Number of Processes: 4

Enter CBT of Process:
6
8
7
3

========================================================
Gantt. Chart
========================================================

P4 | P1 | P3 | P2 |
--------------------------------------------------------
00 03 09 16 24

--------------------------------------------------------
Process CBT Waiting Time Turn Around Time
--------------------------------------------------------

P[4] 3 0 3
P[1] 6 3 9
P[3] 7 9 16
P[2] 8 16 24

Total Waiting Time: 7

Total Turn Around Time: 13

The Output of Shortest Job First Scheduling Non-Preemptive


The Output of Shortest Job First Scheduling Program in C++ With Gantt Chart

Similar to Shortest Job First Non-Preemptive


29/03/2023

Technical SEO For Website Which Can Skyrocket Your Business: The Benefits
If you are a website owner, then you need to understand that without technical SEO, there's no way you can grow that website of yours. It's really as simple as that - yes, you need an effective content strategy. But without a solid SEO strategy, it is almost impossible to increase your domain authority. As a result, boosting your business also becomes an impossibility of sorts.

It is also possible that you have an e-commerce website where you sell products. In that case, as well, you need to use a technical SEO strategy to beat your competition on search engine rankings - you would not want your target audience to end up finding your competitors' products. This is precisely why you need a search engine optimization strategy for boosting your business.

Technical SEO For Website

Stay tuned to find out about the benefits that a solid technical SEO has to offer if you want your business to skyrocket.

Technical SEO For Website Which Can Skyrocket Your Business


Of course, there are relevant factors when it comes to determining whether your website is SEO-optimized - from an SEO-driven website design to SEO-friendly content; there's more than one factor that's vital for optimization. Today, we will solely focus on technical SEO and the benefits it brings to the table.

So without wasting any more time, scroll down and find out the benefits of technical SEO for your website, especially if your business goal is to boost your business.

Increase Reach Across All Channels


You are creating search engine-friendly content to enable powerful search engines such as Google or Bing or even others to discover your content easily, index the same, and eventually display it. And that does make sense since it is reasonable to assume that this way, more of your audience will find your content as well.

Undoubtedly, following all writing and publishing SEO checklists is certainly one way to keep things safe. With an increase in your website's reach across various channels, you will start experiencing increased engagement rates and potential sales.

Increase Search Engine Ranking


In order to boost your website's performance on search engines, you have to focus on increasing your content's ranking on search engines. And that's possible when a powerful search engine like Google actually understands your content - if your content is simple and easily understandable, then it does not just have a better shot of appearing high up in different search results but also includes something cool like 'position zero.'

Read: On-Page and Off-Page SEO for Website Design

This obviously means your content is not just on top of the general search results. But it also means that your content is featured in relatively more visible sections like 'featured snippets' and 'people also ask' sections. After all, getting your content featured here is equivalent to obtaining plenty of Google gold dust.

Rich Snippets in Search Results


Once your content starts appearing on different search results, you would obviously want more than your title and meta description to appear - you would want your videos, call-to-actions, ratings, images, etc., to appear as well.

Anything that can make search results show your content and, more importantly, your website is a lucrative bonus, especially when it's anything more than your competitors. Always remember, a more prominent or enticing result will always mean more reach and engagement.

Improved Display and Layout Across Social Media


Automating the entire process will eliminate the issue of wrong images or even text snippets appearing once your content is shared on social media platforms. Doing this will help you to ensure that there’s a single consistent message spread across all platforms.

Read: 9 Free Best SEO Plugin For WordPress

If you haven't automated which images will be utilized for social media previews or simply on Twitter or Facebook, then you will have to guess from the extensive list of images that are available on the given page. Automating any particular field will provide you with full control - you will be able to see what people can ACTUALLY see on social platforms once your pages start getting returned.
 

And It's A Wrap!


And that's a wrap on the benefits of technical SEO that can help you to boost your website and, subsequently, your business. But what do you think about these benefits? Will these benefits help you to boost your business?

If you do think so, then don't waste any further time and start thinking about optimization - SEO has become an unavoidable part of digital life.

In the meantime, if you are already implementing an effective technical SEO strategy for your website, feel free to share your related experiences in the comments below.

28/03/2023

Messages Order Hackerrank Solution in C++ | Debugging
Messages Order Hackerrank Solution in C++. In real-life applications and systems, a common component is a messaging system. The idea is that a sender sends messages to the recipient. The messages might be sent for example over the network. However, some network protocols don't guarantee to preserve the order of sent messages while they are received by the recipient. 

For example, if someone sends a text message hello, hi and what's up, they might be received in the order what's up, hello, hi. In many systems the expected behaviour is to preserve the order, so the order of sent messages is the same as the order of received messages. 

In this problem, the task is to implement a software layer over the top of a network protocol sending messages in arbitrary order, in such a way that the sent messages are printed by the recipient in the order they were sent.

In the template code below, there are implementations of classes Recipient and Network. Your task is to implement classes Message and MessageFactory according to the below specification:

Messages Order Hackerrank Solution in C++

Class Message is required to store a text value of type std::string and provide a public getter const string& get_text() which is expected to return this text value. Besides that, it should implement the < operator that will be used in the fix_order() method of the recipient to fix the order of received messages. 

Feel free to implement any other methods and class/instance variables. In particular, you can implement any additional constructors, but make sure that you provide an empty constructor, i.e. the one without arguments.

Class MessageFactory is required to have an empty constructor and implement a method Message create_message(const string& text) that is expected to return a Message object storing the value of the text argument. Feel free to implement any other methods and class/instance variables of this class.

The locked code template will act as follows. First, it creates objects message_factory and recipient. These objects are of types MessageFactory and Recipient respectively. Then, it reads messages from the standard input, and then it will use the provided Network class to simulate sending the messages to the recipient. 

The Network class randomly shuffles the passed messages and then it passes them to the recipient using the recipient.receive(const Message&) method. After all, messages are delivered, the recipient uses its own method print_messages to print all the received messages to the standard output, and just before doing that, it uses its own fix_order method to fix the order of retrieved messages. 

For that purpose, it uses the std::sort() algorithm to sort the std::vector of received messages and this is the reason your Message class implementation has to provide the < operator.

Input Format

The input is read by the provided locked code template. It contains several lines of text messages in the order that they will be sent over the network.

Constraints

There will be at most 10 lines in the input.
Each line will contain at most 20 characters

Output Format

The output should be produced by the provided locked code template and it is produced as described in detail in the statement. The expected order of printed messages is the same as the one in the input.

Sample Input 0

Alex
Hello Monique!
What'up?
Not much :(

Sample Output 0

Alex
Hello Monique!
What'up?
Not much :(

Submit your solution here: Click here

Messages Order Hackerrank Solution in C++


#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

class Message
{
	private:
		string text;
	static int nbMessages;
	int rank;
	public:
		Message() {}

	Message(const string &ptext): text(ptext)
	{
		nbMessages++;
		rank = nbMessages;
	};

	const string &get_text()
	{
		return text;
	}

	const int &get_rank()
	{
		return rank;
	}

	bool operator < (Message &);
};

bool Message::operator < (Message & msg)
{
	if (rank <= msg.get_rank()) return true;
	return false;
}

int Message::nbMessages = 0;

class MessageFactory
{
	public:
		MessageFactory() {}

	Message create_message(const string &text)
	{
		Message msg(text);
		return msg;
	}
};

class Recipient
{
	public:
		Recipient() {}

	void receive(const Message &msg)
	{
		messages_.push_back(msg);
	}

	void print_messages()
	{
		fix_order();
		for (auto &msg: messages_)
		{
			cout << msg.get_text() << endl;
		}

		messages_.clear();
	}

	private:
		void fix_order()
		{
			sort(messages_.begin(), messages_.end());
		}

	vector<Message> messages_;
};

class Network
{
	public:
		static void send_messages(vector<Message> messages, Recipient &recipient)
		{
			// simulates the unpredictable network, where sent messages might arrive in unspecified order
			random_shuffle(messages.begin(), messages.end());
			for (auto msg: messages)
			{
				recipient.receive(msg);
			}
		}
};

int main()
{
	MessageFactory message_factory;
	Recipient recipient;
	vector<Message> messages;
	string text;
	while (getline(cin, text))
	{
		messages.push_back(message_factory.create_message(text));
	}

	Network::send_messages(messages, recipient);
	recipient.print_messages();
}

The Output of Messages Order Hackerrank Solution


The Output of Messages Order Hackerrank Solution

Similar to Messages Order