C++ Programming Examples

kilometers to miles in C++

kilometers to miles in C++ with simple conversion formula 1 Kilometers = 0.621 miles. For example: Input: 10 kilometers Output:  6.21 miles Program will use unit formula to convert distance unit kilometers to mile. Example, 10 kilometers = —– miles? Since, 1 km =   0.621 miles hence, 10 km = 10*0.621 = 6.21 miles. C++ […]

C++ map update example

C++ map update – Simple program example to update value in map. To update an existing value in the map, first we will find the value with the given key using map::find() function. If the key exists, then will update it with new value. C++ map update example This example program has a key value […]

C++ program to reverse sentence without reversing words

Program to reverse sentence without reversing words in C++ with simple algorithms using stack. This algorithm also handles spaces and special characters in the sentence or a given string. TEST CASES: Input: Hello World!!!Output: !!!World Hello Input:    Hello             World           !!!Output: !!!          World             Hello Algorithm: Push spaces and each words in a stack and then pop […]

Extract words from string C++ program

Extract words from string  C++ – This program example will extract every words including special characters from the string that contains spaces or multiple spaces etc. using C++ istringstream class. Assign input string to istringstream object and within a loop extract each word . for example, if the string is “hello world” then hello and […]

Scroll to top