What type of loop, such as counter control or sentinel control, will you use in each of the following situations?a. Sum the following series: 1 + (2 / 1) + (3 / 2) + (4 / 3) + (5 / 4) + ... + (10 / 9)b. Sum the following numbers, except the last number: 17, 32, 62, 48, 58, -1c. A file contains employees’ salary. Update employees’ salary.
Q: The equivalent resistance Reg of four resistors R₁, R2, R3 and R4 connected in series is given as…
A: Code: ch=input('Enter the type of connection(1 for series and 2 for parallel): ');if(ch==1 || ch==2)…
Q: Write a for loop to print each contact in contact_emails. Sample output with inputs: 'Alf'…
A: For loop to print each of the contact in contact_emails for x,y in contact_emails.items():…
Q: you use a while loop? a. when you want some code to continue running as long as some condition is…
A: [no. 19] When would you use a while loop? a. when you want some code to continue running as long…
Q: i am just wondering what does this piece of code do, what language is it and what meaning it has…
A: In this question we have to understand what programming language is present in the code given and…
Q: Use EMACS to correct the script below: ############################################### # Favorite…
A: Code: echo -n "What do I like to eat? "read estimatecalculation=0while [ "$estimate" != "Fish &…
Q: Problem G. Just Map Input file: Output file: Time limit: standard input standard output 1 second 256…
A: C++ Source Code: #include <iostream>#include <string>#include…
Q: What is the expected output of the for loop given below? Assume all necessary declarations of…
A: The for is a loop statement that repeats a statement or a set of statements of for loop until the…
Q: 3) Which is true? A for loop: A) Has a loop counter variable in the command B) Does not have a loop…
A: Choose the correct option about a for loop from the given two choices.
Q: Write a program by using the for-lo
A: A = pascal(5); B = magic(7); m = 5; n = 7;
Q: Given the C loop: while (x != y) { .. }. Assume x is in $s0 and y is in $s1. Which option should be…
A: According to the question, the given example of coding in C is as below : while( x != y) {…
Q: ut.txt has characters a, b, c, d, e, f Numbers should be written to output.txt when character is…
A: step 2 contains the solution
Q: You will have an orthogonal triangle input from a file and you need to find the maximum sum of the…
A: Please give positive ratings for my efforts. Thanks. ANSWER using System;using…
Q: Question 4 Unroll the following loop 2 times F0 , 32(R1) Sub F2, F0 , F6 F2 , 32(R1) Subi R1, R1 ,…
A: Answer: I have given answered in the handwritten format in the brief explanation.
Q: which for loop will not work? A) for (i-5; i<=10; i++) B for (i-5; i-10; i++) c) for (i=0; i<5; i++)
A: Answer is Option B) for(i=5;i=10;i++)
Q: 18. What type of loop, such as counter control or sentinel control, will you use in each of the…
A: Sentinel-Controlled: Because it is unpredictable how many times the loop will be run,…
Q: 2. Can a for loop contains another for loop? a) No c) Compilation b) Yes d) Runtime Error 3. Which…
A: Ans(2): b A for loop can contain any loop including another for loop also. Ans(3): b Ans(4): c…
Q: You will read data from a text file using a control loop, convert the numbers to the proper format,…
A: The answer given as below:·
Q: Write a program that uses a while loop to store goals and assists for Lightning players in a text…
A: Note: Since no programming language is mentioned. I am attempting this in python. if you need it in…
Q: Which of the following is a count-controlled loop?a. forb. foreachc. whiled. do-while
A: a) The correct option is b.) for loop
Q: Write your codes in a single m.file Write commend to each line for explaining the line Write a code…
A: Hey there, I am writing the required solution based on the above given question. Please do find the…
Q: Write a program named program6_1.py that prompts the user to enter six test names and their scores…
A: Please find the answer below :
Q: script that print all
A: Step by step descriptive logic to print all even range between one to n victimisation if…
Q: Q3. There are two existing data files: "rawdata.txt and 'marks.txt. The file 'rawdata.txt is used to…
A: C++ program is given below
Q: 6) Write a program in a script file that finds the smallest odd integer that is divisible by 11 and…
A: We need to write a program that finds the smallest odd number divisible by 11 and whose square root…
Q: 2) Start with a working copy of loop-2.py from last lab, and name it Welcome to our counting…
A: The python code for counting the numbers , here we accepted the input from the user for smaller…
Q: A.1. CREATE A PROGRAM USING LOOPING (FOR, WHILE & DO-WHILE) BASED ON THE OUTPUT BELOW: 1.…
A: This question comes from Programming Language which is a paper of Computer Science. Let's discuss it…
Q: 10- What does the following code best represent ? always@ (posedge clk ) begin if (reset). end a) An…
A: Q10. always@(positive edge) means at the positive edge of clock we need to execute the further…
Q: Ask the user for a filename that contains an unknown number of integers. Print the numbers one per…
A: Since multiple questions have been posted at a single request, we will answer only first question…
Q: program6_1.py BetterBuy is having a sale. Write a program that uses a while loop to store to a file…
A:
Q: ## This function is used to generate the input file Directory.txt # def generateInputFile(): try:…
A:
Q: The first line is string and second line is a substring. Search the substring and write the count…
A: Code: #include <stdio.h>#define str_size 100 //Declare the maximum size of the stringint…
Q: We wan to create a for loop that counts the unique variables in all columns of an excel file that…
A: This is very simple. You can do this in ONE line in Python. ------------------------------------…
Q: Input file is given like this: 4 4 XXXX X XX X XX X
A: As programing language is not mentioned, so we are providing answer in python langauge.
Q: Explain the code solution to this problem in a step-by-step way. The steps should be described in…
A: logic:- open file in write mode using f.open() function. Use for loop :- for i in range(1,4) to…
Q: Suppose thattis initially set to 0 and upper bound is initially set to 5. After how many iterations…
A: Program code: #initializing variables with #given values t=0 upper_bound=5 #while loop #will run…
Q: SAMPLE OUTPUT My friend Denny is 24 My friend Penny is 28 My friend Lenny is 20 My friend Jenny is…
A: INPUT:Denny 24Penny 28Lenny 20Jenny 24 OUTPUT:
Q: Write a program using a for loop that creates a file and adds even numbers the integers 1 through 20…
A: Code: #code to add numbers in file addInFile= open("numbers.txt", 'w') for i in range(1,21): if…
Q: select the python loop that prints directory names, subdirectories, and files in the path. for…
A: os.walk(directory) yields a 3-tuple for each subdirectory in the tree. It will return the directory…
Q: Question 1 How many cycle need the following code to finish execution? Loop : LD F0,RI ADD F5,F2,F4…
A: Answer: I have given answered in the handwritten format in brief explanation.
Q: w do I write a Python Program that determines and print the average age of the friends on file. That…
A: fp = open("friends.txt", "w") firstname = input("Enter first name of friend or Enter to quit ")…
Q: So below is the question of the problem for my class. I have attached a picture of my python…
A: List index out of range happens when you try to access the elements that are outside the range of…
Q: I write a program to record student data in the form of records for every record that contains…
A: Program #include <iostream>#include<stdlib.h>using namespace std; struct student{…
Q: Is the following code fragment is a correct example of the use of a WHILE loop.Would it work without…
A: Given:
Q: Subject) - jcofield122e x O Lab 6: Module 6 - Repetitic x…
A: Here since programming language not mentioned using C
Q: Write a program using a for loop that creates a file and adds odd numbers that are in the integers 1…
A: Given: Write a program using a for loop that creates a file and adds odd numbers that are in the…
Q: how do we keep prompting the user to enter the right file name when the file name is wrong?…
A: The given code keep prompting the user to enter the right file name until the file name is not…
Q: Given the following pseudocode that correlates with climbing 10 steps in a flight of stairs, answer…
A: The given for loop iterates from step=1 to 10 Prints step number in every step If step=10 it prints…
Q: ## This function is used to generate the input file Directory.txt 2 ## Run this cell to gererate the…
A: Writting the code in python :
Q: Write a program that reads a file consisting of students’ test scores in the range 0–200. It should…
A: Store given score's in a text files and open a files in reading mode using ifstream objects. Then…
What type of loop, such as counter control or sentinel control, will you use in each of the following situations?
a. Sum the following series: 1 + (2 / 1) + (3 / 2) + (4 / 3) + (5 / 4) + ... + (10 / 9)
b. Sum the following numbers, except the last number: 17, 32, 62, 48, 58, -1
c. A file contains employees’ salary. Update employees’ salary.
Trending now
This is a popular solution!
Step by step
Solved in 3 steps
- 2. Now write a program named filereader.py that reads and displays the data in friends.txt. This program should also determine and print the average age of the friends on file. That will require an accumulator and a counter. Use a while loop to process the file, print the data, and modify the accumulator and counter. Then close the file and use an f-string display the average age accurate to one decimal place. See the Sample Output..SAMPLE OUTPUT My friend Denny is 24My friend Penny is 28My friend Lenny is 20My friend Jenny is 24Average age of friends is 24.0write you c++ code to read a file contains simple +/- maths equations and change it to plus and minus input file example: A+B, 10+20,30-50,8=100output file example A plus B , 10 Plus 20 , 30 minus 50 , 8 plus 100The iostream library provides mechanisms for error handling, such as the failbit, badbit, and eofbit. However, if these are not checked after an input/output operation, it can lead to incorrect program behavior. For example, if you attempt to read past the end of a file without checking eofbit, the program may enter an infinite loop. *Can you provide a simple program of the above paragraph? How do you correct this vunerability?*
- Question B. Write a C++ program that reads the marks of a group of students from a text file "grades.txt" and computes the average of all grades. The program must check the file for any opening problems, and then proceeds to do the other tasks. The input file can have 1 or more students. The text file and sample-output are shown as below: O grades - Notepad File Edit Format View Help 60.0 78.6 78.0 98.6 77.7 55.0 73.0 80.7 80.0 85.0 Windows (CF Ln 13, Col 1 100% CAUsers\Imran\Desktop\Lab111\Debug\Lab111.exe Average of 10 students is 77 Press any key to continue... Activa Coto sAssume that infile has been properly defined to read data from a file and that a file of integers has been properly opened. If you don't know how many integers are in the file, which loop(s) would be appropriate to read in all the values from the file? Variable n has been defined as an int. 1. while(! infile.eof()) 2. for(int x = 0; x < 1000000; x++) 3. while(infile >> n) Answers: A. Both 2 and 3 B. 1, 2, and 3 C. Both 1 and 2 D. Both 1 and 3 E. 3 onlyWrite a Python program to combine each line from the first file with the corresponding line in the second file and then save it in a 3rd file. Consider, both the files have same number of lines. Assume, each line has a newline(\n) at the end. ========================================================= Example:Input from file 1:HelloHiNice Input from file 2:BadWorseWorst Output in 3rd FIle:Hello BadHi WorseNice Worst ========================================================= Hint(1):Use the write() function what will be the answer of this in python programming language
- [no. 19] When would you use a while loop? a. when you want some code to continue running as long as some condition is true b. when you want to run code in one file while code in another file is also running c. when you want to minimize the use of strings in your code d. when you need to run two or more chunks of code at once within the same fileWhen I run the following code, and receive the output songs_time.txt file, it doesn't show any of the songs numbers or time remaining in the output table. I have the input songs.txt file path copied into the file_in location but don't know what is wrong. //headers files #include <iostream> #include <iomanip> #include <fstream> //using namespace using namespace std; //main() function is defined int main() { cout << "Bartleby---xxxxxxx" << endl << endl; //declaring the variables as per the requirement int song_min, song_sec, total_min, total_sec, total_time = 0, remain_time, remain_min, remain_sec; int serial_num, s_sec; //initialising the holding time of CD to 80 minutes int hold_time = (100 * 60); //reading data from the file fstream file_in("C:\Users\gabri\OneDrive\Desktop\songs.txt", ios::in); //writing data as output on the file fstream file_out("songs_time.txt", ios::out); //displaying the heading of the…Program in C only - thanks Write a C Program that writes all the numbers from 1 to 100,000 that are both prime and the sum of the digits > 9. For example 47, 911 are 2 such numbers, since the sum of the digits is > 9. After finding a number, you must immediately write it to the output file. Open the file, write the number you just found, and close the file. Measure how much elapsed time it takes to do this processing. Yes, it is inefficient, but we are trying to force some I/O usage, which will cause interrupts. When this process is completed, next have the program fork and create 10 separate processes. Each process would find search a range of 1 to 100,000 for these prime and sum 11 numbers. One process searches 1 to 10000, another 10001 to 20000 etc. Each process performs the exact same tasks , in the same way, as the first part of the problem, but write the output to 10 separate files, one for each process. When all 10 processes are done, read the ten files to make one file…
- This is for r Regarding a for loop, which of the following is not true? The for keyword must be followed by parentheses. Following the for statement, the code to be executed is recognized by it being indented. The number of times the loop will be performed is determined by the length of the vector passed to the for keyword. The for loop can contain other for loops.Will this loop run infinitely? Or will it stop? Why?data = [0, 2, 4, 6, 8]for i in range(len(data)):data.append(data[i] + 1)Please answer all questions for the while loop: while loop x=9; // loop variable while (x>0) { cout << x <<” , “ endl; x = x - 1;// update } Questions: 1.What is the name of loop variable, or loop control variable? 2.How many iterations does the loop do? 3What is initial value of count? 4.What is value of i when the loop exits (fails) 5.What is the output of the code? See below: 9, 8, 7, 6, 5, 4, 3, 2, 1, 6.What is increment in i between each each iteration 7.Observe semicolons, commas 8.When is the variable incremented: Beginning or