You are on page 1of 1

CPA: Programming

Essentials in C++ C++ INSTITUTE - PROGRAM YOUR FUTURE

Lab 4.5.1 Text manipulation: eliminate duplicates


Objectives
Familiarize the student with:

Basics of string and text manipulation

Scenario
When editing text it is more than common to revisit and edit some previously written sentences. When doing so, people tend to duplicate
words.

Write a program that will read in a line of text and remove all duplicate words in that line of text.

However, two identical words separated by punctuation should not be considered duplicate.

#include <string>
#include <iostream>

int main()
{
std::string sentence;
std::getline(std::cin, sentence);

// manipulate the sentence here

std::cout << sentence << "\n";


}}

Example input
This sentence has no duplicate words

Example output
This sentence has no duplicate words

Example input
This sentence has has only unique words

Example output
This sentence has only unique words

Example input
You should, should you be interested, look for for more information online

Example output
You should, should you be interested, look for more information online

© 2016 C++ Institute. All rights reserved. Last updated: July 15, 2016 | www.cppinstitute.org Page 1 of 1

You might also like