Write a function named addCommas that accepts a string representing a number and returns a ew string with a comma at every third position, starting from the right. For example: addCommas("12345678") -> "12,345,678" strings.cpp 1 // Implement your function here strings.h 1 // Declare your function here client.cpp 1 #include using namespace std; 4 #include "strings.h" int main() cout <« "What number to process: "; string n; cin >> n; 10 // note string input 11 12 13 cout « addCommas (n) <« endl; 14

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter7: User-defined Simple Data Types, Namespaces, And The String Type
Section: Chapter Questions
Problem 8PE: Write a program that reads in a line consisting of a students name, Social Security number, user ID,...
icon
Related questions
Question

Please help in C++

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"
strings.cpp
|1 // Implement your function here
strings.h
1 // Declare your function here
client.cpp
1
#include <iostream>
using namespace std;
#include "strings.h"
int main()
cout <« "What number to process: ";
string n;
cin >> n;
10
// note string input
11
12
13
cout <« addCommas (n) <« endl;
}
14
Transcribed Image Text: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" strings.cpp |1 // Implement your function here strings.h 1 // Declare your function here client.cpp 1 #include <iostream> using namespace std; #include "strings.h" int main() cout <« "What number to process: "; string n; cin >> n; 10 // note string input 11 12 13 cout <« addCommas (n) <« endl; } 14
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr