Programming in C
4th Edition
ISBN: 9780321776419
Author: Stephen G. Kochan
Publisher: Addison-Wesley
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 12, Problem 1E
Explanation of Solution
Purpose of given code 12.1.:
- The code “
Program 12.1.” is to check given value is even or not. It has a function named “isEven()” which get an argument and checks the value of the argument is even using “if…else” condition. - If the given argument value is even, the macro value of “YES” stored into the variable “answer” otherwise it assigned macro value of “NO” to the variable “answer”.
- The main program calls the function with argument as “17” and “20”.
Expert Solution & Answer
Sample Output
no yes
Comparison:
The type in code prints the above output which is “equal” to the output presented in the text book. The function returns “no” for the input value “17” and returns “yes” for the input value “20”.
Want to see more full solutions like this?
Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
python help, fill in the "your response" parts
Write function quoteByNum() that takes as input the name of a file (as a string) and an index i (as an integer). The file will contain quotes, one per line. The function should open the file, read the file, close the file, and return the i-th quote (i.e. the i-th line in the file), assuming that the quote numbering starts at 0. Test your solution on file Wilde_Quotes.txt.>>> quote("Wilde_Quotes.txt", 5)'At twilight, nature is not without loveliness, though perhaps its chief use is to illustrate quotations from the poets.\n'>>> quote("Wilde_Quotes.txt", 0)'A little sincerity is a dangerous thing, and a great deal of it is absolutely fatal.\n'>>> quote("Wilde_Quotes.txt", 23)'Patriotism is the virtue of the vicious. \n'>>>
def quoteByNum(file, int1):
your response (docstring)
infile = open(file) # your response
content = infile your…
Use Scanner and File to read input from a file.
Use PrintStream and File to write output to a file.
Write and call methods that accept parameters and return values to manage information flow and add structure to programs.
Follow prescribed conventions for spacing, indentation, naming, and comments.
Notice that if an input file is not found, either for creating a mad-lib or viewing an existing one, the user is re-prompted. No re-prompting occurs for the output file. If the output file does not already exist, it is created. If it does already exist, its contents are overwritten. (These are the default behaviors in Java.) You may assume that the output file is not the same file as the input file.
When you are viewing an existing mad lib story, you are simply reading and echoing its contents to the console. You do not need to do any kind of testing to make sure that the story came from a mad lib input file; just output the file's contents.
Menu options can be chosen in any order and are…
Create the following programs in C++. Each program should be reading from a file (i.e., test1.txt, test2.txt, test3.txt) and then outputting the following to the screen. Note: No parameters in the main function
Program 1: last line of the file
Program 2: size of the longest line of the file
Knowledge Booster
Similar questions
- (5) Write a function called copy_even_lines() that takes two strings (filenames) as input parameters and copies every other line from the first file into the second. That is, counting from 0, it copies the 0th line, the 2nd line, the 4th line, etc. from the first file to the second file. You may assume that both files exist. (6) Write a python program that asks the user for two filenames and calls your function copy_even_lines() from (5) using those two filenames. If one or more files do not exist, your program must handle the exception by repeating the prompts until valid filenames are entered.arrow_forward3. Laramie Park District has files of participants in its summer and winter programs this year. Each file is in participant ID number order and contains additional fields for first name, last name, age, and class taken (for example, Beginning Swimming). a. Design the logic for a program that merges the files for summer and winter programs to create a list of the first and last names of all participants for the year in ID number order. b. Modify the program so that if a participant has more than one record, the participant's ID number and name are output only once. c. Modify the program so that if a participant has more than one record, the ID number and name are output only once along with a count of the total number of classes the participant has taken.arrow_forwardQ4. Write an algorithm of a program to read from a file. The user should be able to get the option to input the file name. He is supposed to read first 100 bytes from the file. After the reading is done, the file should be closed. If the file is not available, the program should be closed immediately. You should mention "System call" beside each instruction which are supposed to use a system call function. *arrow_forward
- You are creating a function that reads a data file and prints each line of the file. You write the following code. Line numbers are included for reference only The code attempts to read the file even if the file does not exist. SEE PHOTO You need to correct the code. Which three lines have indentation problems? Each correct answer presents part of the solution. (Choose three.) Group of answer choices Line 04 Line 03 Line 05 Line 02 Line 06 Line 07 Line 01 Line 08arrow_forwardWrite a function to input patient information and store it in a file. One of the parameters of the function must be no. of patients to input and another one the name of the file to store the information.arrow_forward100% Solve the exercise specified by your instructor and submit the python source file before the deadline on E-learn page. It is highly recommended to solve ALL of the following exercises. Exercise 1: Write a Python program that reads from the user the name of two files (an input file and an output file). The program will then read each line of the input file and save it in the output file preceded with the line number and removing any of the following punctuations (., !?;:) found at the end of the line. For example, if the input file is: Mary had a little lamb; Whose fleece was white as snow; And everywhere that Mary went; The lamb was sure to go! Then the output file the content of the input file and saves it in the produced output file will be Line 1: Mary had a little lamb Line 2: Whose fleece was white as snow Line 3: And everywhere that Mary Line 4: The lamb was sure to goarrow_forward
- Do not read directly from the example files, as the automated testing system expects you to read from the standard input. Instead, process the lines as follows: 3 - Geography Grades 3 Make a copy of your program for the problem Geography Grades 2 and change the code in such a way that your program can process multiple groups. These groups are on the input separated by ’=\n’. Every group starts with a first line that contains the name of the group and the lines after contain the information about the students in the same way as is specified for the problem Geography Grades 1. With the input 1bErik Eriksen__________4.3 4.9 6.7Frans Franssen________5.8 6.9 8.0=2bAnne Adema____________6.5 5.5 4.5Bea de Bruin__________6.7 7.2 7.7Chris Cohen___________6.8 7.8 7.3Dirk Dirksen__________1.0 5.0 7.7 The output should be: Report for group 1bErik Eriksen has a final grade of 6.0Frans Franssen has a final grade of 7.0End of reportReport for group 2bAnne Adema has a final grade of 6.0Bea de Bruin…arrow_forwardPlease use Python for this question. Please format code properly when answering the question. Write a standalone function partyVolume() that takes accepts one argument, a string containing the name of a file. The objective of the function is to determine the Volume object that is the result of many people at a party turning the Volume up and down. More specifically: the first line of the file is a number that indicates the initial value of a Volume The remaining lines consist of a single character followed by a space followed by a number. The character will be one of ‘U” or ‘D’ which stand for “up” and “down” respectively. The function will create a new Volume object and then process each line of the file by calling the appropriate method of the Volume object which changes the value of the Volume. The function then returns the final Volume object. Guidelines/hints: This is a standalone function, it should NOT be inside (indented within) the class. It should be listed in…arrow_forward(a) Modify the program in Task 2 to write the data from Table 2 into a text file named "weather.txt". (b) Write a program to read the data from the file "weather.txt" and find the number of hot countries, warm countries and cold countries from the list. The program should display the result in the following format: Country Country Code Week 1 Week 2 Week 3 Average Temperature Category Number of hot countries Number of warm countries Number of cold countriesarrow_forward
- Using a sound level meter, the noise emanated from 10 Proton X50 at different frequency levels are measured and shown in Table-1. (a) (b) Write a program in C to write the data into a binary file named proton.txt. Write a program that reads the data from the file proton.txt and find the car that emanates the minimum noise at 100HZ. Also write a program that reads the data from the file proton.txt and find the cars whose noise level is less than 60 dB at 400 Hz. (c) Table-1 Car Noise Level (dB) Vehicle Number 50HZ 100HZ 200HZ 400HZ 800HZ 52.4 60.3 63.5 48.4 AKU4444 55.7 63.1 BKT9876 51.5 46.3 49.6 50.3 CBU5971 56.3 61.2 60.3 59.7 58.1 CKD2813 57.9 58.6 63.2 65.3 64.9 59.2 DEL8690 JАP7561 53.0 60.5 54.7 62.4 63.1 51.2 52.4 58.3 60.9 KUL9781 55.8 58.1 59.6 61.8 62.5 ММА1985 49.1 48.2 50.5 53.7 57.8 PPP8668 43.6 44.8 48.4 47.1 50.8 RAA6767 58.7 56.9 58.1 60.5 62.3arrow_forwardProblem: Write a program that reads from an input file, given by a user, students grade information after a semester and your program generate a semester report including courses information as shown in the sample runs. The input file includes student information: name, id, and college, followed by cumulative of previous semesters: total credits attempted, credits earned and total grade points. At the end of the input file the grades and information of the last completed semester courses are provided as shown in the sample inputs. Your program will calculate the total attempted credits, semester earned credits, semester grade point average (GPA) and cumulated grade point average (CGPA) according to the courses' grades and the number of credit hours of the courses. The scales of each grade are shown in Table 1. F, FSP, FW, and NPW grades will have zero value. Table 1 Grade scales A 4.00 C+ 2.30 A- 3.70 2.00 B+ 3.30 C- 1.70 B 3.00 D+ 1.30 B- 2.70 D 1.00 The Grade Point Average (GPA) is a…arrow_forwardWrite a short notes on the following appending to a file deleting a filearrow_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