In: Computer Science
use c++
(5) 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. (3 pts)
Ex:
Number of Novels Authored Author name | Number of novels -------------------------------------------- Jane Austen | 6 Charles Dickens | 20 Ernest Hemingway | 9 Jack Kerouac | 22 F. Scott Fitzgerald | 8 Mary Shelley | 7 Charlotte Bronte | 5 Mark Twain | 11 Agatha Christie | 73 Ian Flemming | 14 J.K. Rowling | 14 Stephen King | 54 Oscar Wilde | 1
CODE:
#include<iostream>
#include<iomanip>
using namespace std;
//main method
int main(){
//array of authors
string author[] = {"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"};
//array of novels
int novels[] = {6,20,9,22,8,7,5,11,73,14,14,54,1};
//printing the title width 33 right justified
cout<<setw(33)<<right<<"Number of Novels
Authored"<<endl;
//Columns: Column 1 width: 20, left justified you can change it as
per your requirement
//Column 2 width: 23, right justified, divider line width 5 right
justified
cout<<setw(20)<<left<<"Author
Name"<<setw(5)<<right<<"|"<<setw(23)<<"Number
of novels"<<endl;
cout<<setw(20)<<left<<"------------------------"<<setw(23)<<"------------------------"<<endl;
for(int i=0;i<13;i++){
//printing the lines
cout<<setw(20)<<left<<author[i]<<setw(5)<<right<<"|"<<setw(23)<<novels[i]<<endl;
}
return 0;
}
_______________________________________
CODE IMAGES:
________________________________________
OUTPUT:
___________________________________________
Feel free to ask any questions in the comments section
Thank You!