COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
3rd Edition
ISBN: 9780134671123
Author: Bryant
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 5, Problem 5.17HW
Program Plan Intro
Given C Code:
void* basic_memset(void *s, int c, size_t n)
{
size_t cnt = 0;
unsigned char *schar = s;
while (cnt < n)
{
*schar++ = (unsigned char) c;
cnt++;
}
return s;
}
Cycles per element (CPE):
- The CPE denotes performance of program that helps in improving code.
- It helps to understand detailed level loop performance for an iterative program.
- It is appropriate for programs that use a repetitive computation.
- The processor’s activity sequencing is controlled by a clock that provides regular signal of some frequency.
Loop unrolling:
- It denotes a program transformation that would reduce count of iterations for a loop.
- It increases count of elements computed in each iteration.
- It reduces number of operations that is not dependent to program directly.
- It reduces count of operations in critical paths of overall computations.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
IN C++
You have given an array aa of length n and an
integer x to a brand new robot. What the robot
does is the following: it iterates over the
elements of the array, let the current element be
q. If q is divisible by x, the robot adds x copies of
the integer q/x to the end of the array, and
moves on to the next element. Note that the
newly added elements could be processed by
the robot later. Otherwise, if q is not divisible by
x, the robot shuts down.
Please determine the sum of all values of the
array at the end of the process.
Input
The first input line contains a single integer tt
(lâ%oatâ%o¤100) â€" the number of test cases.
The first line of each test case contains two
integers n and x (1â%o¤nâ%o010^5, 2â%oaxâ%o
¤10^9) â€" the length of the array and the value
which is used by the robot.
The next line contains integers al, a2, .., an
(lâ%o¤aiâ%o¤1O^9) â€" the initial values in the
array.
It is guaranteed that the sum of valuesn over all
test cases does not exceed 10^5
Output
For…
Implement the following scenario using C++.
Ibri City Polyclinic wishes to maintain their doctor details such as doctor id, name, and their specialization (Example: General / Pediatrician / El Specialist / Artho / Neurologist) in an array. Kindly help
the hospital authorities to read the doctor details in an ascending order based on doctor id, store it in an array and search any given doctor id in the array using binary search. If the searched doctor id
is found, then display only doctor name and their specialization otherwise display ' This doctor is not working in our hospital '.
Note:
1. Use your name as the name of the structure.
2. Maximum number of account holders 25o
Please choose which of these are true about pointers. Check all that apply. Wrong answers will subtract points.
O A pointer contains an address in RAM.
The pointers we studied were mainly variables.
O A pointer can be initialized with a special value called nullptr.
In the material we studied, we saw that a pointer can contain an entire array.
This definition:
double * dp;
means that the dp variable can contain a double.
Assume this is a function heading for the code you will write:
void somthing10 (int * ptr)
a. In one line of code, how could you add 10 to what ptr points to?
b. Assume ptr points to the first element in an array of ints, each of which takes
up 4 bytes of memory in RAM. In one line of code, how could you store 10
into the third element in the array? If this is not possible, enter "np"
Chapter 5 Solutions
COMPUTER SYSTEMS&MOD MSGT/ET SA AC PKG
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
- Write a function in C language that will take a 2D Array of size 3x3 from the user. Your Program should: 1. Prompt the user to enter 2D array of size 3x3. 2. Calculate the sum of all rows. 3. Calculate the sum of all columns 4. Return 1 if the sum of all rows is greater than sum of all columns, 0 otherwise. Your main program should print the result based on the returned values.arrow_forwardWrite only the function definition: Implement the following function definition: int CrazyWord(char word [ ]); //input: a character array with a null character (string) //sets all of the characters in the word to lowercase letters //changes any lowercase ‘o’ letters to hashtags ‘#’ //returns the number of hashtags that are now in the wordarrow_forwardThis is c-language. The main issue I am having is specifiers errors in compiling the output of my matrix. Can you check where I am getting issues at printing my matrix? #include <stdio.h>#include <math.h>#include <stdlib.h>#define NROWS 5#define NCOLS 5 int main(void){ int i,j, max, min, m, n; float M[NROWS][NCOLS]; char key_hit; //Input the sizes printf("ROW size(1-5) : ");scanf("%d",&m); printf("Column size(1-5): ");scanf("%d",&n); //Size Check while(m>NROWS || n>NCOLS) { printf("Please re-enter the sizes. \n"); printf("Row size(1-5) : ");scanf("%d", &m); printf("Column size(1-5) : ");scanf("%d", &n); } //Input the Matrix Data for(i=0; i<m; i++) for(j=0; j<n; j++) { printf("M[%d][%d] = ", i,j); scanf("%f", &M[i][j]); } //Print the Matrix Data for(i=0; i<m; i++); { for(j=0; j<n; j++)…arrow_forward
- Write a C++ program that will implement and test the five functions described below that use pointers and dynamic memory allocation. The Functions: You will write the five functions described below. Then you will call them from the main function, to demonstrate their correctness. findLast: takes an array of integers, its size and a target integer value. Returns an index of the last occurrence of the target element in the array. If the target value doesn't exist, returns -1. For this function only: Do not use square brackets anywhere in the function, not even the parameter list (use pointer notation instead). nextFibonacci. Modify the following function to use pointers as parameters (instead of reference parameters). The Fibonacci sequence is a series of numbers where each number is the addition of the previous two numbers, starting with 0, and 1 (specifically: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55…). This function updates the given i-th and (i+1)-st Fibonacci numbers to (i+1)-st and…arrow_forward: A monochrome screen is stored as a single array of bytes, allowing eight consecutivepixels to be stored in one byte. The screen has width w, where w is divisible by 8 (that is, no byte willbe split across rows). The height of the screen, of course, can be derived from the length of the arrayand the width. Implement a function that draws a horizontal line from (xl, y) to (x2, y).The method signature should look something like:drawLine(byte[] screen, int width, int xl, int x2, int y)arrow_forwardProgram the following in C language. Prompt the values from user for a single dimensional integer array of length 5 and accept them in First In First Out Consider a one dimensional character array of length 5 and holding data a, e, i, o and u. Sort them in ascending Randomly place values in a 2 dimensional integer array. Prompt values from user for a one dimensional integer array of length 10 in FILO order. Arrange this array in ascending and descending order in other 2 arrays.arrow_forward
- Write a Python function def isSubArray(A,B) which takes two arrays and returns True if the first array is a (contiguous) subarray of the second array, otherwise it returns False. You may solve this problem using recursion or iteration or a mixture of recursion and iteration. For an array to be a subarray of another, it must occur entirely within the other one without other elements in between. For example: [31,7,25] is a subarray of [10,20,26,31,7,25,40,9] [26,31,25,40] is not a subarray of [10,20,26,31,7,25,40,9] A good way of solving this problem is to make use of an auxiliary function that takes two arrays and returns True if the contents of the first array occur at the front of the second array, otherwise it returns False. Then, A is a subarray of B if it occurs at the front of B, or at the front of B[1:], or at the front of B[2:], etc. Note you should not use A == B for arrays.arrow_forwardWhat is the correct way to assign the pointer p to the address of x?. Single choice. p = %x; p = &x; &p = *x; *p = &x;arrow_forwardImplement a function rollsToRepeat in Python that simulates a dice game in which a pair of dice are rolled repeatedly until some total on the dice occurs the specified number of times. Details: accepts one integer argument, n , the number of repeats required before the game ends rolls a pair of dice repeatedly until some dice total has repeated n times returns the total number of times the pair of dice was rolled For example, using a random seed of 85 , the sequence of rolled pairs will be : (2, 6), (5, 1),(3, 2), (2, 4), (3, 5), (2, 6), (4, 5), (5, 2), (6, 5), (5, 5), ... If you runrollsToRepeat with n=1 , only 1 repeat is required. On the first roll, the total 8=2+6 is repeated once (as wouldany first roll). So the simulation stops and the function returns 1. This always happens whenn=1 . n=2 , some total must repeat twice. This first occurs on the 4throll, when the total of 6occurs for the 2ndtime. n=3 , some total must repeat three times. This first occurs on the 6throll, when…arrow_forward
- Java code: write a java code that can perform SQUARE-MATRIX-MULTIPLY-RECURSIVE. A; B(Strassen's Algorithms)/ and ordinary multiplication. The program should ask the user for input file and output file locations, and give output for both methods. It should also check if both outputs match and include error handing for incorrect Matrix Multiplication input.arrow_forwardWrite these in Pseudocode #1a – In pseudocode, write a call to a function that passes 1 Integer variable and 1 Integer array, and saves a Boolean value in return. #1b – In pseudocode, write the function that accepts 1 Integer and 1 Integer array and returns a Boolean. In the function, search the Integer array with a for-loop, and if the Integer parameter is found in the array, return false. If the Integer parameter is not found, return true. #2a – In pseudocode, write a call to a module that passes 1 Integer variable, 1 Real variable, 1 String constant, and 1 String literal as arguments. #2b – In pseudocode, write the module header that accepts 1 Integer, 1 Real, and 2 Strings as parameters. #3 – This pseudocode has multiple problems. Fix the calling statement and the definition below so that the routine accepts 3 grades as parameters and returns the average into a variable.…arrow_forwardProblem Y: Implement the reader writer problem using pthreads and semaphores. You should allow multiple readers to read at the same time and only one single writer to write to the data set. You are required to use the following: 1. A semaphore rw_muter initialized to 1. 2. A semaphore muter initialized to 1. 3. An integer reader_count initialized to 0.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning