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.1, Problem 2STE
Explanation of Solution
Explanation:
//Include the needed headers
#include <iostream>
#include <fstream>
#include <cstdlib>
using namespace std;
//main() method
int main ()
{
//a handle for opening the input file
fin.open("stuff1.dat");
//check the condition
if (fin.fail( ))
{
//display the required data
cout << "Input file opening failed.\n";
//stop and exit
exit(1);
}
//a handle for opening the input file
fout...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Modify your program from Learning Journal Unit 7 to read dictionary items from a file and write the inverted dictionary to a file. You will need to decide on the following:
How to format each dictionary item as a text string in the input file.
How to covert each input string into a dictionary item.
How to format each item of your inverted dictionary as a text string in the output file.
Create an input file with your original three-or-more items and add at least three new items, for a total of at least six items.
Include the following in your Learning Journal submission:
The input file for your original dictionary (with at least six items).
The Python program to read from a file, invert the dictionary, and write to a different file.
The output file for your inverted dictionary.
A description of how you chose to encode the original dictionary and the inverted dictionary in text files.
Show more...
Modify your program from Learning Journal Unit 7 to read dictionary items from a…
Write a program that will sequentially list numbers from 0 to 50, changing its color depending on the size of the number, for example, for numbers from 0 to 10 it will be green, 11 to 22 red and 23 to 35 blue, etc. Limit the screen output speed to about 1 character / second.
In order to change colors, you must first use the GetStdHandle function to get a handle to the console, which is similar to getting a file pointer before working with a file. It is done e.g. as follows:
HANDLE hConsole; hConsole = GetStdHandle (STD_OUTPUT_HANDLE);
The above functions are defined in windows.h
Tip 2: Write a utility to find out the colors corresponding to all combinations from 0 to 255.
Tip 3: Instructions and sample program for working with time.
C language plz with explanation of codes. thanks
Write a program that reads two input files whose lines are ordered by a key data field. Your program should merge these two files, writing an output file that contains all lines from both files ordered by the same key field. As an example, if two input files contain student names and grades for a particular class ordered by name (the key field), merge the information as shown below.
File 1 and file 2 are supplied.
Here is an algorithm to merge the data from two files:
Read a line from each data file
While the end of both files has not been reached
While the end of both files has not been reached
Write the line from file 1 to the output file and read a new line from file 1.
Else
Write the line from file 2 to the output file and read a new line from file 2.
Write the remaining lines (if any) from file 1 to the output file.
Write the remaining lines (if any) from file 2 to the output file.
See the Merging Filesslides attachedto the project in Canvasfor a visual look at this algorithm.
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
- write a program that will open a file called “story.txt”and count the number of occurrences of each letter from the alphabet in this file.At the end your program will output the following report:Number of occurrences for the alphabets:a was used – times.b was used – times.c was used – times…. …and so, onAssume the file contains only lower-case letters and for simplicity just a singleparagraph. Your program should keep a counter associated with each letter of thealphabet (26 counters) [Hint: Use array]Your program should also print a histogram of characters count by addinga new function print Histogram (int counters []). This function receives thecounters from the previous task and instead of printing the number of times eachcharacter was used, prints a histogram of the counters. An example histogram forthree letters is shown below) [Hint: Use the extended asci character 254]:arrow_forwardWrite a program that will open the file dataFile.csv, read its contents and print them out. Your output should look like this: First Last Age Wagejane Smith 21.00 21.50Jack Jones 20.00 19.50Edgar Martinez 22.00 22.75Zanab Sayegh 21.00 21.75 Could I get help doing this code in python. I can't put the file here but I put a screenshot of it in the images below. If I'm missing more details let me know. Thanks.arrow_forwardConsider a scenario where a library is removing duplicate book names from an input file. Create a programme that reads all the titles from the bookTitles.txt input file and sends them to the noDuplicates.txt output file.When finished, the output file ought to include all distinct names located in the input file.arrow_forward
- Create a cpp file containing tests for a program that takes in two numbers and outputs the addition for them. Add three tests but only write code for passing one of them.arrow_forwardWrite a program that read a file(person.txt) from previous question Q1, and Showa all the records/lines from the file as a nicely formatted report with a header as shown: name..............age................city..........arrow_forwardYou are a cyber investigator, your task is to write a python program that can read file signatures from a file and save them into a list. Each file signature is an element of your list. Then, try to find out if there is a JPG file in there. If there is a JPG file, print out a True on screen. (File Signature for JPG file is: FF D8 FF DB) The input file is: FSCS360_Midterm_Exam_Part2.txtarrow_forward
- Develop an M-file to create a plot of volume versus depth, and test your program with cylinder(3,5,'Volume versus depth for horizontal cylindrical tank').arrow_forwardYour ReadRoomFile program reads a room file. Is it possible to tell how many rooms are in the file from the file size? Explain why or why not?arrow_forwardI have 200 .wav audio files each several minutes long. I want a python code to loop through the files and split each file into different 0.5 seconds .wav audio files and store the split files in a different folder. If a file is less than 0.5 seconds, then it should skip that file and continue with the loop for splitting.arrow_forward
- There are 45 students in a class, and the averages of these students are kept in a "sequential process file". You are asked to write a program like this:When the program is run for the first time, it checks whether the "notes.txt" file exists, if there is no file, it creates the file and writes it in the form of "ID POINT" for 45 students with IDs from 1 to 45 and with score values of 0. So the initial state of the file will be as follows.1 02 03 0...44 045 0If the file already exists, the existing file should be opened and the point values in the file should be used. The program will then receive the ID and SCORE from the user and change the grade given to the student with the relevant ID to the current average. If the ID is entered as 0, the program will terminate and the current average values will be written to the file.You can check if the file exists as follows.bool file_varmi(string filename){Ifstream f(name)Return f.good()}Note: It is sufficient for each student to write…arrow_forwardWrite a python program that first reads in the name of an input file and then reads the file using the csv.reader() method. The file contains a list of words separated by commas. Your program should output the words and their frequencies (the number of times each word appears in the file) without any duplicates. I have an error code and I am confused as to why. If I identify the file and use "with open" shouldn't it refer to the input file? Ex: If the input is: input1.csv and the contents of input1.csv are: hello,cat,man,hey,dog,boy,Hello,man,cat,woman,dog,Cat,hey,boy the output is: hello 1 cat 2 man 2 hey 2 dog 2 boy 2 Hello 1 woman 1 Cat 1arrow_forwardWrite a C# program that reads a text file and outputs the contains to the screen. The text file should be created outside of your code. Your program should do the following: Create a StreamReader that will read your text file for example // Open the input file for reading using (StreamReader reader = new StreamReader("input.txt")) Output each line from the text file Output one last line that says: "THE END OF FILE"arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education