Question

In: Computer Science

Function writing: 1). (1 point) Write the prototype of a value-returning function checkIfOdd. This function takes...

Function writing:

1). (1 point) Write the prototype of a value-returning function checkIfOdd. This function takes three integer parameters. It returns true if all three of the parameters are odd, and false otherwise.

2). (1 point) Write a sample call for this function. (Assume that you are calling from main)

3). (3 points) Write the definition (header and body) of the function.

Solutions

Expert Solution

Code for given function writing question is provided below.

C++ code is written and necessary comments are added in code.

Code:

Filename: funWriting.cpp

#include<iostream>
using namespace std;

// Function prototype

bool checkIfOdd(int, int, int);

int main()
{
bool flag;

// Sample call for function from main

// Case-1
flag = checkIfOdd(5, 9, 11);

if(flag==true)
   cout<<"\nAll parameters are Odd\n";
else
   cout<<"\nFunction returned False\n";

// Case-2
flag = checkIfOdd(10, 4, 11);

if(flag==true)
   cout<<"\nAll parameters are Odd\n";
else
   cout<<"\nFunction returned False\n";

return 0;
}

//Function Definition

bool checkIfOdd(int num1, int num2, int num3)
{
if((num1%2 == 1) && (num2%2 == 1) && (num3%2 == 1))
{
   return true;
}

// This part will execute if condition in 'If' is not satisfies...s
return false;
}

Compiled and executed on ubuntu terminal...

Output:

g++ funWriting.c

./a.out

All parameters are Odd

Function returned False

Output Explaination:

In first sample function call...

Parameters were 5, 9, 11.

As all are Odd numbers, function returnes value 'true' and therefore program prints the line 'All parameters are Odd'.

In second sample function call...

Parameters were 10, 4, 11.

As 10 & 4 are even numbers and 11 is an odd number, function returnes value 'false' and therefore program prints the line 'Function returned False'.


Related Solutions

In Python write a function with prototype “def dictsort(d):” which will return a list of key-value...
In Python write a function with prototype “def dictsort(d):” which will return a list of key-value pairs of the dictionary as tuples (key, value), reverse sorted by value (highest first) and where multiple keys with the same value appear alphabetically (lowest first).
Write a function that takes an Array of cases, as well as an FSA String value....
Write a function that takes an Array of cases, as well as an FSA String value. This Case data is an Array where each item in the Array is a custom Case Object. The Array is really [case1, case2, case3, ...], and each Case Object has the following structure:   {      "Age Group": "40 to 49 Years",      "Neighbourhood Name": "Annex",      "Outcome": "RESOLVED",      "Client Gender": "FEMALE",      "Classification": "CONFIRMED",      "FSA": "M5R",      "Currently Hospitalized": "No",      "Episode Date": "2020-09-12",      "Assigned_ID": 17712,      "Outbreak Associated": "Sporadic",      "Ever...
Write a function called draw_card. It takes no arguments and returns an integer representing the value...
Write a function called draw_card. It takes no arguments and returns an integer representing the value of a blackjack card drawn from a deck. Get a random integer in the range 1 to 13, inclusive. If the integer is a 1, print "Ace is drawn" and return 1. If the integer is between 2 and 10, call it x, print "<x> is drawn" and return x (print the number, not the string literal "<x>"). If the number is 11, 12,...
Write a function myfn6 which takes as inputs vector u and value a, and output as...
Write a function myfn6 which takes as inputs vector u and value a, and output as vector w with its elements being “True, ” or “False, ”(w = [True, False, False, …, True]). Such that “True, ” means a is in u and “False, ” means a is not in u. Test your code for u = [0, -3, 1, 1, 2, 2, 6, 2] and a = 9, a = 1 and a = 2. Copy your code together...
c++ Write the definition of a function named ‘isLower’ that takes as input a char value...
c++ Write the definition of a function named ‘isLower’ that takes as input a char value and returns true if the character is lowercase; otherwise, it returns false.•Print the message “The character xis lowercase” when returned value above is true, and vice versa.
2. working with databases and files in python a) Write a function with prototype “def profound():”...
2. working with databases and files in python a) Write a function with prototype “def profound():” that will prompt the user to type something profound. It will then record the date and time using the “datetime” module and then append the date, time and profound line to a file called “profound.txt”. Do only one line per function call. Use a single write and f-string such that the file contents look like: 2020-10-27 11:20:22 -- Has eighteen letters does 2020-10-27 11:20:36...
Write a Python function with prototype “def anagramdictionary(wordlist):” that will return an “anagram dictionary” of the...
Write a Python function with prototype “def anagramdictionary(wordlist):” that will return an “anagram dictionary” of the given wordlist  An anagram dictionary has each word with the letters sorted alphabetically creating a “key”.
Write a function num_day that takes a number in the range of 1 through 7 as...
Write a function num_day that takes a number in the range of 1 through 7 as a parameter and returns a string representing the corresponding day of the week, where 1=Monday, 2 =Tuesday, 3=Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday. The function should return the string "Error" if the parameter is that is outside the range of 1 through 7. You may assume that the parameter will be only numbers. Save the function...
JAVA PLEASE!! Write a value-returning method, isVowel, that returns the value true if a given character...
JAVA PLEASE!! Write a value-returning method, isVowel, that returns the value true if a given character is a vowel, and otherwise returns false. Also write a program to test your method. 2) Write a program that prompts the user to input a sequence of characters and outputs the number of vowels. (Use the method isVowel written in Programming Exercise 1.)
'PYTHON' 1. Write a function called compute_discount which takes a float as the cost and a...
'PYTHON' 1. Write a function called compute_discount which takes a float as the cost and a Boolean value to indicate membership. If the customer is a member, give him/her a 10% discount. If the customer is not a member, she/he will not receive a discount. Give all customers a 5% discount, since it is Cyber Tuesday. Return the discounted cost. Do not prompt the user for input or print within the compute_discount function. Call the function from within main() and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT