1. You will be using Visual Studio to create the following programs. Make sure you see that these are separate programs. 2. Make sure that you follow the General Program Format Rules for each program 3. The closer the form of your output matches that shown in the example Special instructions Make sure the input files are in the same folder as your source code! If you don't, you'll be stuck with entering long pathnames to get to the files. For instance, if were working on PA1prog, I want to put my input file in the PA1prog folder. Here, the input file is named "pract2.txt". Local Disk (C)> VS Projects PA1prog Name Date modified Type Size 92n0203:22 PM File folder Debug PAlprog.cpp A PA1prog.sin S PA1prog.vexproj D PA1prog.voxproj.filters A PA1prog.voxproj.user 10/18/2020 1022 AM File folder 1 KB 2 KB 10/18/2020 10:21 AM CPP File 9/2/2020 3:22 PM Visual Studio Solu. 10/7/2020 7:34 PM vC++ Project 8KB The reason: if you use only a filename, the operating system will automatically look in the folder where your program exists. 10/7/2020 7:34 PM VC. Project Filte. Per-User Project O.. 1 KB 92/2020 3:22 PM 1 KB 1 KB pract2.bt D Source.cpp 10/18/2020 10:18 AM Text Document 10/7/2020 4:58 PM CPP File 4 KB When you save output to a file using only the filename, the file will be in the same folder as your program, also. Question: Ask the user for a filename that contains one string of at least 6 words (the words are separated by spaces). Use a for loop to read the first five words, and save them into a second file named "words.txt". So, if the first file contains this string: Homer Simpson should be president of the United States of America Then your second file will contain: Homer Simpson should be president Note: 1. I'm including a test file named "pract2.txt" 2. Make sure to test to see if the file actually opened. If not, print an error message and don't do anything else. If it did open, go ahead with the input, processing, and output. 3. An ifstream object behaves like cin. You might want to review section 3.8. In other words, whatever you would have done with cin, you can do similarly with your ifstream object. 4. You can declare only two strings in this program.
1. You will be using Visual Studio to create the following programs. Make sure you see that these are separate programs. 2. Make sure that you follow the General Program Format Rules for each program 3. The closer the form of your output matches that shown in the example Special instructions Make sure the input files are in the same folder as your source code! If you don't, you'll be stuck with entering long pathnames to get to the files. For instance, if were working on PA1prog, I want to put my input file in the PA1prog folder. Here, the input file is named "pract2.txt". Local Disk (C)> VS Projects PA1prog Name Date modified Type Size 92n0203:22 PM File folder Debug PAlprog.cpp A PA1prog.sin S PA1prog.vexproj D PA1prog.voxproj.filters A PA1prog.voxproj.user 10/18/2020 1022 AM File folder 1 KB 2 KB 10/18/2020 10:21 AM CPP File 9/2/2020 3:22 PM Visual Studio Solu. 10/7/2020 7:34 PM vC++ Project 8KB The reason: if you use only a filename, the operating system will automatically look in the folder where your program exists. 10/7/2020 7:34 PM VC. Project Filte. Per-User Project O.. 1 KB 92/2020 3:22 PM 1 KB 1 KB pract2.bt D Source.cpp 10/18/2020 10:18 AM Text Document 10/7/2020 4:58 PM CPP File 4 KB When you save output to a file using only the filename, the file will be in the same folder as your program, also. Question: Ask the user for a filename that contains one string of at least 6 words (the words are separated by spaces). Use a for loop to read the first five words, and save them into a second file named "words.txt". So, if the first file contains this string: Homer Simpson should be president of the United States of America Then your second file will contain: Homer Simpson should be president Note: 1. I'm including a test file named "pract2.txt" 2. Make sure to test to see if the file actually opened. If not, print an error message and don't do anything else. If it did open, go ahead with the input, processing, and output. 3. An ifstream object behaves like cin. You might want to review section 3.8. In other words, whatever you would have done with cin, you can do similarly with your ifstream object. 4. You can declare only two strings in this program.
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Hi, I need to solve this question using C++
Note: I have included Program - 5-23, General Program Format Rules, if you needed.
Program 5-23
// This program tests for file open errors.
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ifstream inputFile;
int number;
// Open the file.
inputFile.open("BadListOfNumbers.txt");
// If the file successfully opened, process it.
if (inputFile)
{
// Read the numbers from the file and
// display them.
while (inputFile >> number)
{
cout << number << endl;
}
// Close the file.
inputFile.close();
}
else
{
// Display an error message.
cout << "Error opening the file.\n";
}
return 0;
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
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
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