Computer Science For each of the code snippet given below, identify the error and then write code after fixing the error. Given code is the simulation of grep -v command. -v prints all lines that do not match a specific pattern. void grep_inverse(char *filename, char *str) { FILE *fp; char buf[buff_size]; fp = fopen(filename, "r"); if(!fp) { perror(filename); } else { while (fgets(buf, buff_size, fp) != NULL) { if ((strstr (buf, str)) != NULL) printf("%s", buf); } } fclose(fp); }
Q: Both problems are about the game of 2 player PIG where both players are racing to be the first to Na...
A: For the program we will create a two player game of pig. The game of Pig is a very simple dice game ...
Q: Task 4: Show the token type and word generated by the lexical analyser corresponding to this Java so...
A: Here,try to Show the token type and word generated by the lexical analyzer corresponding to this jav...
Q: Explain which of the conversion methods would be suitable for the following. Justify your choice: U...
A: Upgrading the software for an ATM - Parallel Conversion. Using both old and new systems at thesame t...
Q: Can you issue cd command without argument? What is its effect? Group of answer choices No, Shell wil...
A: The commands in Linux are basically used to carry out operations associated with data. Linux itself ...
Q: 1) Which of the following best explains why machine instruction is written in binary code? a. Mac...
A: Solution: Que 1) The correct answer is 'a' Explanation: The machine instruction are machine code pr...
Q: Justify your usage of degree-two consistency by providing an example. What are the drawbacks of this...
A: Given: Explain why you're using consistency of degree two. What are the drawbacks of this strategy?
Q: Why are input/output instructions often referred to as privileged instructions?
A: INTRODUCTION: User engagement with a program on a machine necessitates the use of an input/output d...
Q: What is it about the concept of a file that is so powerful, despite its simplicity and beauty?
A: Introduction: A file format is required if you wish to save information on your computer. It covers ...
Q: What variables in a transaction processing system might work against linear scale up? In each of the...
A: Factors against linear scale-up in a transaction processing system The four types of parallel datab...
Q: Write a c++program that asks the user to insert continously until and then prints the count of even ...
A: Program Explanation:- Using the header file. Using namespace standard input/output function. Define...
Q: 1) Which of the following is NOT true about application software. Select 2 answers from the options....
A: 1. a. An example of this is Operating System. false b. It is a set of computer programs that helps a...
Q: input1="12345" input2="abcde" output="1a2b3c4d5e" in c++
A: we have to write C++ code to concatenate given two string as follows input1="12345" input2="abcde" ...
Q: What is the definition of routing? Define two popular routing algorithms
A: Introduction: A routing device is a piece of network hardware that is responsible for forwarding pac...
Q: Write a function extractData in your shell script wparser.bash. This function will perform the core ...
A: Check command usage Check the number of command line aarguments passed No of command line arguments...
Q: When saving passwords in a file, why is it preferable to hash them rather than encrypt the password ...
A: Answer the above questions are as follows:
Q: Which of the following best explains why information needs to be archive? a. Information needs to b...
A: As per the bartelby guidelines we can solve only one question for you if you want to another questio...
Q: A survey of nonprofit organizations showed that online fundraising has increased in the past year. B...
A:
Q: ll Need solution Asap
A: given - Q.5 (a) Researcher and technologist are claiming that artificial Intelligence next-Generatio...
Q: Write a loop to compute and print the number of occurrences of ‘!’ in a string named question. in ja...
A: public class Main{ public static void main(String[] args) { String question="hello! world!"; ...
Q: B4. In a circuit to decode 4-bits binary input into decimal and show the decimal out 7-segement disp...
A: Here in this question we have given a boolean function with some don't care conditions too..and we h...
Q: Consider a singly linked list where each node contains two fields – integer data and node type point...
A: PROGRAM INTRODUCTION: Include the required header files. Create the structure for the node of the l...
Q: ion system's ca
A: Introduction With over 200 fully-featured services available from data centres around the world, Ama...
Q: Why could the time it takes to access a memory location in a shared-memory architecture vary dependi...
A: The Answer is
Q: Why are Strings in Java referred to as Immutable?
A: - We need to talk about the immutability of strings in java.
Q: Which is/are not a UNIX or Linux vendor(s)? Group of answer choices HP and IBM Red Hat and Novell Su...
A: Which is/are not a UNIX or Linux vendor(s)? Group of answer choices HP and IBM Red Hat and Novell...
Q: What are the flaws in "Wi-Fi Direct" technology? Conduct a penetration test on "Wi-Fi Direct" techno...
A: Introduction: Wi-Fi Direct is a wireless technology that enables two devices to establish a peer-to-...
Q: Kevin and Stacy want to play a game they have titled 'Vowels or Not?'. Here are the game rules: Bot...
A: I have answered this question in step 2.
Q: What resources are required for thread creation?
A: Introduction When a thread is formed, it does not require any additional resources to run; instead, ...
Q: Code: interface Bicycle{ //interface for bicycle void changeGear(int val); //abstract metho...
A: Solution is given below-
Q: 7. Explain the following briefly: a. What is an /O bound job? b. What is CPU bound? c. Suppose there...
A: Given: Answer the questions.
Q: What is the purpose of a virtual file system (VFS)?
A: Introduction A virtual file system (VFS) or virtual file system switch is an invisible layer over a ...
Q: 1. What is the running time of the following algorithm. for i = 1 ton for j = n to i j = j - 2 for j...
A: Given:
Q: What data fields are associated with the process control block?
A: Introduction What data fields are associated with the process control block?
Q: Write a computer program in C that calculates the bullet train’s constant rate of acceleration, give...
A: Ans:) Given, Initial velocity = 200 mi/hr Acceleration, a = vf -vit In this program, user inputs wil...
Q: How do you remove a file in Python?
A: Introduction: If we want to delete files using python, then we need to import OS module. the os modu...
Q: How can one identify the real-world identity associated with a certain user ID on a public blockchai...
A: How can one identify the real-world identity associated with a certain user ID on a public blockchai...
Q: 2. Explain the difference between a partial and a total function. 3. Explain the difference ...
A: Ans1.) Set:- A set is a representation of a group of items, each of which has one or more common qua...
Q: Convert the following number system Base 16 1. Base 10 2. Base 8 Base 2 3. 11000111.11110I
A: As per our guidelines we are suppose to answer three subparts of a question, kindly post other subpa...
Q: Write a function prototype and a header for a function named distance. The function should return a ...
A: function body example according to given condition: double distance(double rate, double time){ ...
Q: What are the advantages of rigorous two-phase locking? What are the drawbacks?
A: Introduction: In contrast to severe 2PL, which allows read-only locks to be released sooner, rigorou...
Q: This is owing to computers' massive computational capacity. Please describe how computers have grown...
A: Introduction: The computer is an electrical device that is capable of doing complex tasks. There has...
Q: What additional technology shares the cabling with data transmission while utilising DSL to connect ...
A: Introduction: DSL, which stands for full digital subscriber line, is a networking technology that al...
Q: Using an example, explain how allocation of a heap element can be implemented when we are given the ...
A: A heap is a complete binary tree, and the binary tree is a tree in which the node can have atmost tw...
Q: 3. a) A stack is an Abstract Data Type (ADI). Basic operations of stack are PUSH, POP, PEEK/TOP. Imp...
A:
Q: In which memory segments are the variables in the following code located? Explain your reasoning. ...
A: We have a memory layout like below
Q: In a three-tier design, how does information flow?
A: Introduction: Architecture with three levels-
Q: What exactly is a cyber risk assessment?
A: Introduction: We discover, analyze, and evaluate risk in cyber security risk assessments. In this w...
Q: Compare and contrast Business Intelligence (BI), Machine Learning, and Data Mining. Provide real-wor...
A: Answer: Business Intelligence: This area is ...
Q: Try to design a game in which the user has to guess a number and If it is in 100 to 125 then you hav...
A: Required:- Try to design a game in which the user has to guess a number and If it is in 100 to 125 t...
Q: Explain whether HeapSort is a stable sort or NOT. Prove your argument or give a counterexample.
A: Given :- Explain whether Heapsort is a stable sort or NOT.Prove your argument or give a counterexamp...
Computer Science
For each of the code snippet given below, identify the error and then write code after fixing the error.
Given code is the simulation of grep -v command. -v prints all lines that do not match a specific
pattern.
void grep_inverse(char *filename, char *str)
{
FILE *fp;
char buf[buff_size];
fp = fopen(filename, "r");
if(!fp) {
perror(filename);
}
else {
while (fgets(buf, buff_size, fp) != NULL) {
if ((strstr (buf, str)) != NULL)
printf("%s", buf);
}
}
fclose(fp);
}
Step by step
Solved in 2 steps
- Using only BufferedReader and BufferedWriter to read/write files and only arrays for any data structure needs, create a static method reverseLineOrder which accepts the arguments: Filename to the input file as a String Filename of the output file as a String The method will create a new file with the lines from the given data set in reverse order. Data.txt: 1 2 3 4 5 6 7 8 9 0 9 8 7 6 5 4 3 2 1 0 8 7 6 5 4 3 2 1 0 9 Subject: Java ProgrammingWhat would be the content of out.txt after executing the following code? int main() { ofstream file("out.txt"); double num = 3.1415; file << fixed; file << num << endl; file << setprecision(3); file << num << endl; file << setprecision(2); file << num << endl; file << setprecision(1); file << num << endl; return 0;} Group of answer choices 3.14153.143.13 3.14153.1423.143.1 3.1415003.1423.143.1 3.1415003.14153.1423.14Write a program that uses the natural merge algorithm on the two data files provided (merge_1.txt and merge_2.txt) to merge the two files into one, and then state which value appears at index 100. File format: a single integer that is the number of values to follow, followed by at least that number of integers. That first integer is not part of the data. merge_1.txt 100350 659 684 484 735 514 723 473 127 747 735 167 482 954 914 173 186 910 819 879 403 543 776 674 796 342 84 197 130 968 296 863 739 6 301 684 542 515 199 310 338 274 3 57 391 411 968 621 901 370 16 136 818 56 28 171 599 331 979 329 919 946 814 88 75 425 691 650 777 374 688 625 315 199 412 536 617 200 938 293 560 623 426 958 991 279 321 389 310 5 500 578 161 356 889 792 685 625 59 971 merge_2.txt
- Consider the binary file named, "Course_Data" whose format is below. Each record represents a course with a single letter grade, a numerical grade, and the number of assignments in the course. Write a block of code to read the first 200 records and find and print the average of all courses whose letter grade was an "A". Maximum 20 lines of code for credit. (Assume all libraries are included) File format:{ char LGrade; // Letter Grade: A, B, C, D, F (Single letter) int NGrade; // Number Grade: 0 - 100 int NOA; // Number of assignments: 1 - 20}Write a program that reads the-zen-of-python.txt and writes each line to UpdatedZen.txt, a new text file. It capitalizes the first character of each line and adds a period to the end of each line before writing it back to updatedzen.txt. the-zen-of-python.txt file contents: beautiful is better than ugly explicit is better than implicit simple is better than complex complex is better than complicated flat is better than nested sparse is better than dense readability counts special cases aren't special enough to break the rules although practicality beats purity errors should never pass silently unless explicitly silenced in the face of ambiguity, refuse the temptation to guess there should be one-- and preferably only one --obvious way to do it although that way may not be obvious at first unless you're Dutch now is better than never although never is often better than *right* now if the implementation is hard to explain, it's a bad idea if the implementation is easy to explain, it…Modify the program 11-10 from pages 753-755 as follows: 1. To Length class files (Length.h and Length.cpp) add the operator overload for stream insertion (<<) and stream extraction (>>) from page 759. You should not use the modified version of class Length from page 759 because it contains more operator overloads. Instead of typing you can use copy/paste from Length1.h and Length1.cpp respectively. 2. In main() replace the lines 11-16 with appropriate usage of stream extraction overload (>>) to change "first" and "second" objects with values inputted by the end user. 3. In main(), replace the output on lines 21,22 and 25,26 with appropriate usage of stream insertion (<<) operator. The resulting output should be identical with the unmodified version of the program. 11-10: // This program demonstrates the Length class's overloaded // +, -, ==, and < operators. #include <iostream> #include "Length.h" using namespace std; int main() { Length first(0),…
- given a text file (data1.txt) that consists of different garbage strings.1.Create a new file, from data1.txt, which contains all the strings from theprevious file with the following constraints:-No special characters or digits must be in the new string-No repetition of letters in the new string• Save the newly generated text-file as data2.txtThe following example in table 1 shows what your output file should contain.data1.txt data2.txtf5@p fpp&ott6 potInstructions:Create a class cleanFile to read in data1.txtClean the data inside the files following the rules in the above exampleWrite the cleaned data into data2.txtmodify minishell.c to run who, ls, and date with option. who will show the count of users, ls will list files in long listing format and date will show UTC time. Modify this file so the shell can run commands with options.*/#include <stdio.h>#include <unistd.h>#include <sys/types.h>#include <sys/wait.h>#include <stdlib.h>#include <fcntl.h> int main(int argc, char *argv[]){ char *cmd[] = {"who", "ls", "date"}; int i; while(1){ printf("0=who 1=ls 2=date : "); scanf( "%d", &i ); if(i<0 || i>2) continue; pid_t result= fork(); if(result==0) { /* child */ execlp( cmd[i], cmd[i], (char *)0 ); printf("execlp failed\n"); exit(1); } else if (result >0){ /* parent */ int status; wait(&status); } else{ //handle error } } return 0;}Modify task5.c so it will print out a content of a file backward. You will need to use lseek() to accomplish this task. Modify this program to print the file backward.*/ #include <stdio.h>#include <unistd.h>#include <fcntl.h> int main(int argc, char *argv[]){ char *filename = argv[1]; int input = open(filename, O_RDONLY); char c; while(1){ int r = read(input,&c,1); if(r==0) break; write(1,&c, 1); } close(input); return 0;}
- A user wants to write a C program for manipulating student records. The program contains a function for accessing the student file. The user wants to add some records to the file. Which of the following line of code is used to open the student file for implementing this functionality? Choose an answer A fp = fopen ("studentfile.dat", "r"); B ch = fgetc(fp); C fp = fopen ("studentfile.dat", "w"); D fputc (ch, fp);I have the following code but it is not running correctly! import csvlst = []def save_dict_to_csv(storage, file_name): with open(file_name, 'w', newline = '') as f: f.write(file_name) f.write('\n') for key, value in storage.items(): lst1 = [] lst1.append(str(key)) for val in value : if type(val) == list: for v in val: lst1.append(str(v)) else: lst1.append(str(val)) for i in range(len(lst1)): if i != (len(lst1) - 1): f.writelines(lst1[i] + ',') else: f.writelines(lst1[i]) f.writelines('\n') f = open(file_name) print(f.read()) if __name__ == "__main__": storage = { 101: ["quiz", 12, [1,2,3,4]], 102: ["final", 53, [10, 10, 10, 10]] } res = save_dict_to_csv(storage,…What would be the printout of the following code if the same file.txt was used as above? int main() { fstream file("file.txt", ios::in); char ch; file.get(ch); while (!file.eof()) { cout << ch << " "; file.get(ch); } file.close(); return 0;} Group of answer choices I have a dream. I h a v e a d r e a m . Ihaveadream. I have a dream.I have a dream.