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;
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:
Read the first line of the file and redisplay it to the output window.
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 into this function as your starting point.
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.
Repeat step for every line of the input file.
Ex:
Charlotte Bronte Mark Twain Agatha Christie Ian Fleming JK Rowling
Now formally format the table. There will be a leftjustified title line. The column widths are defined by the global constants. The name column is leftjustified and the number of books column is rightjustified. The two columns are separated by a single vertical line character.
Ex:
Number of Novels Authored Author Name Number Of Titles Jane Austen
Charles Dickens
Ernest Hemingway
Jack Kerouac
The last feature is to determine the integer average number of books per author in the file. Display the fully formatted table from step along with two more lines at the bottom:
Ex:
Average titles
predefined classes, functions, structures
#include cin, cout
missing several
using namespace std;
global formatting constants
const unsigned int AUTHORCOLUMNWIDTH ;
const unsigned int TITLECOUNTCOLUMNWIDTH ;
function prototypes
void showMenu;
void displayFirstFileLineconst string filename;
void displayFirstAuthorNameconst string filename;
void displayFirstAuthorInformationconst string filename;
void displayAllAuthorInformationconst string filename;
void displayFormattedTableNoAverageconst string filename;
void displayEntireFormattedTableconst string filename;
main definition
main definition
int main
loop through menu
unsigned int userchoice;
const string FILENAME "authortitlesdata.txt;
get first user choice
showMenu;
cout "Enter your choice to : ;
cin userchoice;
while userchoice
cout endl;
switch userchoice
case :
displayFirstFileLineFILENAME;
break;
case :
displayFirstAuthorNameFILENAME;
break;
case :
displayFirstAuthorInformationFILENAME;
break;
case :
displayAllAuthorInformationFILENAME;
break;
case :
displayFormattedTableNoAverageFILENAME;
break;
case :
displayEntireFormattedTableFILENAME;
break;
default:
nothing
break;
cout endl;
get next user choice
showMenu;
cout "Enter your choice to : ;
cin userchoice;
cout endl;
return ;
function definitions
void showMenu
cout "Choose an option:" endl
display the first file line unformatted to screen" endl
display the first author name to screen" endl
display the first author name, spaces, title count to screen" endl
display all authors name, spaces, title count to screen" endl
display formatted table of authors no average" endl
option plus the formatted average titles per author" endl
quit" endl
endl;
return;
void displayFirstAuthorNameconst string filename
return;
void displayFirstFileLineconst string filename
return;
void displayFirstAuthorInformationconst string filename
return;
void displayAllAuthorInformationconst string filename
return;
void displayFormattedTableNoAverageconst string filename
return;
void displayEntireFormattedTableconst string filename
return;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
