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: problem3functions.h and problem3functions.cpp
Example calls:
- NumDigits(1078) should return 4
- NumDigits(-10) should return 2
- 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 =12325;
FindAndReplace(x,2,7); the function should return true, and after
the function call x should hold 17375
- x =11811;
FindAndReplace(x,11,6); - the function should return true, and after the
function call x should hold 6806
- x =118111; FindAndReplace(x,11,23); - the function should return true,
and after the function call x should hold 238123
- x =10345;
FindAndReplace(x,3,10); - the function should return false because the
second argument has fewer digits (1) than the third argument (2), and
after the function call x should hold 10345
- x =18;
- FindAndReplace(x,-1,1); - the function should return false because the
second argument is negative, and after the function call x should hold 18
Specifications:
- Both function prototypes should be included in problem3.h
- Both functions should be implemented in problem3.cpp
A makefile and some minimal unit tests have been included in problem3tests.zip. You are
encouraged to create more rigorous tests. To run the test provided, create a directory containing
only your problem3functions.h file, your problem3functions.cpp file, and the files extracted from the attached problem3tests.zip. Then type
make testNumDigits
make testFindAndReplace
# makefile for problem 3
#
# $@ target
# $< first prerequisite
# $^ all prerequisites
flags =-std=c++17-Wall -I .
problem3functions.o : problem3functions.cpp problem3functions.h
g++ $(flags)-c $<
testNumDigits : testNumDigits.cpp problem3functions.o
g++ $(flags) $^-o $@
$@
testFindAndReplace : testFindAndReplace.cpp problem3functions.o
g++ $(flags) $^-o $@
$@

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!