IN C++ /* Writing to, reading from data files using functions. Project: Novels Name: */ #include #include
Posted: Mon Jun 06, 2022 5:28 pm
IN C++
/*
Writing to, reading from data files using functions.
Project: Novels
Name:
*/
#include <iostream>
#include <string>
#include <iomanip>
//FIXME: stream manipulation library
using namespace std;
// Function Declarations
void createAuthorDataFile(string fileName);
//FIXME: declare the get header function
//FIXME: declare the make table function
//FIXME: declare the make histogram function
int main()
{
// Variables
// FIXME: What variables are needed in main()? Define
them below
getHeader(dataTitle, columnHeader1,
columnHeader2);
createAuthorDataFile("novels.txt");
//FIXME: call the make table function
//FIXME: call the make histogram function
return 0;
}
//open outFS and put the user data into the file
void createAuthorDataFile(string fileName)
{
int numNovels;
string authorName;
ofstream outFS;
outFS.open(fileName);
cout << "Enter a data point (-1 done to stop
input):" << endl;
cin >> numNovels;
cin.ignore();
getline(cin, authorName);
while (numNovels != -1 && authorName !=
"done") { // to stop enter -1 done
// display data to screen
cout << "Data string: " <<
authorName << endl;
cout << "Data integer: " <<
numNovels << endl;
// write data to file
outFS << numNovels << "
";
outFS << authorName <<
endl;
// get data for the next author
cin >> numNovels;
cin.ignore();
getline(cin, authorName);
}
outFS.close();
cout << endl;
}
// get title for data and columns headers
//FIXME: define the get header function
//open outFS and put the user data into the file
//FIXME: declare the make table function
//make table and output data onto table
//FIXME: declare the make histogram function
(1). Write a function named getHeader to do the following: Prompt the user for a title for data. Output the title. Ex: Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored Prompt the user for the headers of two columns of a table. Output the column headers. Ex: Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels. You entered: Number of novels • The getHeader function is called as shown below: getHeader (dataTitle, column Headerl, columnHeader2); (2). Read and understand the create AuthorDataFile function. This function does the following: Opens an output file named "novels.txt". . Prompts the user for data points. Data points must be in this format: int string. The user will enter -1 done when they have finished entering data points. Outputs the data points. Writes the data points to an output file. Closes the output file. Assume the user enters valid input. Note: this part of the program has already been written and tested. Review the code and reuse it. Ex: Enter a data point (-1 done to stop input): 6 Jane Austen Data string: Jane Austen Data integer: 6 • The createAuthorDataFile function is called as shown below: createAuthorDataFile ("novels.txt");
• The createAuthorDataFile function is called as shown below: createAuthorDataFile ("novels.txt"); (3). Write a function named make Table to do the following: • Open an input file named "novels.txt". We are using the file created by the createAuthorDataFile function. • This time we are reading data from the file and output the information in a formatted table. The title is right justified with a setw() value of 33. Column 1 has a setw() value of 20. Column 2 has a setw() value of 23. Close the input file. Ex: Number of Novels Authored Author name Number of novels Jane Austen Charles Dickens. Ernest Hemingway Jack Kerouac F. Scott Fitzgerald Mary Shelley Charlotte Bronte Mark Twain Agatha Christie Ian Flemming J.K. Rowling Stephen King Oscar Wilde • The makeTable function is called as shown below: makeTable ("novels.txt", dataTitle, columnHeader1, columnHeader2); (4). Write a function named makeHistogram to do the following: Open the input file named "novels.txt" again. Read data from the file and output the information as a formatted histogram (display a line of asterisks to match the number of novels written by each author). Each name is right justified with a setw() value of 20. Close the input file. Jane Austen ****** Charles Dickens ****** Ernest Hemingway Jack Kerouac ***** F. Scott Fitzgerald **** Mary Shelley ****** Charlotte Bronte ***** Ex: ***** 600 20 9 22 8 J00 7 5 11 73 14 14 54 Hibisin WP 1
• The makeTable function is called as shown below: makeTable ("novels.txt", dataTitle, columnHeaderl, columnHeader2); (4). Write a function named makeHistogram to do the following: • Open the input file named "novels.txt" again. • Read data from the file and output the information as a formatted histogram (display a line of asterisks to match the number of novels written by each author). Each name is right justified with a setw() value of 20. . Close the input file. Jane Austen ***** Charles Dickens ***** Ernest Hemingway ***** Jack Kerouac ***** F. Scott Fitzgerald ***** Mary Shelley Charlotte Bronte ***** Mark Twain ***** Agatha Christie ***** Ian Flemming ***** * J.K. Rowling ***** Stephen King Oscar Wilde * The makeHistogram function is called as shown below: makeHistogram ("novels.txt"); Ex:
Posted: Mon Jun 06, 2022 5:28 pm
IN C++
/*
Writing to, reading from data files using functions.
Project: Novels
Name:
*/
#include <iostream>
#include <string>
#include <iomanip>
//FIXME: stream manipulation library
using namespace std;
// Function Declarations
void createAuthorDataFile(string fileName);
//FIXME: declare the get header function
//FIXME: declare the make table function
//FIXME: declare the make histogram function
int main()
{
// Variables
// FIXME: What variables are needed in main()? Define
them below
getHeader(dataTitle, columnHeader1,
columnHeader2);
createAuthorDataFile("novels.txt");
//FIXME: call the make table function
//FIXME: call the make histogram function
return 0;
}
//open outFS and put the user data into the file
void createAuthorDataFile(string fileName)
{
int numNovels;
string authorName;
ofstream outFS;
outFS.open(fileName);
cout << "Enter a data point (-1 done to stop
input):" << endl;
cin >> numNovels;
cin.ignore();
getline(cin, authorName);
while (numNovels != -1 && authorName !=
"done") { // to stop enter -1 done
// display data to screen
cout << "Data string: " <<
authorName << endl;
cout << "Data integer: " <<
numNovels << endl;
// write data to file
outFS << numNovels << "
";
outFS << authorName <<
endl;
// get data for the next author
cin >> numNovels;
cin.ignore();
getline(cin, authorName);
}
outFS.close();
cout << endl;
}
// get title for data and columns headers
//FIXME: define the get header function
//open outFS and put the user data into the file
//FIXME: declare the make table function
//make table and output data onto table
//FIXME: declare the make histogram function
(1). Write a function named getHeader to do the following: Prompt the user for a title for data. Output the title. Ex: Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored Prompt the user for the headers of two columns of a table. Output the column headers. Ex: Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels. You entered: Number of novels • The getHeader function is called as shown below: getHeader (dataTitle, column Headerl, columnHeader2); (2). Read and understand the create AuthorDataFile function. This function does the following: Opens an output file named "novels.txt". . Prompts the user for data points. Data points must be in this format: int string. The user will enter -1 done when they have finished entering data points. Outputs the data points. Writes the data points to an output file. Closes the output file. Assume the user enters valid input. Note: this part of the program has already been written and tested. Review the code and reuse it. Ex: Enter a data point (-1 done to stop input): 6 Jane Austen Data string: Jane Austen Data integer: 6 • The createAuthorDataFile function is called as shown below: createAuthorDataFile ("novels.txt");
• The createAuthorDataFile function is called as shown below: createAuthorDataFile ("novels.txt"); (3). Write a function named make Table to do the following: • Open an input file named "novels.txt". We are using the file created by the createAuthorDataFile function. • This time we are reading data from the file and output the information in a formatted table. The title is right justified with a setw() value of 33. Column 1 has a setw() value of 20. Column 2 has a setw() value of 23. Close the input file. Ex: Number of Novels Authored Author name Number of novels Jane Austen Charles Dickens. Ernest Hemingway Jack Kerouac F. Scott Fitzgerald Mary Shelley Charlotte Bronte Mark Twain Agatha Christie Ian Flemming J.K. Rowling Stephen King Oscar Wilde • The makeTable function is called as shown below: makeTable ("novels.txt", dataTitle, columnHeader1, columnHeader2); (4). Write a function named makeHistogram to do the following: Open the input file named "novels.txt" again. Read data from the file and output the information as a formatted histogram (display a line of asterisks to match the number of novels written by each author). Each name is right justified with a setw() value of 20. Close the input file. Jane Austen ****** Charles Dickens ****** Ernest Hemingway Jack Kerouac ***** F. Scott Fitzgerald **** Mary Shelley ****** Charlotte Bronte ***** Ex: ***** 600 20 9 22 8 J00 7 5 11 73 14 14 54 Hibisin WP 1
• The makeTable function is called as shown below: makeTable ("novels.txt", dataTitle, columnHeaderl, columnHeader2); (4). Write a function named makeHistogram to do the following: • Open the input file named "novels.txt" again. • Read data from the file and output the information as a formatted histogram (display a line of asterisks to match the number of novels written by each author). Each name is right justified with a setw() value of 20. . Close the input file. Jane Austen ***** Charles Dickens ***** Ernest Hemingway ***** Jack Kerouac ***** F. Scott Fitzgerald ***** Mary Shelley Charlotte Bronte ***** Mark Twain ***** Agatha Christie ***** Ian Flemming ***** * J.K. Rowling ***** Stephen King Oscar Wilde * The makeHistogram function is called as shown below: makeHistogram ("novels.txt"); Ex:
/*
Writing to, reading from data files using functions.
Project: Novels
Name:
*/
#include <iostream>
#include <string>
#include <iomanip>
//FIXME: stream manipulation library
using namespace std;
// Function Declarations
void createAuthorDataFile(string fileName);
//FIXME: declare the get header function
//FIXME: declare the make table function
//FIXME: declare the make histogram function
int main()
{
// Variables
// FIXME: What variables are needed in main()? Define
them below
getHeader(dataTitle, columnHeader1,
columnHeader2);
createAuthorDataFile("novels.txt");
//FIXME: call the make table function
//FIXME: call the make histogram function
return 0;
}
//open outFS and put the user data into the file
void createAuthorDataFile(string fileName)
{
int numNovels;
string authorName;
ofstream outFS;
outFS.open(fileName);
cout << "Enter a data point (-1 done to stop
input):" << endl;
cin >> numNovels;
cin.ignore();
getline(cin, authorName);
while (numNovels != -1 && authorName !=
"done") { // to stop enter -1 done
// display data to screen
cout << "Data string: " <<
authorName << endl;
cout << "Data integer: " <<
numNovels << endl;
// write data to file
outFS << numNovels << "
";
outFS << authorName <<
endl;
// get data for the next author
cin >> numNovels;
cin.ignore();
getline(cin, authorName);
}
outFS.close();
cout << endl;
}
// get title for data and columns headers
//FIXME: define the get header function
//open outFS and put the user data into the file
//FIXME: declare the make table function
//make table and output data onto table
//FIXME: declare the make histogram function
(1). Write a function named getHeader to do the following: Prompt the user for a title for data. Output the title. Ex: Enter a title for the data: Number of Novels Authored You entered: Number of Novels Authored Prompt the user for the headers of two columns of a table. Output the column headers. Ex: Enter the column 1 header: Author name You entered: Author name Enter the column 2 header: Number of novels. You entered: Number of novels • The getHeader function is called as shown below: getHeader (dataTitle, column Headerl, columnHeader2); (2). Read and understand the create AuthorDataFile function. This function does the following: Opens an output file named "novels.txt". . Prompts the user for data points. Data points must be in this format: int string. The user will enter -1 done when they have finished entering data points. Outputs the data points. Writes the data points to an output file. Closes the output file. Assume the user enters valid input. Note: this part of the program has already been written and tested. Review the code and reuse it. Ex: Enter a data point (-1 done to stop input): 6 Jane Austen Data string: Jane Austen Data integer: 6 • The createAuthorDataFile function is called as shown below: createAuthorDataFile ("novels.txt");
• The createAuthorDataFile function is called as shown below: createAuthorDataFile ("novels.txt"); (3). Write a function named make Table to do the following: • Open an input file named "novels.txt". We are using the file created by the createAuthorDataFile function. • This time we are reading data from the file and output the information in a formatted table. The title is right justified with a setw() value of 33. Column 1 has a setw() value of 20. Column 2 has a setw() value of 23. Close the input file. Ex: Number of Novels Authored Author name Number of novels Jane Austen Charles Dickens. Ernest Hemingway Jack Kerouac F. Scott Fitzgerald Mary Shelley Charlotte Bronte Mark Twain Agatha Christie Ian Flemming J.K. Rowling Stephen King Oscar Wilde • The makeTable function is called as shown below: makeTable ("novels.txt", dataTitle, columnHeader1, columnHeader2); (4). Write a function named makeHistogram to do the following: Open the input file named "novels.txt" again. Read data from the file and output the information as a formatted histogram (display a line of asterisks to match the number of novels written by each author). Each name is right justified with a setw() value of 20. Close the input file. Jane Austen ****** Charles Dickens ****** Ernest Hemingway Jack Kerouac ***** F. Scott Fitzgerald **** Mary Shelley ****** Charlotte Bronte ***** Ex: ***** 600 20 9 22 8 J00 7 5 11 73 14 14 54 Hibisin WP 1
• The makeTable function is called as shown below: makeTable ("novels.txt", dataTitle, columnHeaderl, columnHeader2); (4). Write a function named makeHistogram to do the following: • Open the input file named "novels.txt" again. • Read data from the file and output the information as a formatted histogram (display a line of asterisks to match the number of novels written by each author). Each name is right justified with a setw() value of 20. . Close the input file. Jane Austen ***** Charles Dickens ***** Ernest Hemingway ***** Jack Kerouac ***** F. Scott Fitzgerald ***** Mary Shelley Charlotte Bronte ***** Mark Twain ***** Agatha Christie ***** Ian Flemming ***** * J.K. Rowling ***** Stephen King Oscar Wilde * The makeHistogram function is called as shown below: makeHistogram ("novels.txt"); Ex: