Answer: provided below
Explanation:
The code is provided below/
// the method to add all double value in the string
double AddAll(const char *str)
{
double total = 0;
vector<string> vec;
stringstream strStream(str);
while (strStream.good())
{
string substr;
getline(strStream, substr, ';');
vec.push_back(substr);
}
for (size_t i = 0; i < vec.size(); i++)
{
total = total + stod(vec[i]);
}
return total;
}
Program code with addition of the above for testing is provided thus
#include <iostream>
#include <sstream>
#include <vector>
using namespace std;
//addin all double value in syring
double AddAll(const char *str)
{
double total = 0;
vector<string> vec;
stringstream strStream(str);
while (strStream.good())
{
string substr;
getline(strStream, substr, ';');
vec.push_back(substr);
}
for (size_t i = 0; i < vec.size(); i++)
{
total = total + stod(vec[i]);
}
return total;
}
int main()
{
//method calling and display result
cout<<AddAll("1.245;2.9");
}
This gives output as:
4.145