1. Here are five functions, with descriptions of what they are supposed to do. T
ID: 3750798 • Letter: 1
Question
1. Here are five functions, with descriptions of what they are supposed to do. They are incorrectly implemented. Replace the incorrect implementations of these functions with correct ones that use recursion in a useful way; your solution must not use the keywords while, for, or goto. You must not use global variables or variables declared with the keyword static, and you must not modify the function parameter lists. You must not create any auxiliary or helper functions. 7/ Returns the product of two positive integers, m and n, // using only repeated addition int mult (unsigned int m, unsigned int n) return This is incorrectExplanation / Answer
#include <iostream>
#include <string>
using namespace std;
string find_paren(const string &s)
{
const string start_paren = "(";
const string stop_paren = ")";
//Returns the position of the "(" in the input string
unsigned first_paren_pos = s.find(start_paren);
unsigned end_pos_of_first_paren = first_paren_pos + start_paren.length();
//Returns the position of ")" in the input string
unsigned last_paren_pos = s.find(stop_paren);
// Finally using substr method to get the substring inside the parentheses
return ( "(" + s.substr(end_pos_of_first_paren,
last_paren_pos - end_pos_of_first_paren) + ")" );
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.