Format Text
Lesson 7 of 18 in Coddy's Functions in C++: Building Your Own Functions course.
Challenge
EasyWrite a function to format a list of words into a grammatically correct sentence.
The format_sentence function takes a list of words and joins them into a sentence. The first word should be capitalized, and the sentence should end with a period. If the list is empty, the function should return an empty string.
For example, if the input list is <strong>["hello", “world”]</strong>, the result will be:
Hello world.If the input list is <strong>["this", "is", "a", "test"]</strong>, the result will be:
This is a test.
Try it yourself
#include <iostream>
#include <vector>
using namespace std;
string format() {
}All lessons in Functions in C++: Building Your Own Functions
1Introduction
Introduction2Beginner-level function
Repeat a StringReverse a StringMax ValueFill stringCenter TextFormat TextMath Operation