Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

void test() { int x; x = multiply(10, 5); assert(x == 50); multiply2(2, 3, x); assert(x == 6); bool result = isPalindrome(racecar); assert(result == true);

image text in transcribed

void test() { int x; x = multiply(10, 5); assert(x == 50); multiply2(2, 3, x); assert(x == 6); bool result = isPalindrome("racecar"); assert(result == true); assert(isPalindrome("ab") == false); assert(isPalindrome("aba") == true); assert(addMultiple() == 0); assert(addMultiple(2) == 2); assert(addMultiple(2, 5) == 7); assert(addMultiple(2, 3, 4) == 9); assert(addMultiple(2, 3, 4, 5) == 14); assert(addMultiple(2, 3, 4, 5, 6) == 20); assert(getBigger(10, 50) == 50); assert(getBigger(2.34, 1.56) == 2.34); // for strings, getBigger returns value // that appears first in dictionary assert(getBigger("car", "glove") == "car"); assert(getBigger("car", "bed") == "bed"); assert(makePalindrome("a") == "a"); assert(makePalindrome("ab") == "aba"); assert(makePalindrome("abc") == "abcba"); assert(makePalindrome("abcd") == "abcdcba"); assert(makePalindrome("abcde") == "abcdedcba"); // advanced case, you do not have to handle it // assert(makePalindrome("abcb") == "abcba"); } C++ Thank you!

Goal: Understanding references, default parameters, templates For this assignment you will write several functions in a multiply - takes two integer parameters and returns the product of the two values given. multiply2 takes three integer parameters. The first two parameters are passed by value and the third parameter is passed by reference. When multiply2 is finished, the third parameter contains the product of the first two parameters. addMultiple - takes zero to 5 integers and returns the sum of all the integers. You should have one function called addMultiple, not 6 different versions. getBigger takes two parameters of any type and returns the larger one. The parameters can be int or double. You have to use Templates to handle multiple data types, not write two versions of the same function. Changed 11/8, you do not handle strings. Test case below changed as well abte ef string Fer strings, the greater-thanis-definee-as the were that weule isPalindrome takes a string parameter and returns true if the given string is a palindrome. For a string, say called str, you can access its characters using str [0, str [1] str [2], and so on. The size of the string is given by str.size ), so the last character in the string is strIstr.size) 11 since the character index starts from zero. makePalindrome takes a string parameter and returns a palindrome made from the string. If the string is already a palindrome, a copy is returned. Otherwise, letters are added to a copy of the string to make it into a palindrome. To add a single character to a string,say called str, you would use str 'a' or if the character was stored in another string, you'd use str otherString[5]. You only have to handle the simple case for turning strings into palindromes. See examples below for clarification. A sample test function and its output is provided below to help you design and test your functions

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional SQL Server 2012 Internals And Troubleshooting

Authors: Christian Bolton, Justin Langford

1st Edition

1118177657, 9781118177655

More Books

Students also viewed these Databases questions

Question

How can perceptions affect customer relations?

Answered: 1 week ago