Question: Write a function named addCommas that accepts a string representing a number and returns a new string with a comma at every third position, starting

Write a function named addCommas that accepts a string representing a number and returns a new string with a comma at every third position, starting from the right. For example: addCommas ("12345678") -> "12,345,678" Complete the following files: strings.cpp 1 #include"strings.h" 2 string addCommas(string s) 3 { 4 int n = s.length() - 3; 5 while (n > 0) 6 { 7 s.insert(n, ","); 8 = 3; 9 } 10 return s; 11 ] 12 n strings.h 1 #ifndef STRINGS_H 2 #define STRINGS_H 3 #include
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
