Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 11, Problem 8E
Program Plan Intro
Program Plan:
- Include the necessary header files into program.
- Define the function named “bitSize()” which is used to fetch the size of the value.
- Declare the variables in type of unsigned int and int.
- Using “while” loop, check the value of “size”.
- If the value greater than “0”, right shift operation is performed and increments the “temp” value.
- Return the value of “temp-1”.
- Define the function named “no_of_bits()” which is used to calculate the minimum number of bits needed to represent the value.
- Declare and initialize the variables.
- Using “while” loop, check the value and left shift the value of “temp” and increment the “counter” value.
- Return the size which is reduced from counter.
- Define the function named “bitpat_get()” which is used to extract the “n” bits from source starting at “start” argument.
- Declare the variables.
- Call the “bitSize()” method and store the size into variable “size”.
- Initialize the value of “c” in type of integer.
- Using “if…else” condition, calculate the offset and temporary value.
- Return the temporary value to function.
- Define the function named “bitpat_set()” which is used to set the bit size within the source to value which is starting at “*start”.
- Declare the variables.
- Call the “no_of_bits()” method which passes “*start” as argument.
- Call the other appropriate methods and store in the variable.
- Using left shift operator to calculate the value of “val”.
- Print the appropriate result on screen.
- Define the main method.
- Declare the variables in type of unsigned integer.
- Prompt and get the values.
- Call the “bitpat_set()” method and print the result on screen.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
This problem needs to be solved in python.
Write a function read_movies_data(f) that takes in a movies file and returns a pandas DataFrame, where the index is the movie id and the columns are "title", "year", and "genre" (in that order).
movies_df = read_movies_data("moviesSample.txt")
assert movies_df.shape == (9, 3)assert movies_df.iloc[2, 2] == "Comedy"assert movies_df.loc[6, "title"] == "Heat"assert all(movies_df.columns == ["title", "year", "genre"])assert list(movies_df.index) == [1, 2, 3, 4, 5, 6, 8, 9, 10]
NOTE: Make sure all of the asserts work
The moviesSample.txt looks like this:
1|Toy Story|1995|Adventure2|Jumanji|1995|Adventure8|Tom and Huck|1995|Adventure3|Grumpier Old Men|1995|Comedy4|Waiting to Exhale|1995|Comedy5|Father of the Bride Part II|1995|Comedy6|Heat|1995|Action9|Sudden Death|1995|Action10|GoldenEye|1995|Action
NOTE: Try to sent screenshots of the code working.
PROGRAM IN PLAIN C PLEASE!
Write a void function that will merge the contents of two text files containing
chemical elements sorted by atomic number and will produce a sorted file of
binary records. The function’s parameters will be three file pointers. Each text
file line will contain an integer atomic number followed by the element name,
chemical symbol, and atomic weight. Here are two sample lines:
11 Sodium Na 22.99
20 Calcium Ca 40.08
The function can assume that one file does not have two copies of the same
element and that the binary output file should have this same property. Hint:
When one of the input files is exhausted, do not forget to copy the remaining
elements of the other input file to the result file.
Problem 5
Solve this problem inside the files problem5-library.c and problem5-library.h. Do not modify any other files for this problem.
Write a function called "nextLetter" inside problem5-library.c and add its prototype inside problem5-library.h.
• The function must accept 2 parameters, a character then an integer.
It will return a character.
• The function will return the character that is reached by starting from the passed letter and moving steps equal to the passed integer. Check the examples below:
Example: If the parameters were 'A' and 1, the function will return 'B', because 'B' is 1 step away from 'A'.
Example: If the parameters were 'e' and 3, the function will return 'h', because 'h' is 3 steps away from 'e'.
• If the given letter is uppercase, the returned letter must be uppercase. If the given letter is lowercase, the returned letter must be lowercase.
• If the given integer is too big or will cause the letters to reach the last letter, you must restart the letters from…
Chapter 11 Solutions
Programming in C
Ch. 11 - Type in and run the four programs presented in...Ch. 11 - Write a program that determines whether your...Ch. 11 - Prob. 3ECh. 11 - Using the result obtained in exercise 3, modify...Ch. 11 - Write a function called b that takes two...Ch. 11 - Write a function called b that looks for the...Ch. 11 - Write a function called b to extract a specified...Ch. 11 - Prob. 8E
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
- Can you give the answer to these two questionsarrow_forwardWrite a C language function named count that takes a void pointer and int parameter, representing a memory buffer, and a uint8_t parameter representing a byte, and returns an int result. The returned result should be the number of occurrences of the byte in the bufer. For example if the buffer p pointed to the bytes 01 12 01 23, then count(p, 4, 0x01) should return 2.arrow_forwardAdd file i/o to your program Implement a function writeEmpToFile that takes two arguments: a struct Employee pointer and a FILE *. It should write each field in order as an appropriate type. Note that you will probably want to write a length of the name before you write the characters of the name. By doing this, when you write the load function below, you can read the length of the string and use it to malloc a buffer of the proper size to hold the name. Because of the embedded name pointer, you CAN NOT write the Employee struct as a single struct. You will need to write it out field by field. You will want to write this as a binary file, not as a text file. Implement a SAVE command in your main loop that will save all the employees out to a file. The SAVE command should ask for a file name, similar to the way your FIND command asked for a name. Implement a function readEmpFromFile that takes a FILE * as the only argument and returns a pointer to a struct employee. This function should…arrow_forward
- Define a function named get_encrypted_list (word) which takes a word as a parameter. The function returns a list of characters. The first element is the first letter from the parameter word and the rest is as a sequence of '*', each '*' representing a letter in the parameter word. Note: you can assume that the parameter word is not empty. For example: Test Result ['h', '*', **1 guess = get_encrypted_list('hello') print(guess) print (type (guess)) guess = get_encrypted_list('succeed') ['s', '*', print (guess) **¹, ¹*¹] **']arrow_forwardDefine a function read_data that accepts a single argument corresponding to the filename, and returns a list of lists. You can find an example file to work within the Brightspace and the startercode section of the Vocareum Each line in the data file follows this format: "[Name], num1, num2, num3 . . . ." Ben, -1, 2.3, 4.1, 5.25, -4, 0.2, 0.55, 1.1 Mary,2.1, 1.4, 1.2, 1.5, 1.0, 2, 3.1 Giulia, 1.8, -2.2, -1.6,3 The function must return a list of lists where each sublist represents one line from the file. All the numbers must be converted to float datatype in the returned value Sample output: > > print(read_data('sample_ data.txt')) [['Ben', - 1.0, 2.3, 4.1, 5.25, -4.0, 0.2, 0.55, 1.1], ['Mary ', 2.1, 1.4, -1.2, 1.5, 1.0, 2.0, 3.1], ['Giulia', 1.8, -2.2, 1.6, 3.0]] - -arrow_forwardWhich of the following will exchange the values at addresses identified by pointers p and q? (All assignments may be assumed to be between compatible types). Select one: O a. Any will work. O b. temp = p; p = q; q = temp; O c. temp = p; *p = *q; q = temp; O d. temp &p; *p = *q; q = *temp; None will work. O e. O f. temp = *p; *p = *q; *q = temp;arrow_forward
- Use C++arrow_forwardhe data must be stored in two dynamic arrays: an array of strings named names, and an array of ints named scores. These arrays must be declared and allocated using "new" in the main function. The user input of the names and scores should be done in a function named readData(). It should have the following signature: void readData(string names[], int scores[], int size) You must also write two more functions: one to sort both arrays in descending order by score, and one to display the final list of names and scores. They should have the following signatures. void sortData(string names[], int scores[], int size) void displayData(const string names[], const int scores[], int size) The main function should be very short. It should just get the number of scores, allocate the two arrays, invoke these three functions, and then deallocate the arrays. Some of you may not have studied sorting algorithms. Sorting is covered in lesson 9, section 9.6. You can copy as much code from that lesson as…arrow_forwardComputer Science Write a C++ language program that reads the file numbers.txt having 10,000 random integers ranging from 1-1,000,000. It takes an input argument num_jobs with a value between 1 and 8. E.g. if num_jobs is 3, it splits into 3 parallel processes using fork() function and each process then calculates prime numbers from a subset of the input data. Together these 3 jobs find prime numbers from all the 10,000 input integers. The overall parent process then combines the results from its children into a single file prime.txt. NOTE: The key part is to solve it with fork()arrow_forward
- Write a program that reads movie data from a CSV (comma separated values) file and output the data in a formatted table. The program first reads the name of the CSV file from the user. The program then reads the CSV file and outputs the contents according to the following requirements in c++ : Each row contains the title, rating, and all showtimes of a unique movie. A space is placed before and after each vertical separator ('|') in each row. Column 1 displays the movie titles and is left justified with a minimum of 44 characters. If the movie title has more than 44 characters, output the first 44 characters only. Column 2 displays the movie ratings and is right justified with a minimum of 5 characters. Column 3 displays all the showtimes of the same movie, separated by a space. Each row of the CSV file contains the showtime, title, and rating of a movie. Assume data of the same movie are grouped in consecutive rows. Hints: Use the find() function to find the index of a comma in each…arrow_forwardIn C, write a function that gets 3 pointers int* a, int* b, int* c, and rotates the values in their addresses to the left. That is, a gets the value of b, b gets the value of c, and c gets the value of a. void rotate3 (int* a, int* b, int* c); For example, if we have int x=1, y=2, z=3, then after calling rotate3 (&x, &y, &z) we should have x==2, y==3, and z==1. if we have int x=7, y=1, z=6, then after calling rotate3 (&x, &y, &z) we should have x==1, y==6, and z==7.arrow_forward3. Task 2: Reading lines from a File Write C code which will read a line of characters (terminated by a \n) from input_file into a character array called buffer. NULL terminate the buffer upon reading a \n. NOTE:Your source code must display any of the given sample output below.It means your source code should be flexible enough to meet any of the given sample output.Your source code output must be identical to any of the given sample output.It means you have to strictly follow what are the displayed text, labels, casing of characters in the sample output.Strictly follow the naming of file. Sample OUTPUT1: Enter File Name: lupang_hinirang.txt Bayang magiliw Perlas ng silanganan Alab ng puso sa dibdib mo’y buhay Lupang Hinirang, duyan ka ng magiting Sa manlulupig, di ka pasisiil Sa dagat at bundok na simoy At sa langit mong bughaw Tagumpay na nagnininging Ang bituin at araw niyan Kailan pa ma’y di magdidilim Lupa ng araw ng luwalhati’t pagsinta Buhay ay…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 Ptr
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr