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 31STE
Explanation of Solution
Program:
//Include the needed headers
#include <fstream>
#include <iostream>
using namespace std;
//main() Method
int main( )
{
//creating object for ofstream
ofstream fout;
//a handle for opening the input file
fout.open("morestuf.dat");
//Print the required data
cout << "Enter 2 lines of input:\n";
//call the function
sen...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
python
The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hours worked> <hourly wage>
Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period.
The report should be in tabular format with the appropriate header.
Each line should contain:
An employee’s name
The hours worked
The wages paid for that period.
An example of the program input and output is shown below:
Enter the file name: data.txt Name Hours Total Pay Lambert 34 357.00 Osborne 22 137.50 Giacometti 5 503.50
The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hours worked> <hourly wage>
Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period.
The report should be in tabular format with the appropriate header.
Each line should contain:
An employee’s name
The hours worked
The wages paid for that period.
An example of the program input and output is shown below:
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
- The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hours worked> <hourly wage> Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report should be in tabular format with the appropriate header. Each line should contain: An employee’s name The hours worked The wages paid for that period. I am stuck on the portion of the problem regarding the producing the output of test file 1: I entered the following code: # Get the file name from user name = input("Enter the file name: ") # open file in read mode readFile = open(name, "r") #Get the file contents through #readlines method fileConetent = readFile.readlines() #Display statement print("\nName\t\t\tHours\t\tTotalPay"); #Iterate the loop for eachLine in fileConetent: #split each line with empty space…arrow_forwardUnder what circumstances is a file stream object’s ios::hardfail bit set? What member function reports the state of this bit?arrow_forwardThe functions that belong to the I stream should be defined.arrow_forward
- The Payroll Department keeps a list of employee information for each pay period in a text file. The format of each line of the file is the following: <last name> <hourly wage> <hours worked> <tips> Using Python :Write a program that inputs a filename from the user and prints to the terminal a report of the wages paid to the employees for the given period. The report should be in tabular format with the appropriate header. Each line should contain an employee’s name, the hours worked, and the wages paid for that period. The wages paid are equal to the hourly wage * hours worked + tips.arrow_forwardQ2: Suppose that the file (employee.txt) shown in the figure was stored in the default path, the data stored in this file is employee's name (string), his age (integer), and his salary (double); this data is stored for unknown number of employee. Write a program that uses a function which receives a file stream object of the file (employee.txt) and then it ereates another file to store the names of the employees whose ages are over 30 years. Вy C++ employee be-Notepad Fin Edr Fomat View Help Ahmed Al1 hasan 33 37 40 1.5e+06 1.6e+e6 1.7e+86 noharmed 43 1.Be-86 kamal 55 1.9e+06 bassam 25 9000ee hussam 22 100% Windows (CRLF) UTF-Barrow_forwardThis 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_forward
- It is necessary to define the functions that are part of the I stream.arrow_forwardWrite a function named repeat_words that takes two string parameters: 1. in_file: the name of an input file that exists before repeat_words is called 2. out_file: the name of an output file that repeat_words creates Assume that the input file is in the current working directory and write the output file to that directory. For each line of the input file, the function repeat_words should write to the output file all of the words that appear more than once on that line. Each word should be lower cased and stripped of leading and trailing punctuation. Each repeated word on a line should be written to the corresponding line of the output file only once, regardless of the number of times the word is repeated. For example, if the following is the content of the file catInTheHat.txt: Too wet to go out and too cold to play ball. So we sat in the house. We did nothing at all. So all we could do was to Sit! Sit! Sit! Sit! The following function call: inF = 'catInTheHat.txt' outF =…arrow_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_forward
- Write a statement that defines a file stream object named places. The object will be used for both output and input.arrow_forwardGiven a text file containing the availability of food items, write a program that reads the information from the text file and outputs the available food items. The program first reads the name of the text file from the user. The program then reads the text file, stores the information into four separate lists, and outputs the available food items in the following format: name (category) - description Assume the text file contains the category, name, description, and availability of at least one food item, separated by a tab character ('\t'). Ex: If the input of the program is: food.txt and the contents of food.txt are: Classic ham sandwich Available sandwich Chicken salad sandwich Not available Classic cheeseburger Cheeseburger Not available Salads Water 16oz bottled water Available Caesar salad Chunks of romaine heart lettuce dressed with lemon juice Available Salads Asian salad Mixed greens with ginger dressing, sprinkled with sesame Not available Beverages Beverages Mexican food…arrow_forwardLet A and B two text files, containing some binary lines between of length 1...N. Where N is the line with the maximum number of characters, 1 the minimum number of characters in each line. Design a Python3 function to compare each line of the files, character by character, and if there is a match of the characters, create a variable representing the similarity between the lines of each file, and return that similarity variable measures the similarity between two files.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