Menu
Coddy logo textTech

Format Text

Lesson 7 of 18 in Coddy's Functions in C++: Building Your Own Functions course.

challenge icon

Challenge

Easy

Write 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