In C++, Complete the Code & Show the output.
Schedule the following process using Shortest Job First Scheduling algorithm
Porcress | Burst time | Arrival time |
1 | 8 | 0 |
2 | 2 | 0 |
3 | 1 | 0 |
4 | 4 | 0 |
Compute the following and show the output
a) Individual Waiting time & Turnaround time
b) Average Waiting time & Turnaround time
c) Display the Gantt chart (Order of Execution)
#include
using namespace std;
//structure for every process
struct Process {
int pid; // Process ID
int bt; // Burst Time
int art; // Arrival Time
};
// Soring Process based on Burst Time Descending Order
void sort(Process a[],int n) {
//-------------Sorting
// Write Code Here
}
// function to find the waiting time for all processes
void WaitingTime(Process proc[], int n, int wt[])
{
// Write Code Here
}
// function to calculate turn around time
void TurnAroundTime(Process proc[], int n, int wt[], int tat[])
{
// Write Code Here
}
int main() {
const int n=4;
Process proc[] = { { 1, 8, 0 },
{ 2, 2, 0 },
{ 3, 1, 0 },
{ 4, 4, 0 } };
int wt[n], tat[n], total_wt = 0,total_tat = 0;
// Sort Processes based on Burst Time
sort(proc,n);
// Function to find waiting time of all processes
WaitingTime(proc, n, wt);
// Function to find turn around time for all processes
TurnAroundTime(proc, n, wt, tat);
// Write Code Here
cout<<"\n\nOrder of Execution ";
for (int i = 0; i < n; i++) {
cout<<"P"<";
}
return 0;
}
In: Computer Science
Please Use C++ to finish as the requirements.
Implement a class called SinglyLinkedList. In the main function, instantiate the SinglyLinkedList class. Your program should provide a user loop and a menu so that the user can access all the operators provided by the SinglyLinkedList class.
In: Computer Science
NASA has sent about a dozen robotic lander and rover missions to
Mars, and only seven have succeeded. One of these missions, the
Mars Polar Lander, was lost due to a problem with a sensor. A
sensor onboard the spacecraft triggered the shutdown of the
lander's engines when it thought the craft had landed on the
planet, but it had not reached the surface yet; in fact, the craft
was 131 feet above the surface when the engines were turned off,
and the resulting drop destroyed the vehicle.
For this discussion, identify and discuss at least one other
disaster that was caused by an embedded system failure, including
problems with either the hardware or software.
In: Computer Science
In: Computer Science
Array based application
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
// Function prototypes
void selectionSort(string [], int);
void displayArray(string [], int);
void readNames(string[], int);
int main()
{
const int NUM_NAMES = 20;
string names[NUM_NAMES];
// Read the names from the file.
readNames(names, NUM_NAMES);
// Display the unsorted array.
cout << "Here are the unsorted names:\n";
cout << "--------------------------\n";
displayArray(names, NUM_NAMES);
// Sort the array.
selectionSort(names, NUM_NAMES);
// Display the sorted array.
cout << "\nHere are the names sorted:\n";
cout << "--------------------------\n";
displayArray(names, NUM_NAMES);
return 0;
}
//
********************************************************
// The selectionSort function performs an ascending order *
// selection sort on an array of strings. The size *
// parameter is the number of elements in the array. *
// ********************************************************
void selectionSort(string values[], int size)
{
int startScan;
int minIndex;
string minValue;
for (startScan = 0; startScan < (size - 1);
startScan++)
{
minIndex = startScan;
minValue = values[minIndex];
for(int index = startScan + 1;
index < size; index++)
{
if
(values[index] < minValue)
{
minValue = values[index];
minIndex = index;
}
}
values[minIndex] =
values[startScan];
values[startScan] = minValue;
}
}
//
********************************************************
// The displayArray function displays the contents of *
// the array. *
// ********************************************************
void displayArray(string values[], int size)
{
for (int i = 0; i < size; i++)
cout << values[i] <<
endl;
}
//
********************************************************
// The readNames function reads the contents of the *
// "names.dat" file into the array. *
// ********************************************************
void readNames(string values[], int size)
{
int index = 0; // Array index
// Open the file.
ifstream inFile;
inFile.open("names.dat");
// Test that the file was opened.
if (!inFile)
{
cout << "Error opening names.dat\n";
exit(0);
}
// Read the names from the file into the
array.
while (index < size)
{
// Get a line from the file.
getline(inFile, values[index]);
// Increment index.
index++;
}
// Close the file.
inFile.close();
Program 1:
Use the array based application above to build an equivalent STL Vector application. Keep in mind that a vector object can be passed to functions like any other object, it is not an array.
Use the following as the input data for the names.dat file.
Collins, Bill
Smith, Bart
Allen, Jim,
Griffin, Jim
Stamey, Marty
Rose, Geri,
Taylor, Terri
Johnson, Jill,
Allison, Jeff
Looney, Joe
Wolfe, Bill,
James, Jean
Weaver, Jim
Pore, Bob,
Rutherford, Greg
Javens, Renee,
Harrison, Rose
Setzer, Cathy,
Pike, Gordon
Holland, Beth
In: Computer Science
Question:
Write a program that prompts users to pick either a seat or a price. Mark sold seats by changing the price to 0. When a user specifies a seat, make sure it is available. When a user specifies a price, find any seat with that price.
Code Provided:
(Please help me finish the line marked with "Complete this method", Please don't change other lines.)
Besides, if you could kindly mark each your line is for what purpose, I'll be very happy.
import java.util.Scanner;
public class SeatingChart
{
/**
Prints the price of seats in a grid like pattern.
@param seats a 2D array of prices
*/
public void printSeats(int[][] seats)
{
System.out.print(" ");
for (int j = 0; j < seats[0].length; j++)
{
System.out.print("s" + (j+1) + " ");
}
System.out.println();
for (int i = 0; i < seats.length; i++)
{
System.out.print("r" + (seats.length-i) + ":");
for (int j = 0; j < seats[i].length; j++)
{
System.out.printf("%3d", seats[i][j]);
}
System.out.println();
}
}
/**
Marks a seat with the price given to 0.
If there is no seat with the price, print an error message.
@param seats: the array of seat prices
@param price: the price to mark to zero
*/
public void sellSeatByPrice(int[][] seats, int price)
{
// COMPLETE THIS METHOD
// System.out.println("Sorry, no seat found with that
price.");
}
/**
Marks a seat based on a given row and seat number from input.
If seat or row numbers are invalid, print error messages.
If the seat is already occupied, print error message.
@param seats: the array of seat prices
@param rownum: row number
@param seatnum: seat number
*/
public void sellSeatByNumber(int[][] seats, int rownum, int
seatnum)
{
// COMPLETE THIS METHOD
//System.out.println("Sorry, seat already occupied.");
//System.out.println("Sorry, invalid seat number.");
//System.out.println("Sorry, invalid row.");
}
public static void main(String[] args)
{
// initial values come from problem description
int[][] seats = { { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
{ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 },
{ 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
{ 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
{ 10, 10, 20, 20, 20, 20, 20, 20, 10, 10 },
{ 20, 20, 30, 30, 40, 40, 30, 30, 20, 20 },
{ 20, 30, 30, 40, 50, 50, 40, 30, 30, 20 },
{ 30, 40, 50, 50, 50, 50, 50, 50, 40, 30 } };
SeatingChart seating = new SeatingChart();
seating.printSeats(seats);
System.out.println("Pick by <s>eat or <p>rice or
<q> to quit: ");
Scanner in = new Scanner(System.in);
String choice = in.next();
while (!choice.equals("q"))
{
if (choice.equals("s"))
{
System.out.println("Enter the row number you want:
");
int rownum = in.nextInt();
System.out.println("Enter the seat number you want: ");
int seatnum = in.nextInt();
seating.sellSeatByNumber(seats, rownum, seatnum);
}
else
{
// pick by price
System.out.println("What price do you want to buy?");
int price = in.nextInt();
seating.sellSeatByPrice(seats, price);
}
seating.printSeats(seats);
System.out.println("Pick by <s>eat or <p>rice or
<q> to quit: ");
choice = in.next();
}
in.close();
}
}
In: Computer Science
1) Using IEEE 754 format, determine the number this represents:
(64 bits) 0 11000111010 1100110000000100000000000000100000000000000000000000
2) Using complement two:
a) Represent 127
b) 127 – 499
3) How many nibbles can fit in three Word?
4) Using complement one:
a) What number represents 10001111?
In: Computer Science
Is Wireshark open-source or proprietary? What does it mean to be open-source vs proprietary in the first place? Give an example of something that is open source vs something that is proprietary in the field of networking and telecommunications.
In: Computer Science
<Python Coding>
Book : Discovering Computer Science chap3.2 (open source)
1. Write a modified version of the flower bloom program that draws a flower with 18 sides, using an angle of 100.
2. Write a program that uses a for loop to draw a square with side length 200.
3. Write a program that uses a for loop to draw a rectangle with side length 200 and width 100.
In: Computer Science
e. Task 5 (3 pts): (This task uses Strings and an if..then..elseif cascade) A program that prompts the user for their party affiliation (Democrat, Republican, or Independent) and responds accordingly with a Donkey,
In: Computer Science
Java Palindrome (Timelimit: 10seconds)
Problem Description
Write a Java program to solve the following problem.
A palindromic number is an integer that is the same when the digits are reversed. For example, 121 and 625526 are palindromic, but 625 is not a palindromic number.
Input:
The input is in ‘palindrome.txt’. The first line of the input contains the line count m (1 ≤ m ≤ 1,000), which is the number of lines that follows the first line. Each of the following lines contains an integer of n digits (1 ≤ n ≤ 5,000).
Sample input:
3.
12333.
92837465.
1000000000000000123.
Output: The output consists of m lines. Each line transforms the corresponding input line into a palindrome by concatenating the input and its digits in reversed order. To minimize the output length, you must not repeat the trailing digit (or, digits if there are multiple occurrences of the same digit) of the input integer.
Sample output:
1233321.
928374656473829.
1000000000000000123210000000000000001.
Information
1. The expected complexity is O(n).
2. You can assume that the input integers are positive, and does not start with zero. Write a code ‘A.java’ that reads ‘palindrome.txt’ and writes the output in a filecalled‘A.txt’.
3. The score will be 0 if your program does not terminate within 10 seconds.
Every palindrome of 4 digits is divisible by 11 (good to know, but not related to this assignment). Can you prove it in a midterm question?
In: Computer Science
I am having trouble figuring out how to To-Do list using java. Can anyone guide me through the steps for achieving this?
In: Computer Science
Think about a DATABASE PROJECT (BUSINESS PROBLEM) you want to do after school
show me the attributes
create a three table for it and explain each table and what it mean.
In: Computer Science
Hi there,
I am having a bit of an issue that I just can't seem to figure it out. My code is supposed to read from another file and then have an output of a number for each categorie
////////Required Output///////
Movies in Silent Era: 0\n Movies in Pre-Golden Era: 7\n Movies in Golden Era: 581\n Movies in Change Era: 3445\n Movies in Modern Era: 10165\n Movies in New Millennium Era: 15457\n
My program is:
import java.util.ArrayList; public class MovieReducerEraCount implements MediaReducer { private String result; public String reduce(ArrayList<Media> list, String era) { this.result = result; int counter = 0; for (int year = 0; year < list.size(); year++) { if (list.get(year).getName().equals(era)) { counter++; } } result = "Movies in " + era + ": " + counter; return result; } }
/////////Movie.java//////////
public class Movie extends Media { public Movie(String name, int year, String genre) { super(name, year, genre); } @Override public String getEra() { if (getYear() >= 2000) { return "New Millennium Era"; } else if (getYear() >= 1977) { return "Modern Era"; } else if (getYear() >= 1955) { return "Change Era"; } else if (getYear() >= 1941) { return "Golden Era"; } return "Pre-Golden Era"; } @Override public boolean wasReleasedAfter(Media other) { return getYear() > other.getYear(); } @Override public boolean wasReleasedBeforeOrInSameYear(Media other) { return getYear() <= other.getYear(); } }
///////move_list.txt///////
!Next? 1994 Documentary #1 Single 2006 Reality-TV #ByMySide 2012 Drama #Follow 2011 Mystery #nitTWITS 2011 Comedy $#*! My Dad Says 2010 Comedy $1,000,000 Chance of a Lifetime 1986 Game-Show $100 Makeover 2010 Reality-TV $100 Taxi Ride 2001 Documentary $100,000 Name That Tune 1984 Game-Show $100,000 Name That Tune 1984 Music $2 Bill 2002 Documentary $2 Bill 2002 Music $2 Bill 2002 Music $2 Bill 2002 Music $2 Bill 2002 Music $25 Million Dollar Hoax 2004 Reality-TV $40 a Day 2002 Documentary $5 Cover 2009 Drama $5 Cover: Seattle 2009 Drama $50,000 Letterbox 1980 Game-Show $9.99 2003 Adventure $weepstake$ 1979 Drama ' Horse Trials ' 2011 Sport '80s Videos: A to Z 2009 Music 'Allo 'Allo! 1982 Comedy 'Allo 'Allo! 1982 War 'Conversations with My Wife' 2010 Comedy 'Da Kink in My Hair 2007 Comedy
I've shorten the file.
In: Computer Science
In Visual Studios 2017, using c++, Create a class (Scores) that stores test scores (integers) in an array (assume a maximum of 100 scores). The class should have a constructor that allows the client to specify the initial value of the scores (the same initial value applies to all of them) and another default constructor that initializes them to 0. The class should have functions as follows:
1. A member function that adds a score to the array. The client must not pass the array index to the object. This member function returnsan error indication if the value is invalid – i.e. negative test scores are not permitted.
2. A member function to sort the array in ascending order.
3. A member function to compute the average of the scores in the array, and
4. A member function to display the scores.
Note that you will need to be careful about sorting the array and computing the average of the scores. Because your constructor will initialize all members of the array to be a value, you do not want to include these values in your average calculation nor in your sort function. Write a program (client) that uses the class by creating a Scores object and prompting the user for a file name. Appropriate error checking is required to ensure that the file exists and can be opened successfully. The client should read the file contents and store them in the object. The file will be formatted so that the first line contains the number of scores, and each successive line contains a score. A typical input file might contain:
4
90
85
99
94
The client should read and store the contents of the file, sort and display the scores, and compute and display the average score. All output should be labeled appropriately, and validity checking should be done on input and storage of the data. If an error is encountered in the input, the program should output an error message indicating which item was invalid, and the entire program should then terminate.
The executing program should look something like this:
In the screen above, notice that the average is displayed with decimal points. Whenever you are calculating an average, nevertruncate the decimal portion until you are told to do so. In this lab, you are not to truncate the average.
If a negative score is read in, the program might look something like this:
If a non-numeric score is read in, the program might look something like this:
In the screen above, notice that the program pauses long enough to read the error message that is displayed.
Use good coding style (modular, separate .h and .cpp class files, no globals, meaningful comments, etc.) throughout your program.
In: Computer Science