Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 6.3, Problem 29STE
Explanation of Solution
Program:
//Include the needed headers
#include <fstream>
#include <iostream>
using namespace std;
//main() Method
int main( )
{
//creating object for ifstream
ifstream fin;
//a handle for opening the input file
fin.open("stuff...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a write_scores function that opens the file, and writes scores and names from lst_scores and lst_names into the file. An example function call is below. Make sure to handle a file error. Assume good input in both lists.
Function name: write_scoresParameters: lst_scores, a list of ints; lst_names, a list of strings; file_name, a string Purpose: Writes the names and scores to the file name, with one name and one corresponding score per line.Example function call:
(attached)
After this code runs, the file final_grades.txt should read:
Ayesha 96
Paolo 99
Ahmed 93
Anna 94
The functions that belong to the I stream should be defined.
in C program please
Chapter 6 Solutions
Problem Solving with C++ (10th Edition)
Ch. 6.1 - Prob. 1STECh. 6.1 - Prob. 2STECh. 6.1 - Suppose that you are still writing the same...Ch. 6.1 - Prob. 4STECh. 6.1 - Prob. 5STECh. 6.1 - Prob. 6STECh. 6.1 - Suppose bla is an object, dobedo is a member...Ch. 6.1 - Prob. 8STECh. 6.1 - Prob. 9STECh. 6.1 - A program has read half of the lines in a file....
Ch. 6.1 - Prob. 11STECh. 6.2 - Prob. 12STECh. 6.2 - Prob. 13STECh. 6.2 - Prob. 14STECh. 6.2 - What output will be sent to the stuff.dat when the...Ch. 6.2 - Prob. 16STECh. 6.2 - In formatting output, the following flag constants...Ch. 6.2 - Here is a code segment that reads input from...Ch. 6.2 - Prob. 19STECh. 6.2 - Write the definition for a void function called...Ch. 6.2 - (This exercise is for those who have studied the...Ch. 6.3 - Suppose c is a variable of type char. What is the...Ch. 6.3 - Suppose c is a variable of type char. What is the...Ch. 6.3 - Prob. 24STECh. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Suppose that the program described in Self-Test...Ch. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Prob. 29STECh. 6.3 - Define a function called copyLine that takes one...Ch. 6.3 - Prob. 31STECh. 6.3 - (This exercise is for those who have studied the...Ch. 6.3 - (This exercise is for those who have studied the...Ch. 6.3 - Suppose ins is a file input stream that has been...Ch. 6.3 - Write the definition for a void function called...Ch. 6.3 - Consider the following code (and assume that it is...Ch. 6.3 - Write some C++ code that will read a line of text...Ch. 6 - Write a program that will search a file of numbers...Ch. 6 - Write a program that takes its input from a file...Ch. 6 - a. Compute the median of a data file. The median...Ch. 6 - Write a program that takes its input from a file...Ch. 6 - Write a program that gives and takes advice on...Ch. 6 - Write a program that reads text from one file and...Ch. 6 - Prob. 7PCh. 6 - Write a program to generate personalized junk...Ch. 6 - Write a program to compute numeric grades for a...Ch. 6 - Enhance the program you wrote for Programming...Ch. 6 - Prob. 4PPCh. 6 - Write a program that will correct a C++ program...Ch. 6 - Write a program that allows the user to type in...Ch. 6 - This project is the same as Programming Project 6,...Ch. 6 - This program numbers the lines found in a text...Ch. 6 - Write a program that computes all of the following...Ch. 6 - The text file babynames2012.txt, which is included...Ch. 6 - To complete this problem you must have a computer...Ch. 6 - Write a program that prompts the user to input the...Ch. 6 - The following is an old word puzzle: Name a common...
Knowledge Booster
Similar questions
- 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 count_character(filename, character) that takes in a filename and a character, both as strings, and returns the total number of times the given character occurs in the file. Examples: Contents of hello.txt:HelloHELLOHelloHELLO count_character('hello.txt', 'L') returns 4count_character('hello.txt', 'H') returns 4count_character('hello.txt', 'e') returns 2 Requirements: Please use Python Programming only Show screenshot of your work.arrow_forwardpythonarrow_forward
- The program will prompt the user to enter the file names for a source input file and an output file along with two strings, one to be found in the source file and a string that will replace each occurrence of that string in the file. source file: this is the text file that your program will read and search for the target string to be replaced output file: this is the file that will contain the source file after all of the occurrences of the target string have been found and replaced by the replacement string target string: this is the string your program will search for in the source file to locate all occurrences of the string replacement string: this is the string that will replace each occurrence of the target string in the source file I cant use the replace method, count method, split method, range() function, or lists in my solution is there any other method to use to get this.arrow_forwardWrite a small program that copies everything in a tet file to another file. The text file is calledin.txt and the output file is called out.txt. Two files should be exactly the same after copying(the first file shouldn’t be changed, and the second file should be the same as the first one).Your program should define a function called copyFile to copy the input file to the output filewith two arguments: a file pointer to the input file and a file pointer to the output file. You shouldnot and do not need to use an array during copying.arrow_forwardWriteaC++programthatpromptstheusertoenterafilenamethatcontains the total mark of students. Each line in the input file contains a student name followed by the student’s total mark. The program should ask the user for the passing threshold (i.e. student whose total mark is greater than or equal the threshold will pass the course) and copy the students who pass the course to a new file (the name of the output file is specified by the user). Moreover, the output file should be format so that all the marks are displayed with two digits after the decimal point. The width for the names and marks fields should be eight and seven, respectively. A sample input and output files are shown below (the passing mark in this sample is assumed to be 60). Total.txt Ahlam 80.123 Bader 83.1 Nabil 91.25 Khoula 70 Saif 55.333 Salem 50 Sultan 92.5 Qais 77.2arrow_forward
- This Python Lab 9 Lab: Write a file copying program. The program asks for the name of the file to copy from (source file) and the name of the file to copy to (destination file). The program opens the source file for reading and the destination file for writing. As the program reads each line from the source file and it writes the line to the destination file. When every line from the source file has been written to the destination file, it close both files and print “Copy is successful.” In the sample run, “add.py” is the source file and “add-copy.py” is the destination file. Note that both “add-copy.py” is identical to “add.py” because “add-copy.py” is a copy of “add.py”. Sample run: Enter file to copy from: add.py Enter file to copy to : add-copy.py Copy is successful. Source file: add.py print("This program adds two numbers") a = int(input("Enter first number: ")) b = int(input("Enter second number: ")) print(f"{a} + {b} = {a+b}") Destination file:…arrow_forwardPython - Text Processing Write a function copy(x, y) that can copy a file x into another file y. Use demo.txt as the input to verify your function. _Hint_: use functions open( ), read( ), write( ), and close( ).arrow_forwardProgram specifications: Write a function called rCopy that copies the entire contents of one file to another, but copies them over in reverse order. This function should take the names of the input and output files as strings. If either file does not open for any reason, the function should output an error message stating the name of the file that didn’t open and then return the value false. Otherwise, if both files open correctly, the function should return true once the reverse copy has been completed. For example, if a file named in.dat contains the following: A c d 87arc 65879 9 then after the function call: rCopy("in.dat", "out.dat") the file out.dat should contain the following: 9 97856 cra78 d c A You must solve this recursively!! To implement this recursively you will need to write a helper function that passes in an input and an output file stream. This helper function will be the recursive function. Recall that the expression cin.get(ch) will read in a single character from…arrow_forward
- It is necessary to define the functions that are part of the I stream.arrow_forwardDefine a function named get_words_from_file(filename) that takes a filename as a parameter. The function reads the contents of the file specified in the parameter and returns a list of words. The words in the file are separated by whitespace. Note: remember to close the file. Click here to download a sample text file. For example: Test Result print (get_words_from_file("input2.txt")) ['the', 'heavy', 'rain', 'is', 'to', 'ease', 'tonight', 'however', 'further', 'showers', 'are', 'expected', 'tomorrow']arrow_forwardpython programmingarrow_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