If a read-loop is written to process an unknown number of values using the while construct, and if there is one read before the while instruction there will also be one __________.
a. |
at the bottom of the body of the loop |
|
b. |
in the middle of the body of the loop |
|
c. |
at the top of the body of the loop |
|
d. |
there are no other reads |
The correct option is a
Explanation:
Consider the following algorithm/pseudocode to read unknown number of values from a file and compute their sum:
infile = open(“sample.txt”, ‘r’)
value = infile.readline()
sum = 0
while (value != EOF):
{
// Perform the operation on the value.
sum = sum + int(value1)
// Read the next line.
value = infile.readline()
}
infile.close()
print(sum)
Hence, the correct answer is option a, at the bottom of the body of the loop.
If a read-loop is written to process an unknown number of values using the while construct,...
Using basic c++ 2. Count the positive and negative numbers using ***while loop*** • Write a program that reads unspecified number of integers , determines how many negative and positive values have been read. Also calculate total and average. Your program will end with input 0. • Output Enter an integer, the input ends if it is 0: 25 34 -89 72 -35 -67 21 48 0 The number of positives is 5 The number of negatives is 3 The...
(While-loop controlled by a sentinel value) Write a program that reads an unspecified number of integers. Your program ends with the input 0. Determine and display how many positive and negative values have been read, the maximum and minimum values, and the total and average of the input values (not counting the final 0).
2. Read in an unknown number of real values from a file called “data.txt”. Calculate the average of the real numbers. Output the average of the real numbers to a file called “output.txt”. Some skeleton code is provided for you below. #include int main (void) { FILE *infile = NULL; FILE *outfile = NULL; /* Fill in the code to open a file. Make sure you check that the file was open successfully. */ while (!feof (infile)) { /*...
PYTHON Ask the user for an integer number n. Construct, using one single loop, the list with the values [1,2,3,4,…,n] and the list with the values [1^2 ,2^2 ,3^2 ,…n^2 ] by using list concatenation ). After this loop is over, use a separate loop to show the user the two results by printing corresponding elements from the two lists in the same line, as follows: 1 1 2 4 3 9 … …
Objectives: Use the while loop in a program Use the do-while loop in a second program Use the for loop in a third program Instructions: Part A. Code a for loop to print the Celsius temperatures for Fahrenheit temperatures 25 to 125. C = 5/9(F – 32).Output should be in a table format: Fahrenheit Celsius 25 ? . . . . . . . . Turn in the source and the output from Part A. Part B. Code a while...
Write a C program named space_to_line.c that features a while loop that continuously reads input from the user one character at a time and then prints that character out. The exception is that if the user inputs a space character (‘ ‘), then a newline character (‘\n’) should be printed instead. This will format the output such that every word the user inputs is on its own line. Other than changing the spaces to newlines, the output should exactly match...
Write a complete C++ program using a while loop to read a list of integers ending with the integer 999. Count and output the number of integers in the list that are greater than 500. If there is no integer in the list that is greater than 500. output (only once) the message that "No integer in the list is greater than 500". Do not use functions.
Rewrite the following loops without using the enhanced for loop construct. Here, values is an array of floating-point numbers. a. for (double x : values) { total = total + x; } b. for (double x : values) { if (x == target) { return true; } } c. int i = 0; for (double x : values) { values[i] = 2 * x; i++; }
1. (a) Before entering any while loop, the while loop condition is. . . A. true B. false C. true or false (b) At the beginning of each iteration, a while loop condition is. . . A. true B. false C. true or false (c) When the loop terminates, a while loop condition is. . . A. true B. false C. true or false (d) Which of the following statements will not cause a compile-time error? A. byte b =...
PLEASE READ AND CODE IN BASIC C++ CODE. ALSO, PLEASE CODE USING THIS DO WHILE LOOP AND FORMAT: #include <iostream> using namespace std; int main() { //variables here do { // program here }while (true); } Objectives To learn to code, compile and run a program containing SELECTION structures Assignment Write an interactive C++.program to have a user input the length of three sides of a triangle. Allow the user to enter the sides...