Question
Develop a C++ program that prints the last line of each paragraph. Paragraphs are separated by one or more blank (i.e., empty) lines. The last
Develop a C++ program that prints the last line of each paragraph. Paragraphs are separated by one or more blank (i.e., empty) lines. The last paragraph may not have trailing empty lines. Next copy-paste the following starter code to your project to help you get going with this program. Now think about how to add suitable if-statement(s) to check and print the last line of each paragraph. Note: The std::string::empty() method will come in handy here.
#include
#include
int main() {
std::string line, prevLine;
// Read & process line-by-line until EOF
while (std::getline(std::cin, line)) {
// Print the line
std::cout << line << std::endl;
}
return 0;
}
Sample input:
para #1
welcome.
para #2: Introduction
This is a simple test line
to create a 2 line para
conclusion of inputs
This para is the last para.
It has 3 lines
3 lines including this one and 3 blank lines at end
Last paragraph with 1 line
Sample output:
welcome.
to create a 2 line para
3 lines including this one and 3 blank lines at end
Last paragraph with 1 line
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started