Computer Systems: A Programmer's Perspective (3rd Edition)
3rd Edition
ISBN: 9780134092669
Author: Bryant, Randal E. Bryant, David R. O'Hallaron, David R., Randal E.; O'Hallaron, Bryant/O'hallaron
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 8, Problem 8.25HW
Write a version of the fgets function, called tfgets, that times out after 5 seconds. The tfgets function accepts the same inputs as fgets. If the user doesn't type an input line within 5 seconds, tfgets returns NULL. Otherwise, it returns a pointer to the input line.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
2. Test Scores
File: test_scores.py
Write pseudocode for the main() part of a program that asks the user to enter 4 test scores between 0 and 100, then displays a JCU grade for each score and also the average test score.
When you have written the pseudocode for main, implement your solution in Python code and test it with a range of meaningful data.
Remember that we've done the JCU grades question before, so copy your function from that practical code file.
Sample Output
Score: 3
Score: 50.5
Score: 66
Score: 100
Score 3.0, which is N
Score 50.5, which is P
Score 66.0, which is C
Score 100.0, which is HD
The average score was 54.875
Enhancements
When you have that working...
We asked for 4 scores. Have a look at your code... did you use 4 as a numeric literal or a constant?Change 4 to 3... Did you have to change the program in more than one place?If so, then you've missed one of the things we've taught...As a strong guideline: if you need to use the same literal more than once, you…
A prime number is an integer value that is only divisible by 1 and itself. 2, 3, 5, 7, and 11 are examples of prime numbers. You have been provided with
two function definitions:
The is_prime () function takes an integer parameter number, and returns True if number is prime and False otherwise. The
get_next_prime () function also takes a single integer parameter number, and returns the first prime number larger than it. You must not
change the implementation of these 2 functions.
Complete the get_primes_list() function that takes a single list of integers called numbers as parameter. You can assume that the integer
items in this list will be non-negative. The function must update this list so that items that are not prime numbers are updated to the first prime number
larger than them. To implement this function you must call both the is_prime () and get_next_prime () functions. Some examples of the
function being called are shown below.
Note: the get_primes_list() function does not…
Using either pseudocode of C++ code, write a function that takes three parameters and performs a sequential search. The first parameter is an array of integers. The second parameter is an integer representing the size of the array. The third parameter takes the value to be search form. The function should return the subscripts at which the value is found or -1 is the array does not contain the search term.
Chapter 8 Solutions
Computer Systems: A Programmer's Perspective (3rd Edition)
Ch. 8.2 - Prob. 8.1PPCh. 8.4 - Prob. 8.2PPCh. 8.4 - Prob. 8.3PPCh. 8.4 - Prob. 8.4PPCh. 8.4 - Practice Problem 8.5 (solution page 797) Write a...Ch. 8.4 - Practice Problem 8.6 (solution page 797) Write a...Ch. 8.5 - Practice Problem 8.7 (solution page 798) Write a...Ch. 8.5 - Prob. 8.8PPCh. 8 - Prob. 8.9HWCh. 8 - In this chapter, we have introduced some functions...
Ch. 8 - How many hello output lines does this program...Ch. 8 - How many "hello' output lines does this program...Ch. 8 - Prob. 8.13HWCh. 8 - How many hello output lines does this program...Ch. 8 - How many "hello lines does this program print?Ch. 8 - Prob. 8.16HWCh. 8 - Prob. 8.17HWCh. 8 - Consider the following program: Determine which of...Ch. 8 - How many lines of output does the following...Ch. 8 - Use execve to write a program called my1s whose...Ch. 8 - What are the possible output sequences from the...Ch. 8 - Write your own version of the Unix system function...Ch. 8 - One of your colleagues is thinking of using...Ch. 8 - Modify the program in Figure 8.18 so that the...Ch. 8 - Write a version of the fgets function, called...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
For each of the following activities, give a PEAS description of the task environment and characterize it in te...
Artificial Intelligence: A Modern Approach
For each of the following E-R diagrams from Chapter 2 C: Transform the diagram to a relational schema that show...
Modern Database Management (12th Edition)
For each of the following numeric formats, identify the format string used as the input parameter when calling ...
Starting Out With Visual Basic (8th Edition)
Consider the following class declaration: public class Thing { private int x; private int y; private static int...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
A file that contains a Flash animation uses the __________ file extension. a. .class b. .swf c. .mp3 d. .flash
Web Development and Design Foundations with HTML5 (8th Edition)
What is the output produced by the following (when embedded in a correct program with x declared to be of type ...
Problem Solving with C++ (9th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- C languagearrow_forwardUsing C++ Write the section of code which takes an array of characters and copies it to another array of characters. At this point two arrays of characters should hold the same name. You will need to use one of the loop instructions to do this. You can't use any built in functions. Write a second section of code which concatenates two arrays of characters into a third array of characters. The first array (which holds the first name) will be copied into the third array and the second array (which holds the last name) will be concatenated onto the third array. Once you are done filling in the arrays you should output the two sentences below. You are given the example input and output below.Example Input: Input first name -> FredInput last name -> SmithExample output: Your first name is Fred and the copy of your first name is Fred. Your first name is Fred and your last name is Smith and the concatenation is FredSmith.arrow_forwardC Program Functions using Pointers Create a function modify that accepts an integer and divides the integer by 2 if it is even. If the integer is odd, add one and divide it by 2. The function does not return anything. In the main function, write a program that asks for an integer input and call the modify function by passing in the reference of that variable as a parameter. An initial code is provided for you. Just fill in the blanks. Input 1. One line containing an integer input Output Enter a number: 5 Before: 5 After: 3arrow_forward
- (Numerical) Write a program that tests the effectiveness of the rand() library function. Start by initializing 10 counters to 0, and then generate a large number of pseudorandom integers between 0 and 9. Each time a 0 occurs, increment the variable you have designated as the zero counter; when a 1 occurs, increment the counter variable that’s keeping count of the 1s that occur; and so on. Finally, display the number of 0s, 1s, 2s, and so on that occurred and the percentage of the time they occurred.arrow_forward4. The following program loads and displays an image. Complete the modify function to change the brightness of the image. The parameter m is a multiplication factor. modify will will multiply each pixel by m - that means you need to multiply the red, green, and blue channels by m, create a new pixel with new red, green, and blue values, and replace the old pixel with the new pixel. Be sure none of the red, green, and blue values exceed 255 (if a value is greater than 255, set it to 255). Your program should work for images of any size. A good example is the sepia tone exercise. Do not change the main function, except to try different values for the multiplication factor. Save & Run Load History 1 import image 3 def modify(pic, m): '''Multiply each pixel by m to darken or brighten an image''' pass #You can leave this or remove it #Your code here to change the brightness of the image 4 7 8 def main(): 9. '''Controls the program'" fname…arrow_forwardImplement a function named get_player_selection. This function has parameters for the players number (which will be either 1 or 2), and the number of sticks remaining on the board. For this function you will need to do the following: Use the input function to get the player to type in their selection. Validate the user’s input, printing out a message if they enter an invalid number and continually prompting them until they do enter a valid number. The user may enter any number between 1 and 3, unless there are fewer than 3 sticks remaining, in which case they can only enter between 1 and the number of sticks remaining. As in the example, the input prompt should list the valid range of numbers. Return the (validated) number as an integer (not a string). You should test that this function works by running it in the REPL. Make sure you try different scenarios, like the user entering an invalid number multiple times in a row. After you are done testing and fixing any errors you find,…arrow_forward
- In python, Old-fashioned photographs from the nineteenth century are not quite black and white and not quite color, but seem to have shades of gray, brown, and blue. This effect is known as sepia, as shown in the figures below. Original Sepia Original Image & Sepia Image Write and test a function named sepia that converts a color image to sepia. This function should first call grayscale to convert the color image to grayscale. A code segment for transforming the grayscale values to achieve a sepia effect follows.Note that the value for green does not change. (red, green, blue) = image.getPixel(x, y)if red < 63: red = int(red * 1.1) blue = int(blue * 0.9)elif red < 192: red = int(red * 1.15) blue = int(blue * 0.85)else: red = min(int(red * 1.08), 255) blue = int(blue * 0. 1. GUI TEST 2. CUSTOM TEST 3. IMAGE TESTarrow_forwardWrite a function, named randomPassword, that generates a random password that takes no parameter. It will return the randomly generated password as its ONLY result. Display the randomly generated password in the main program. Password Criteria: o The password should have a random length of between 7 and 10 characters. o Each character should be randomly selected from positions 33 to 126 from the ASCII table You must import randint function directly and inline within the random package and it must be the first line of code in your program, after your program header comment. o Declaring and using FOUR constants. Constants must be named appropriately and intuitively. o You must use the chr built-in function within your randomPassword function: o Declaring the main function and invoking randomPassword function. o Logical approach to problem solving, computation, and displaying appropriate output.arrow_forwardUsing the following header, create a recursive function that shows an integer value backwards on the console using the syntax:reverseDisplay(value) is defined as follows:For example, the reverseDisplay(12345) function shows the number 54321. Create a test application that asks the user to input a number and then shows the inverse of that integer.arrow_forward
- Add a function to get the CPI values from the user and validate that they are greater than 0. 1. Declare and implement a void function called getCPIValues that takes two float reference parameters for the old_cpi and new_cpi. 2. Move the code that reads in the old_cpi and new_cpi into this function. 3. Add a do-while loop that validates the input, making sure that the old_cpi and new_cpi are valid values. + if there is an input error, print "Error: CPI values must be greater than 0." and try to get data again. 4. Replace the code that was moved with a call to this new function. - Add an array to accumulate the computed inflation rates 1. Declare a constant called MAX_RATES and set it to 20. 2. Declare an array of double values having size MAX_RATES that will be used to accumulate the computed inflation rates. 3. Add code to main that inserts the computed inflation rate into the next position in the array. 4. Be careful to make sure the program does not overflow the array. - Add a…arrow_forward27. In C programming . make a program that lists 10 numbers from the user into an array, create a moving_average function that when its in a loop it makes a length 3 moving average array. make sure it prints the inputted array and then the moving average array. make a flowchart with itarrow_forwardWe want to develop a game where the user should guess a secret number. The game asks the user to input a number and tells how close it is to the secret random number that the game generates. Complete the main() function that implements this game by calling the get_user_input(), generate_secret(), and display_result(user_input, secret) functions that you will develop as follows: • Complete the get_user_input() function so that it prompts the user to enter a whole number between 1 and 20 (inclusive) and returns the number that the user enters. • Complete the generate_secret() function so that it generates and returns a random number between 1 and 20 (inclusive). • Complete the display_result(user_input, secret) function that takes the two parameters that correspond to the user input and the secret. It should then print the absolute difference between these two numbers. For example: Test Input Result random.seed (10) S Enter a number from 1 to 2015 You entered 5. The secret was 19. The…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Computer Programming for Beginners | Functions, Parameters & Arguments | Ep24; Author: Programming With Avelx;https://www.youtube.com/watch?v=VXlh-qJpfw0;License: Standard YouTube License, CC-BY