Practice Problem 8.7 (solution page 798)
Write a
linux>./snooze 5
CTRC+C
Slept for 3 of 5 secs.
linux
User hits Ctrl+C after 3seconds
Want to see the full answer?
Check out a sample textbook solutionChapter 8 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Additional Engineering Textbook Solutions
Concepts Of Programming Languages
Absolute Java (6th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Concepts of Programming Languages (11th Edition)
Introduction To Programming Using Visual Basic (11th Edition)
- Computer Science c++ || urgent Write the code for choosing the list of items in order to get the maximum profit of fractional knapsack problem. [NOTE: number of input items should be user interest, and output should be like - firstly print the resulting profit table, and then print the all selected items (must not be all items from the inputted items - means that all inputted items should not be as the selected items) for the knapsack and then print the maximum profit.]arrow_forward6.22 C++ Define a function named SwapValues that takes four integers as parameters and swaps the first with the second, and the third with the fourth values. Then write a main program that reads four integers from input and calls function SwapValues() to swap the input values. The main program then prints the swapped values on a single line separated with spaces and ending with a newline. The program must define and call the following function:void SwapValues(int& userVal1, int& userVal2, int& userVal3, int& userVal4) Ex: If the input is: 3 8 2 4 function SwapValues() stores 8, 3, 4, and 2 in userVal1, userVal2, userVal3, and userVal4, respectively. The main program then outputs: 8 3 4 2 Function SwapValues() swaps the values referenced by the parameters and does not print any output.arrow_forwardProblem 2 (5 pts) Write a Python program that plays the game Ro-Sham-Bo (a.k.a., Rock, Paper, Scissors) for a player and a computer opponent. The player selects one of the options listed in a console prompt, then the computer randomly selects an option as well. The winner of the game is determined as follows: Rock beats Scissors - Scissors beats Paper - Paper beats Rock The same selection results in a tie. Your program must do the following: Prompt the player to enter a selection in the console. Provide instructions to user on what is a valid input. For example, you can have the integers 1, 2, and 3 represent the selection, or use the words rock, paper, scissors, etc. Check that the user entered valid input. If the entry is invalid, the program needs to inform the user of the invalid input and can end, or re-prompt the user for their entry. Generate a random selection for the computer's choice. You can use a random integer and follow the same rules as was stated to the user. - Display…arrow_forward
- // Your task is to write C code to do the following: // // 1) Include stdio.h and qutyio.h so that you can access the // functions required to write to the serial interface. // 2) Initialise the qutyio serial inteface by calling serial_init(). // 3) Create a variable "state" to store your student number. You // should interpret your student number as a decimal number. Use // the smallest standard unsigned integer type in which your student // number will fit. (you will need to include the stdint header). // e.g. the student number 10000012 would represent the number // ten million and twelve. // 4) Iterate through all the numbers from 0 to 255 in sequence. // For each number in the sequence perform the following steps: // a) Take the bitwise xor of the number with the variable "state", // storing the result back into "state". // b) Rotate right the bits in "state" at least one time, and until // the LSB of "state" is a zero. If there are no…arrow_forwardProblem: 9.19 LAB: Convert to binary - methodsWrite a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0Output x % 2 (remainder is either 0 or 1)x = x / 2Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string. Ex: If the input is: 6the output is: 110Your program must define and call the following two methods. The method integerToReverseBinary() should return a string of 1's and 0's representing the integer in binary (in reverse). The method reverseString() should return a string representing the input string in reverse. public static String integerToReverseBinary(int integerValue)public static String reverseString(String inputString) Java code:import java.util.Scanner; public class LabProgram {/* Define your method here */ public static String integerToReverseBinary(int…arrow_forward7:42 1 of 2 CE102 Homework 2 Description: You are tasked with creating a C++ program for managing a virtual pet store. The program should implement a simple user interface and utilize loops, if-else statements, and input-output functions. Your objective is to design and implement the following structure: Pet Class: ✓ Attributes: name: string (private) type: string (private) age: integer (private) hungerLevel: integer (private) happinessLevel: integer (private) ✓ Enum Definition: Create an enum to represent different types of pets. The enum should include options such as "DOG", "CAT", "BIRD", etc., corresponding to common types of pets that can be managed in the virtual pet store program. Use this enum to specify the type of each pet when creating instances of the Pet class. ✓ Member Functions: ⚫ Constructor: ⚫ Parameters: name (string), type (string), age (integer) • feed: Functionality: Initializes the pet with the provided details and default hunger and happiness levels. Parameters:…arrow_forward
- Problem:9.17 LAB: Count characters - methodsWrite a program whose input is a character and a string, and whose output indicates the number of times the character appears in the string. Ex: If the input is: n Mondaythe output is: 1Ex: If the input is: z Today is Mondaythe output is: 0Ex: If the input is: n It's a sunny daythe output is: 2Case matters. n is different than N. Ex: If the input is: n Nobodythe output is: 0Your program must define and call the following method that returns the number of times the input character appears in the input string.public static int countCharacters(char userChar, String userString) Java code:import java.util.Scanner; public class LabProgram {/* Define your method here */public static int countCharacters(char userChar, String userString) {int counter=0;for (int i=0; userString.length; i++) {if (userString.charAt(i)==userChar) {counter++; }}return counter;}}public static void main(String[] args) {/* Type your code here. */ Scanner scnr = new…arrow_forward6.23 C++ Define a function named CoinFlip that returns "Heads" or "Tails" according to a random value 1 or 0. Assume the value 1 represents "Heads" and 0 represents "Tails". Then, write a main program that reads the desired number of coin flips as an input, calls function CoinFlip() repeatedly according to the number of coin flips, and outputs the results. Assume the input is a value greater than 0. Hint: Use the modulo operator (%) to limit the random integers to 0 and 1. Ex: If the random seed value is 2 and the input is: 3 the output is: Tails Heads Tailsarrow_forward67% Os: Consider the following Java program: public void fun(void) { Int a, b, c; /* definition 1 */ while (. . .) ( int b, c, d; /*definition 2 */ 1. while (. . .) { int c, d, e; /* definition 3 */ 2 3. 4 For each of the four marked points in this function, list each visible variable, long with the number of the definition statement that defines Mark Point List of Visible Variable (e.g a,b.c.etc.) Definition Number (e.g. definition 1) 2. 4. (Tarrow_forward
- 6.23 C++ Define a function named CoinFlip that returns "Heads" or "Tails" according to a random value 1 or 0. Assume the value 1 represents "Heads" and 0 represents "Tails". Then, write a main program that reads the desired number of coin flips as an input, calls function CoinFlip() repeatedly according to the number of coin flips, and outputs the results. Assume the input is a value greater than 0. Hint: Use the modulo operator (%) to limit the random integers to 0 and 1. Ex: If the random seed value is 2 and the input is: 3 the output is: Tails Heads Tails The program must define and call the following function:string CoinFlip()arrow_forwardINSTRUCTION: Read and study the assignment below. Solve the problem using C++ programminglanguage, compile, run and screen shot the correct output. Copy and paste the source code or programcode and the required sample output (screen shot) in the format below. PROBLEM 1: Write a program using VOID FUNCTION that will display the sum, product, difference, quotient andmodulus of two numbers. Note: Create function name for sum, product, difference quotient and modulus. Complete the program codes below to finish the problem requirements. SAMPLE OUTPUT:Enter first number: 7Enter second number: 2The sum is 9The product is 14The difference is 5The quotient is 3The modulus is 1 SOURCE CODE: Update the source code below#include<iostream>using namespace std; void addTwoNumbers(int , int); // function name for sum// Create function name for product// Create function name for difference// Create function name for quotient// Create function name for modulus int num1, num2, sum=0;…arrow_forward(python) Write a function myfunction that requests user input i the form of an integer value, 1, 2 or 3. The function should print out: Option 1 selected Option 2 selected Option 3 selected when the corresponding number is entered, and the loop should end if q is entered. Any unrecognised options should result in the following statement being printed: Unknown optionarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education