Question: In visual studio code: - Write a function named NumDigits that takes an integer parameter and returns the number of digits in the integer. Deliverable:
In visual studio code: Write a function named NumDigits that takes an integer parameter and returns the number of digits in the integer. Deliverable: problemfunctions.h and problemfunctions.cpp
Example calls:
NumDigits should return
NumDigits should return
Write a function named FindAndReplace that replaces digits within an integer variable.
The function will take an integer variable to search, a positive integer to find, and a
positive integer to replace as arguments. The function should find all occurrences of the
find integer within the integer variable and replace them with replace integer, moving
from right to left.
Preconditions: the second and third arguments should be positive integers, and
the second argument should contain at least as many digits as the third
argument. If the preconditions are not met, the function should return false and
leave the first argument unchanged.
Example calls:
x ;
FindAndReplacex; the function should return true, and after
the function call x should hold
x ;
FindAndReplacex; the function should return true, and after the
function call x should hold
x ; FindAndReplacex; the function should return true,
and after the function call x should hold
x ;
FindAndReplacex; the function should return false because the
second argument has fewer digits than the third argument and
after the function call x should hold
x ;
FindAndReplacex; the function should return false because the
second argument is negative, and after the function call x should hold
Specifications:
Both function prototypes should be included in problemh
Both functions should be implemented in problemcpp
A makefile and some minimal unit tests have been included in problemtests.zip. You are
encouraged to create more rigorous tests. To run the test provided, create a directory containing
only your problemfunctions.h file, your problemfunctions.cpp file, and the files extracted from the attached problemtests.zip. Then type
make testNumDigits
make testFindAndReplace
# makefile for problem
#
# $@ target
# $ first prerequisite
# $ all prerequisites
flags stdcWall I
problemfunctions.o : problemfunctions.cpp problemfunctions.h
g $flagsc $
testNumDigits : testNumDigits.cpp problemfunctions.o
g $flags $o $@
$@
testFindAndReplace : testFindAndReplace.cpp problemfunctions.o
g $flags $o $@
$@
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
