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
Answer the given question with a proper explanation and step-by-step solution.
In this exercise, you are to modify the Classify Numbers programming example in this chapter. As written, the program inputs the data from the standard input device (keyboard) and outputs the results on the standard output device (screen). The program can process only 20 numbers. Rewrite the program to incorporate the following requirements:a. Data to the program is input from a file of an unspecified length; that is, the program does not know in advance how many numbers are in the file.
b. Save the output of the program in a file.c. Modify the function getNumber so that it reads a number from the input file (opened in the function main), outputs the number to the output file (opened in the function main), and sends the number read to the function main. Print only 10 numbers per line.d. Have the program find the sum and average of the numbers.e. Modify the function printResult so that it outputs the final results to the output file (opened in the function main). Other than outputting…
By using files:
Please Write Python program design at the beginning of program:define the purpose, Input /output data and Algorithm
and please write the program testing ( for cases that could happen)
Knowledge Booster
Similar questions
- 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…arrow_forwardpython 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…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
- Type in C Make sure the student ID shows for each line please.arrow_forwardYou 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_forwardDo 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_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_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_forwardwrite in python Note:- Do not provide handwritten solution. Maintain accuracy and quality in your answer. Take care of plagiarism. Answer completely. You will get up vote for sure.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