1. Please provide code based on Chapter 12 only from the text. Also include output to console picture after the program is compiled.
2. Text is Tony Gaddis 9th edition C++.
Chapter 12, page 714, Problem 5 'Line Numbers'
3. Please use 'forChapt12.txt' file for the problem. The text is pasted below after description of the problem.
5. LINE NUMBERS (page 714)
Write a program that asks the user for the name of the file. The program should display the contents of the file
on the screen. Each line of the screen output should be preceded with a line number, followed by a colon.
The line numbering should start at 1. Here is an example:
1:George Rolland
2:127 Academy Sreet
3:Brasstown, NC 28706
If the files contents wont fit on a single screen , the program should display 24 lines of output at the user
and then pause. Each time the program pauses, it should wait for user to strike a key before the next 24 lines are displayed.
Use the text below for the 'forChp12.txt'
No one is unaware of the name of that famous English shipowner,
Cunard.
In 1840 this shrewd industrialist founded a postal service between
Liverpool and Halifax, featuring three wooden ships with
400-horsepower paddle wheels and a burden of 1,162 metric
tons.
Eight years later, the company's assets were increased by four
650-horsepower ships at 1,820 metric tons, and in two more years,
by two other vessels of still greater power and tonnage.
In 1853 the Cunard Co., whose mail-carrying charter had just been
renewed, successively added to its assets the Arabia, the Persia,
the China, the Scotia, the Java, and the Russia, all ships of top
speed and, after the Great Eastern, the biggest ever to plow the
seas.
So in 1867 this company owned twelve ships, eight with paddle
wheels and four with propellers.
If I give these highly condensed details, it is so everyone can
fully understand the importance of this maritime transportation
company, known the world over for its shrewd management.
No transoceanic navigational undertaking has been conducted with
more ability, no business dealings have been crowned with greater
success.
In twenty-six years Cunard ships have made 2,000 Atlantic crossings
without so much as a voyage canceled, a delay recorded, a man, a
craft, or even a letter lost.
Accordingly, despite strong competition from France, passengers
still choose the Cunard line in preference to all others, as can be
seen in a recent survey of official documents.
Given this, no one will be astonished at the uproar provoked by
this accident involving one of its finest steamers.
Two men who work together in a factory were talking.
"I know how to get some time off," said one.
"How are you going to do that?" asked the other.
"Watch," he said, and climbed a ladder to the ceiling.
The foreman asked what he was doing up there,
and the man replied. "I'm a lightbulb."
"I think you need some time off," the foreman
said, and the first man walked out of the
factory. After a moment, the second man followed
him. "Where do you think you're going?"
the foreman shouted.
"I can't work in the dark," he said.
No one is unaware of the name of that famous English shipowner,
Cunard.
In 1840 this shrewd industrialist founded a postal service between
Liverpool and Halifax, featuring three wooden ships with
400-horsepower paddle wheels and a burden of 1,162 metric
tons.
Eight years later, the company's assets were increased by four
650-horsepower ships at 1,820 metric tons, and in two more years,
by two other vessels of still greater power and tonnage.
In 1853 the Cunard Co., whose mail-carrying charter had just been
renewed, successively added to its assets the Arabia, the Persia,
the China, the Scotia, the Java, and the Russia, all ships of top
speed and, after the Great Eastern, the biggest ever to plow the
seas.
So in 1867 this company owned twelve ships, eight with paddle
wheels and four with propellers.
If I give these highly condensed details, it is so everyone can
fully understand the importance of this maritime transportation
company, known the world over for its shrewd management.
No transoceanic navigational undertaking has been conducted with
more ability, no business dealings have been crowned with greater
success.
In twenty-six years Cunard ships have made 2,000 Atlantic crossings
without so much as a voyage canceled, a delay recorded, a man, a
craft, or even a letter lost.
Accordingly, despite strong competition from France, passengers
still choose the Cunard line in preference to all others, as can be
seen in a recent survey of official documents.
Given this, no one will be astonished at the uproar provoked by
this accident involving one of its finest steamers.
Two men who work together in a factory were talking.
"I know how to get some time off," said one.
"How are you going to do that?" asked the other.
"Watch," he said, and climbed a ladder to the ceiling.
The foreman asked what he was doing up there,
and the man replied. "I'm a lightbulb."
"I think you need some time off," the foreman
said, and the first man walked out of the
factory. After a moment, the second man followed
him. "Where do you think you're going?"
the foreman shouted.
"I can't work in the dark," he said.
No one is unaware of the name of that famous English shipowner,
Cunard.
In 1840 this shrewd industrialist founded a postal service between
Liverpool and Halifax, featuring three wooden ships with
400-horsepower paddle wheels and a burden of 1,162 metric
tons.
Eight years later, the company's assets were increased by four
650-horsepower ships at 1,820 metric tons, and in two more years,
by two other vessels of still greater power and tonnage.
In 1853 the Cunard Co., whose mail-carrying charter had just been
renewed, successively added to its assets the Arabia, the Persia,
the China, the Scotia, the Java, and the Russia, all ships of top
speed and, after the Great Eastern, the biggest ever to plow the
seas.
So in 1867 this company owned twelve ships, eight with paddle
wheels and four with propellers.
If I give these highly condensed details, it is so everyone can
fully understand the importance of this maritime transportation
company, known the world over for its shrewd management.
No transoceanic navigational undertaking has been conducted with
more ability, no business dealings have been crowned with greater
success.
In twenty-six years Cunard ships have made 2,000 Atlantic crossings
without so much as a voyage canceled, a delay recorded, a man, a
craft, or even a letter lost.
Accordingly, despite strong competition from France, passengers
still choose the Cunard line in preference to all others, as can be
seen in a recent survey of official documents.
Given this, no one will be astonished at the uproar provoked by
this accident involving one of its finest steamers.
Two men who work together in a factory were talking.
"I know how to get some time off," said one.
"How are you going to do that?" asked the other.
"Watch," he said, and climbed a ladder to the ceiling.
The foreman asked what he was doing up there,
and the man replied. "I'm a lightbulb."
"I think you need some time off," the foreman
said, and the first man walked out of the
factory. After a moment, the second man followed
him. "Where do you think you're going?"
the foreman shouted.
"I can't work in the dark," he said.
Thanks for your help!
Vaidas
Program code to copy
main.cpp
//header files
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <fstream>
using namespace std;
//main function
int main()
{
//declare variable as string
string name;
//asking user to enter file name
cout << "Enter file name: ";
//getting input from user
cin >> name;
//opening file
fstream file(name.c_str(), ios::in);
//checking the condition using if loop
if (file)
{
string line;
//The line numbering should start
at 1
int lineNum = 1;
while (!file.eof())
{
getline(file,
line);
//display line
number with content
cout <<
lineNum << ":" << line << endl;
//the program
should display 24 lines of output
if (lineNum % 24
== 0)
system("pause");
lineNum++;
}
}
//closing file
file.close();
return 0;
}
==============================================================================
forChap12.txt
No one is unaware of the name of that famous English shipowner,
Cunard.
In 1840 this shrewd industrialist founded a postal service between
Liverpool and Halifax, featuring three wooden ships with
400-horsepower paddle wheels and a burden of 1,162 metric
tons.
Eight years later, the company's assets were increased by four
650-horsepower ships at 1,820 metric tons, and in two more years,
by two other vessels of still greater power and tonnage.
In 1853 the Cunard Co., whose mail-carrying charter had just been
renewed, successively added to its assets the Arabia, the Persia,
the China, the Scotia, the Java, and the Russia, all ships of top
speed and, after the Great Eastern, the biggest ever to plow the
seas.
So in 1867 this company owned twelve ships, eight with paddle
wheels and four with propellers.
If I give these highly condensed details, it is so everyone can
fully understand the importance of this maritime transportation
company, known the world over for its shrewd management.
No transoceanic navigational undertaking has been conducted with
more ability, no business dealings have been crowned with greater
success.
In twenty-six years Cunard ships have made 2,000 Atlantic crossings
without so much as a voyage canceled, a delay recorded, a man, a
craft, or even a letter lost.
Accordingly, despite strong competition from France, passengers
still choose the Cunard line in preference to all others, as can be
seen in a recent survey of official documents.
Given this, no one will be astonished at the uproar provoked by
this accident involving one of its finest steamers.
Two men who work together in a factory were talking.
"I know how to get some time off," said one.
"How are you going to do that?" asked the other.
"Watch," he said, and climbed a ladder to the ceiling.
The foreman asked what he was doing up there,
and the man replied. "I'm a lightbulb."
"I think you need some time off," the foreman
said, and the first man walked out of the
factory. After a moment, the second man followed
him. "Where do you think you're going?"
the foreman shouted.
"I can't work in the dark," he said.
No one is unaware of the name of that famous English shipowner,
Cunard.
In 1840 this shrewd industrialist founded a postal service between
Liverpool and Halifax, featuring three wooden ships with
400-horsepower paddle wheels and a burden of 1,162 metric
tons.
Eight years later, the company's assets were increased by four
650-horsepower ships at 1,820 metric tons, and in two more years,
by two other vessels of still greater power and tonnage.
In 1853 the Cunard Co., whose mail-carrying charter had just been
renewed, successively added to its assets the Arabia, the Persia,
the China, the Scotia, the Java, and the Russia, all ships of top
speed and, after the Great Eastern, the biggest ever to plow the
seas.
So in 1867 this company owned twelve ships, eight with paddle
wheels and four with propellers.
If I give these highly condensed details, it is so everyone can
fully understand the importance of this maritime transportation
company, known the world over for its shrewd management.
No transoceanic navigational undertaking has been conducted with
more ability, no business dealings have been crowned with greater
success.
In twenty-six years Cunard ships have made 2,000 Atlantic crossings
without so much as a voyage canceled, a delay recorded, a man, a
craft, or even a letter lost.
Accordingly, despite strong competition from France, passengers
still choose the Cunard line in preference to all others, as can be
seen in a recent survey of official documents.
Given this, no one will be astonished at the uproar provoked by
this accident involving one of its finest steamers.
Two men who work together in a factory were talking.
"I know how to get some time off," said one.
"How are you going to do that?" asked the other.
"Watch," he said, and climbed a ladder to the ceiling.
The foreman asked what he was doing up there,
and the man replied. "I'm a lightbulb."
"I think you need some time off," the foreman
said, and the first man walked out of the
factory. After a moment, the second man followed
him. "Where do you think you're going?"
the foreman shouted.
"I can't work in the dark," he said.
No one is unaware of the name of that famous English shipowner,
Cunard.
In 1840 this shrewd industrialist founded a postal service between
Liverpool and Halifax, featuring three wooden ships with
400-horsepower paddle wheels and a burden of 1,162 metric
tons.
Eight years later, the company's assets were increased by four
650-horsepower ships at 1,820 metric tons, and in two more years,
by two other vessels of still greater power and tonnage.
In 1853 the Cunard Co., whose mail-carrying charter had just been
renewed, successively added to its assets the Arabia, the Persia,
the China, the Scotia, the Java, and the Russia, all ships of top
speed and, after the Great Eastern, the biggest ever to plow the
seas.
So in 1867 this company owned twelve ships, eight with paddle
wheels and four with propellers.
If I give these highly condensed details, it is so everyone can
fully understand the importance of this maritime transportation
company, known the world over for its shrewd management.
No transoceanic navigational undertaking has been conducted with
more ability, no business dealings have been crowned with greater
success.
In twenty-six years Cunard ships have made 2,000 Atlantic crossings
without so much as a voyage canceled, a delay recorded, a man, a
craft, or even a letter lost.
Accordingly, despite strong competition from France, passengers
still choose the Cunard line in preference to all others, as can be
seen in a recent survey of official documents.
Given this, no one will be astonished at the uproar provoked by
this accident involving one of its finest steamers.
Two men who work together in a factory were talking.
"I know how to get some time off," said one.
"How are you going to do that?" asked the other.
"Watch," he said, and climbed a ladder to the ceiling.
The foreman asked what he was doing up there,
and the man replied. "I'm a lightbulb."
"I think you need some time off," the foreman
said, and the first man walked out of the
factory. After a moment, the second man followed
him. "Where do you think you're going?"
the foreman shouted.
"I can't work in the dark," he said.
===================================================================================
Program Screenshot
main.cpp
=================================================================================
forChap12.txt
=================================================================================
Sample Output
1. Please provide code based on Chapter 12 only from the text. Also include output to...
1. Expense Pie Chart Create a text file that contains your expenses for last month in the following categories: -Rent -Gas -Food -Clothing -Car Payment -Misc Write a Python program that reads the data from the file and uses matplotlib to plot a pie chart showing you how you spend your money. 2. 1994 weekly gas graph The text file named 1994_Weekly_Gas_Averages.txt contains the average gas price for each week in the year 1994. (There are 52 lines in the...