Question: The program will get its data from the input file authortitlesdata.txt . This file can be accessed from your lab program. It can also be

The program will get its data from the input file authortitlesdata.txt. This file can be accessed from your lab program. It can also be downloaded so you can review its contents. The file contains many lines of information about book authors. Each line is formatted as an author's full name, semicolon, and the number of books the author has written
: John F. Kennedy; 12
Your program will read the file into a program, manipulate the data, and create a formatted table from the data and a calculation.
The template gives you a start of the program. There are several new concepts in this template.
The menu illustrates the progression that a programmer develops a complicated program like this. It lets you create this program in steps and test each step.
It is very occasionally a good idea to create global constants. The formatting constants will be used in multiple functions in this program so making them
The alternate way of creating programmer defined functions in C++ appear
Develop your program in steps:
(1) Read the first line of the file and redisplay it to the output window.
(2) Figure out how to get the full name from the first line of the file. Display the full name to the output window. You'll probably copy and past the code from step (1) into this function as your starting point.
(3) Figure out how to get the number of books from the first line of the file AS AN INTEGER. (HINT: will be useful.) Display the first author's information in the minimal format from the menu.
(4) Repeat step (3) for every line of the input file.
Ex:
Charlotte Bronte 5 Mark Twain 11 Agatha Christie 73 Ian Fleming 14 J.K. Rowling 14
(5) Now formally format the table. There will be a left-justified title line. The column widths are defined by the global constants. The name column is left-justified and the number of books column is right-justified. The two columns are separated by a single vertical line character.
Ex:
Number of Novels Authored Author Name | Number Of Titles -------------------------------------------- Jane Austen |6
Charles Dickens |20
Ernest Hemingway |9
Jack Kerouac |22
(6) The last feature is to determine the integer average number of books per author in the file. Display the fully formatted table from step (5) along with two more lines at the bottom:
Ex:
| Average titles |18
predefined classes, functions, structures
#include // cin, cout
// missing several
using namespace std;
global formatting constants
const unsigned int AUTHOR_COLUMN_WIDTH =25;
const unsigned int TITLE_COUNT_COLUMN_WIDTH =18;
function prototypes
void showMenu();
void displayFirstFileLine(const string file_name);
void displayFirstAuthorName(const string file_name);
void displayFirstAuthorInformation(const string file_name);
void displayAllAuthorInformation(const string file_name);
void displayFormattedTableNoAverage(const string file_name);
void displayEntireFormattedTable(const string file_name);
main() definition
main() definition
int main()
{
// loop through menu
unsigned int user_choice;
const string FILE_NAME = "author_titles_data.txt";
// get first user choice
showMenu();
cout << "Enter your choice [1 to 7]: ";
cin >> user_choice;
while (user_choice <7)
{
cout << endl;
switch (user_choice)
{
case 1:
displayFirstFileLine(FILE_NAME);
break;
case 2:
displayFirstAuthorName(FILE_NAME);
break;
case 3:
displayFirstAuthorInformation(FILE_NAME);
break;
case 4:
displayAllAuthorInformation(FILE_NAME);
break;
case 5:
displayFormattedTableNoAverage(FILE_NAME);
break;
case 6:
displayEntireFormattedTable(FILE_NAME);
break;
default:
// nothing
break;
}
cout << endl;
// get next user choice
showMenu();
cout << "Enter your choice [1 to 7]: ";
cin >> user_choice;
}
cout << endl;
return 0;
}
function definitions
void showMenu()
{
cout << "Choose an option:" << endl
<<"1) display the first file line unformatted to screen" << endl
<<"2) display the first author name to screen" << endl
<<"3) display the first author name, 3 spaces, title count to screen" << endl
<<"4) display all authors name, 3 spaces, title count to screen" << endl
<<"5) display formatted table of authors no average" << endl
<<"6) option 5 plus the formatted average titles per author" << endl
<<"7) quit" << endl
<< endl;
return;
}
void displayFirstAuthorName(const string file_name)
{
return;
}
void displayFirstFileLine(const string file_name)
{
return;
}
void displayFirstAuthorInformation(const string file_name)
{
return;
}
void displayAllAuthorInformation(const string file_name)
{
return;
}
void displayFormattedTableNoAverage(const string file_name)
{
return;
}
void displayEntireFormattedTable(const string file_name)
{
return;
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!