Write a python program that calculates the average number of words per sentence in the input text file. every sentence ends with a period (when, in reality, sentences can end with !, ", ?, etc.) and the average number of sentences per paragraph, where a paragraph is any number of sentences followed by a blank line or by the end of the text.
In: Computer Science
Assume there is a 30-byte heap. The free list for this heap has two elements on it. One entry describes the first 10-byte free segment (bytes 0-9), and one entry describes the other free segment (bytes 20-29).
Now assume we have a request for just a single byte of memory. In this case, the allocator will perform an action known as __________ to find a free chunk of memory that can satisfy the request.
|
splitting |
||
|
coalescing |
||
|
chopping |
||
|
relocating |
Refer to the previous question.
After the action is completed, how many elements are there on the free list?
|
3 |
||
|
4 |
||
|
2 |
||
|
1 |
__________ is a strategy for managing free space which results in the smallest leftover hole in memory.
|
Best fit |
||
|
Next fit |
||
|
First fit |
||
|
Worst fit |
__________ is a strategy for managing free space which results in the largest leftover hole in memory.
|
Next fit |
||
|
Best fit |
||
|
Worst fit |
||
|
First fit |
In: Computer Science
When the following statements are executed, what is the output from the child process? You may assume all variables have been properly declared and all function calls are successful.
var2 = 200;
var3 = 300;
var1 = fork();
if ( var1 > 0 )
{
printf("%d\n", var2);
}
else
{
printf("%d\n", var3);
}
|
200 |
||
|
1 |
||
|
0 |
||
|
300 |
||
|
100 |
A process that has terminated, but whose parent has not yet called wait(), is known as a __________ process.
|
zombie |
||
|
terminated |
||
|
false |
||
|
init |
In Unix/Linux, a process can run the __________ system call to load another executable to its memory image.
|
wait() |
||
|
exit() |
||
|
fork() |
||
|
exec() |
In: Computer Science
1) The document must have a small image that must appear at the position of the mouse cursor when the mouse button is clicked, regardless of the position of the cursor at that time.
2) The document contains four small paragraphs of text, stacked on top of each other, with only enough of each show so that the mouse cursor can always be placed over some part of them. When the cursor is placed over the exposed part of any paragraph, it should rise to the top to become completely visible.
Need help with two JavaScript tasks. Please do them separately and do both of them because they are linked to each other. Also please attach browser images running code. Thankyou.
In: Computer Science
Write a hangman program in c++.The game is played as follows:
1. The program selects a random word for the user to guess (Read words for the user to guess into an array of strings from a file. The words are: revolutionary, meaning, recovery, compartment, trainer, pursuit, harm, platform, error, confusion)
2. User guesses one letter at a time until either they guess the word, or they run out of guesses.
3. Select a random word from the array of strings to the word the user has to guess.
Maintain 2 char arrays:
a. availableLetters: a char array of the available letters the user can choose their guess from. Initialize availableLetters as the lowercase alphabet. As the user guesses letters, replace the corresponding guessed letter with a space to denote the letter has already been guessed.
b. visibleLetters: a char array of the not guessed letters in the word. Initialize visibleLetter to all dashes ("-"). As the user correctly guesses a letter, replace the corresponding dash(es) with the correct letter.
4. The main game loop:
a. Display information regarding the status of the game (visibleLetters, availableLetters, and the number of incorrect guesses remaining (the user gets 7 incorrect guesses)).
b. Prompt the user to enter their guess. If the user tries to guess a letter they have already guessed, inform the user and re-prompt.
c. Exit the loop if the users completely guesses the letters of the word or if the user runs out of incorrect guesses.
Note: relevant string methods you will likely need to use for this program are <string variable>.at(i) to get a character at index position and i and <string variable>.size() (or <string variable>.length() to get the number of characters in the string.
Example output:
The word to guess has 5 letters. ----- Available letters: abcdefghijklmnopqrstuvwxyz 7 incorrect guesses remaining. Please enter your guess: s s is not in the word. Too bad. 6 incorrect guesses remaining. ----- Available letters: abcdefghijklmnopqr tuvwxyz 6 incorrect guesses remaining. Please enter your guess: e Nice! e is in the word. -e--- Available letters: abcd fghijklmnopqr tuvwxyz 6 incorrect guesses remaining. Please enter your guess: r r is not in the word. Too bad. 5 incorrect guesses remaining. -e--- Available letters: abcd fghijklmnopq tuvwxyz 5 incorrect guesses remaining. Please enter your guess: r r is not an available letter -e--- Available letters: abcd fghijklmnopq tuvwxyz 5 incorrect guesses remaining. Please enter your guess: l Nice! l is in the word. -ell- Available letters: abcd fghijk mnopq tuvwxyz 5 incorrect guesses remaining. Please enter your guess: h Nice! h is in the word. hell- Available letters: abcd fg ijk mnopq tuvwxyz 5 incorrect guesses remaining. Please enter your guess: o Nice! o is in the word. Congrats, you guessed the word hello!
In: Computer Science
• Describe executive, managerial, and associate-level roles in project management??
In: Computer Science
How do I get the computerPlayer to play as the other character? This is a connect4 game that has to use the the connect4ComputerPlayer to play as the other character when playing connect4 in the text console. How can i achieve this?
Programming language is java.
import java.util.Random;
import ui.Connect4TextConsole;
public class Connect4ComputerPlayer {
public static void ComputerPlayer(){
int counter = 1;
Random rand = new Random();
int computerMove = rand.nextInt(5)
+ 1;
int column = computerMove;
while(true){
if(column >
Connect4.width){
System.out.println("Invalid column
Input.");
break;
}
if
(Connect4.board[Connect4.widthMinus][column] == '|') {
Connect4.board[Connect4.widthMinus][column] =
'X';
break;
}
else
if(Connect4.board[Connect4.widthMinus][column] == 'X' ||
Connect4.board[Connect4.widthMinus][column] == 'O'){
if(Connect4.board[Connect4.widthMinus -
counter][column] == '|'){
Connect4.board[Connect4.widthMinus - counter][column] = 'X';
break;
}
}
counter +=
1;
}
}
}
---------------------------------------------------------------------------------------------------------------------
import java.util.Scanner;
import core.Connect4ComputerPlayer;
import core.Connect4;
public class Connect4TextConsole {
public static void main(String[] args) {
Connect4 game = new
Connect4();
boolean go = true; //true player O,
false player X
Scanner keyboard = new
Scanner(System.in); //creates a new scanner, used for console
input.
do {
go = !go;
game.boardLayout();
char
player;
if(go) {
//alternates who goes with player X going first.
player = 'O';
}else {
player =
Connect4ComputerPlayer.ComputerPlayer('X');
}
System.out.print("\nPlayer"+player+" - your turn. Choose a column
number from 1-7.");
boolean valid =
false;
while(!valid)
{ //Checks if it can place a disk and if not prompts
invalid move
valid = game.dropDisk(player,
keyboard.nextInt());
if(!valid) {
System.out.print("Invalid move");
}
}
} while(!game.draw() &
!game.winCondition()); //Checks if game is either a draw or any of
the 4 win conditions are met.
game.boardLayout();
if(game.winCondition()) {
System.out.printf("Player %s Won the game", (go?"O":"X")); //prints
which player wins the game, depends on the turn that it ended
on.
}
keyboard.close(); //stop resource
leak
}
}
-----------------------------------------------------------------------------------------------------------
public class Connect4 {
static char[][] board;
final static int width = 6;
final static int height = 7;
final static int widthMinus = width - 1;
public Connect4() {
board = new
char[width][height]; //42 spots to fill size of board,
creates board.
for(int i=0; i
for(int j=0; j
board[i][j] = ' ';
}
}
}
/* public char get(int i, int j) {
return board[i][j];
} */
public void boardLayout() { //creates layout for the
board and where | go.
for(int i=0; i
System.out.printf("|");
for(int j=0; j
System.out.printf("%c|", board[i][j]);
}
System.out.println();
}
}
public boolean dropDisk(char player, int
verticalWin) { //drops disk or X/O into selected slot
verticalWin--;
boolean drop =
false;
for(int i=board.length -
1; i >= 0; i--) {
if(board[i][verticalWin] == ' ') {
board[i][verticalWin] = player;
drop = true;
break;
}
}
return drop;
}
public boolean draw() { //if the game ends in a draw,
no more spaces to fill
for(int i=0; i
if(board[0][i] == ' ')
{
return false;
}
}
return true;
}
public boolean winCondition() { //Our method called
winCondition that uses boolean values for each time a player may
win.
//if the win condition can be met,
if not then continues game. Done so by having them set as false, if
one of them turns true then game ends.
boolean horizontalWin =
false;
boolean verticalWin =
false;
boolean diagonal1Win =
false;
boolean diagonal2Win =
false;
for (int row = 0; row
< board.length; row++) { //horizontalWin if four spots are
filled with correct character horizontally
for (int col = 0; col < board[0].length - 3; col++) {
if (board[row][col] != ' '
&& board[row][col] == board[row][col +
1]
&& board[row][col] == board[row][col +
2]
&& board[row][col] == board[row][col +
3]) {
horizontalWin = true;
}
}
}
for (int col =0; col
< board[0].length; col++) { //verticalWin if four spots are
filled with correct character vertically
for (int row = 0; row < board.length - 3; row++) {
if (board[row][col] != ' '
&& board[row][col] == board[row +
1][col]
&& board[row][col] == board[row +
2][col]
&& board[row][col] == board[row +
3][col]) {
verticalWin = true;
}
}
}
for (int row = 0; row
<= 2; row++) { //diagonal1win if four spots are filled with
correct character from top right to bottom left
for (int col = 3; col <= 6; col++) {
if (board[row][col] != ' '
&& board[row][col] == board[row + 1][col
- 1]
&& board[row][col] == board[row + 2][col
- 2]
&& board[row][col] == board[row + 3][col
- 3]) {
diagonal1Win = true;
}
}
}
for (int row = 0; row
<= 2; row++) { //diagonal2win if four spots are filled with
correct character from top left to bottom right
for (int col = 0; col <= 3; col++) {
if (board[row][col] != ' '
&& board[row][col] == board[row + 1][col
+ 1]
&& board[row][col] == board[row + 2][col
+ 2]
&& board[row][col] == board[row + 3][col
+ 3]) {
diagonal2Win = true;
}
}
}
if (horizontalWin |
verticalWin | diagonal1Win | diagonal2Win) //checks if any of them
are true, if so then game ends, if not then game continues
return true;
else
return false;
}
}
----------------------------------------------------------------------------------------------------
In: Computer Science
Python language:
Write a function dice(n) that returns a list
with the results of n dice rolls conducted with a six sided dice.
Use Numpy's random number functions to do this (Hint: use
randint() within numpy's random
module).
i.e. dice(3) returns something like [2,3,5] to indicate the first
dice obtained a 2, the second a 3 etc
In: Computer Science
Use your webcam and record a movie, write a motion detection code and print the message "Motion Detected" on the original frame. Try to make a better visualization by using different masking. Using OpenCv, pandas,numpy
code be written in python,
In: Computer Science
* The course name Ethics in information Technology*
1-Using your research skills, find the meaning of the following terms, which constitute important parts of trustworthy software:
-Security
--Reliability
-Privacy
2-List your references. (You should have at least 3 references)
In: Computer Science
write a code in python for evolutionary search method for multivarible
In: Computer Science
Write a Java program that reads a name and displays on the screen.
In: Computer Science
Let Σ be a finite alphabet with n letters and let R be the relation on Σ* defined as follows: R = {(u, v): every letter in u occurs somewhere in v, and every letter in v occurs somewhere in u} Then R is an equivalence relation with exactly 2n equivalence classes.
T or F?
In: Computer Science
C++ Project 1
For this project, we are going to create our own classes and use them to build objects. For each class you will create an *.h and *.cpp file that contains the class definition and the member functions. There will also be one file called 'main.cpp' that obviously contains the main() function, and will instantiate the objects and test them.
You will create 2 new classes for this project, one will be from the list below and one will be a required 'Date' class. Here is the list:
WebSite
Shoes
Beer
Book
Song
Movie
TVShow
Computer
Bike
VideoGame
Car
The process is: take your assigned class from the list such as Book. Add to your project new files called Book.h and Book.cpp and create the new class from scratch in those files. I suggest following the simple technique for adding a class discussed in the lecture. Do not overthink. Just come up with the 3 most important data members that describe the class/object you want to build and the write 2 constructors, 3 get member functions, 3 set member functions and a toString method and you are done.
Once you have created a new class, you need to adjust the main() function to allow the user to input the data members for your class and create an object of that type. Use the toString method to then display the new object on the screen. When the project is complete, both classes/objects should be created and displayed with main().
Please do not use the same 3 data types for any class's member variables. That is, do not make them all ' int ' or all ' string '.
As for the Date class, the data members will be int day; int
year; string month; Create a Date class with 2 constructors, 3 get
member functions, 3 set member functions and a toString method.
Adjust the main() function to use the Date class.
When the user wants to build a Date object, on the screen I would
input 3 values, one for each member variable. Insert values into
the Date object then output a simple message like:
"The Date object is: March 2, 2013"
It is very important that the data input be inserted INTO the object, and pulled back OUT of the object to print the above message.
To ensure you complete each class, use this checklist:
_____ Three global variables (not the same type) _____ Two constructor methods _____ Three 'get' methods _____ Three 'set' methods _____ One 'toString' method _____ In the main function you create an object, insert values into the object, and print the object
Good Luck
Upgrade the Date Class
There are three (3) levels of understanding of objects. The first is objects are composed of variables and methods. Variables should be private and simple set/get methods allow us to insert data into and pull data back out of the objects.
The second level of understanding is objects should verify their data! To prevent 'Garbage IN, Garbage OUT' the object should NEVER allow bad data to be assigned to the member (or global) variables. Modify the set methods and constructors of the date class to make SURE the day value is always between 1 and 31, make sure the year value is between 1970 and 2099. If the user tries to assign a bad value, print a simple error message and DO NOT change the value of the variable. Example, the 'setDay' is called with the value 99, a simple message like "Value of day is not in range 1 to 31" should be output and the variable day SHOULD NOT be modified.
The third level of understanding is objects are SMART! Methods can and do generate actions and information that are not explicitly stored in the object. The date class has a string month variable that stores "jan", "feb" ... "dec". Everyone knows month could ALSO be stored as an integer value 1 ("jan") to 12 ("dec"). But we DO NOT need to store BOTH; we can generate the number when needed. Write a method: int getMonthNumber(); that returns the proper value 1-12 based on the string stored in the month variable. It should return the value -1 if the current value in the month variable is NOT valid. DO NOT store the month number in a member variable (local is OK), generate it when the method is called.
Write a method: void printDate( int format ); when it is called the format value will determine how the date is output to the screen using cout:
format 0: Mar 12, 2013
format 1: 12 Mar 2013
format 2: 3-12-2013
format 3: 3/12/13
Of course the actual values stored in the object will be output, this is only an example. Modify the main program to print the date in these additional formats. Optional: Use the int getMonthNumber(); method to check if the user enters a proper value for the month variable.
In: Computer Science
C# programming
This application will calculate the speed of an interstellar spacecraft as it accelerates though our galaxy to explore the stars. The spacecraft is using a new engine technology that continues to accelerate over time with no limit, allowing the spacecraft to reach distant areas of the galaxy at record speed. The spacecraft starts out slowly, but for each day it accelerates, it will double the speed it has attained prior to that point. The spacecraft will accelerate from 0 MPD (Miles Per Day) at launch to 1000 MPD by the end of the first day, and will have covered 500 miles (average speed of (0 + 1000)/2= 500). At the end of day two, it will be up to 2000 MPD (double day one's speed), and will have covered 2000 miles total (the previous day’s 500 miles plus the new day’s average of (1000+2000)/2)). Create an app that allows the user to enter the number of days the spacecraft has been traveling and your app will use the formulae given, plus some looping code, to tell the user what the speed of the spacecraft is (in MPD) at the end of that day. Your app will also calculate the total distance traveled by the spacecraft to the end of that day (also done with the fomulae and some looping code). Create a form with the appropriate controls to get the user input and display the answers correctly. Ensure you do proper data validation so that any mistakes the user makes entering data do not crash the program or create/allow strange results
In: Computer Science