Write a recursive, bool-valued function, containsVowel, that accepts a string and returns true if the string contains a vowel. A string contains a vowel if: The first character of the string is a vowel, or The rest of the string (beyond the first character) contains a vowel

C++

LANGUAGE: C++ CHALLENGE: Write a recursive, bool-valued function, containsVowel, that accepts a string and returns true if the string contains a vowel. A string contains a vowel if: The first character of the string is a vowel, or The rest of the string (beyond the first character) contains a vowel

Read More

Write a recursive, int -valued function, len, that accepts a string and returns the number of characters in the string. The length of a string is: 0 if the string is the empty string (“”””). 1 more than the length of the rest of the string beyond the first character.

C++

LANGUAGE: C++ CHALLENGE: Write a recursive, int -valued function, len, that accepts a string and returns the number of characters in the string. The length of a string is: 0 if the string is the empty string (“”). 1 more than the length of the rest of the string beyond the first character.

Read More

Two non-negative integers x and y are equal if either: – Both are 0, or – x-1 and y-1 are equal Write a bool-function named equals that recursively determines whether its two int parameters are equal and returns true if they are and false otherwise.

C++

LANGUAGE: C++ CHALLENGE: Two non-negative integers x and y are equal if either: – Both are 0, or – x-1 and y-1 are equal Write a bool-function named equals that recursively determines whether its two int parameters are equal and returns true if they are and false otherwise.

Read More

Write the definition of a function called product. The function receives two int parameters. You may assume that neither parameter is negative. The function returns the product of the parameters. So, product (3,5) returns 15 and product (30,4) returns 120. The function must not use a loop of any kind (for, while, do-while) to accomplish its job.

C++

LANGUAGE: C++ CHALLENGE: Write the definition of a function called product. The function receives two int parameters. You may assume that neither parameter is negative. The function returns the product of the parameters. So, product (3,5) returns 15 and product (30,4) returns 120. The function must not use a loop of any kind (for, while,…

Read More

Assume the availability of a function called fact. The function receives an int argument and returns an int value. If the argument is one or smaller, it returns the integer value one. Otherwise it returns the product of all the integers from one to its argument. So the value of fact(4) is 1*2*3*4 and the value of fact(10) is 1*2*3*4*5*6*7*8*9*10. Assume further that the variable k has been declared and initialized to a positive integer. Assume further that the variable x has been declared as an integer type. Write a statement that assigns x the value k*(k-1)*(k-2)*…*3*2*1 by calling the fact function and multiplying its return value by k. Note: your solution must include multiplying fact’s return value by k here.

C++

LANGUAGE: C++ CHALLENGE: Assume the availability of a function called fact. The function receives an int argument and returns an int value. If the argument is one or smaller, it returns the integer value one. Otherwise it returns the product of all the integers from one to its argument. So the value of fact(4) is…

Read More

Assume the availability of a function called printStars. The function receives an int argument. If the argument is positive, the function prints (to standard output) the given number of asterisks. Thus, if the printStars(8) is called, ******** (8 asterisks) will be printed. Assume further that the variable starCount has been declared and initialized to a positive integer. Write some code that prints starCount asterisks to standard output by: first printing a single asterisk (and no other characters) then calls printStars to print the remaining asterisks.

C++

LANGUAGE: C++ CHALLENGE: Assume the availability of a function called printStars. The function receives an int argument. If the argument is positive, the function prints (to standard output) the given number of asterisks. Thus, if the printStars(8) is called, ******** (8 asterisks) will be printed. Assume further that the variable starCount has been declared and…

Read More

Assume the availability of a function named printStars that can be passed a non-negative integer n and print a line of asterisks. Write a function named printTriangle that receives a non-negative integer n and prints a triangle of asterisks as follows: first a line of 1 asterisk, followed by a line of 2 asterisks, and then a line of 3 asterisks, and so on and finally a line of n asterisks. For example, if the function received 5 it would print: * * * * * * * * * * * * * * * The function must not use a loop of any kind (for, while, do-while) to accomplish its job. The function should invoke printStars to accomplish the task of printing a single line.

C++

LANGUAGE: C++ CHALLENGE: Assume the availability of a function named printStars that can be passed a non-negative integer n and print a line of asterisks. Write a function named printTriangle that receives a non-negative integer n and prints a triangle of asterisks as follows: first a line of 1 asterisk, followed by a line of…

Read More

Write a statement that reads 5 successive integers into these variables that have already been declared: x1 x2 x3 x4 x5. Then write a statement that prints each out on its own line so that they form a right-justified column with a 5-digit width. If any of the integers are 5-digits in size, then they will start at the very beginning of their lines. For example: |54213 | 8713 | 23 | 147 | 15 NOTE: The vertical bar,|, on the left above represents the left edge of the print area; it is not to be printed out. Also, we show x in the output above to represent spaces–your output should not actually have x’s!

C++

LANGUAGE: C++ CHALLENGE: Write a statement that reads 5 successive integers into these variables that have already been declared: x1 x2 x3 x4 x5. Then write a statement that prints each out on its own line so that they form a right-justified column with a 5-digit width. If any of the integers are 5-digits in…

Read More

Given three variables, a, b, c, of type double that have already been declared and initialized, write some code that prints each of them in scientific (also known as e-notation or exponential notation) in a 10 position field on the same line. Each number should be printed with 3 digits to the right of the decimal point. For example, if their values were 987654321, 1234, 0.00987654321, the output would be: |x9.877e+08×1.234e+03×9.877e-03 NOTE: The vertical bar, |, on the left above represents the left edge of the print area; it is not to be printed out. Also, we show x in the output above to represent spaces–your output should not actually have x’s!

C++

LANGUAGE: C++ CHALLENGE: Given three variables, a, b, c, of type double that have already been declared and initialized, write some code that prints each of them in scientific (also known as e-notation or exponential notation) in a 10 position field on the same line. Each number should be printed with 3 digits to the…

Read More

Given three variables , a, b, c, of type double that have already been declared and initialized, write some code that prints each of them in a 15 position field on the same line, in such away that scientific (or e-notation or exponential notation) is avoided. Each number should be printed with 5 digits to the right of the decimal point. For example, if their values were 24.014268319, 14309, 0.00937608, the output would be:|xxxxxxx24.01427xxxx14309.00000xxxxxxxx0.00938 NOTE: The vertical bar, | , on the left above represents the left edge of the print area; it is not to be printed out. Also, we show x in the output above to represent spaces– your output should not actually have x’s!

C++

LANGUAGE: C++ CHALLENGE: Given three variables , a, b, c, of type double that have already been declared and initialized, write some code that prints each of them in a 15 position field on the same line, in such away that scientific (or e-notation or exponential notation) is avoided. Each number should be printed with…

Read More

Given three variables, a, b, c, of type double that have already been declared and initialized, write a statement that prints each of them on the same line, separated by one space, in such away that scientific (or e-notation or exponential notation) is avoided. Each number should be printed with 5 digits to the right of the decimal point. For example, if their values were 4.014268319, 14309, 0.00937608, the output would be:|4.01427×14309.00000×0.00938 NOTE: The vertical bar, |, on the left above represents the left edge of the print area; it is not to be printed out. Also, we show x in the output above to represent spaces– your output should not actually have x’s!

C++

LANGUAGE: C++ CHALLENGE: Given three variables, a, b, c, of type double that have already been declared and initialized, write a statement that prints each of them on the same line, separated by one space, in such away that scientific (or e-notation or exponential notation) is avoided. Each number should be printed with 5 digits…

Read More