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.
python exercise: a. Write a function sumDigits that takes a positive integer value and returns the...
python exercise: a. Write a function sumDigits that takes a positive integer value and returns the total sum of the digits in the integers from 1 to that number inclusive. b. Write a program to input an integer n and call the above function in part a if n is positive, else give ‘Value must be Positive’ message. sample: Enter a positive integer: 1000000 The sum of the digits in the number from 1 to 1000000 is 27000001 Enter a...
0.2 point for writing the hypothesis in symbolic form. 0.2 point for determining the value of...
0.2 point for writing the hypothesis in symbolic form. 0.2 point for determining the value of the test statistic. 0.2 point for finding the critical value OR the p-value. 0.2 point for determining if you should reject the null hypothesis or fail to reject the null hypothesis. 0.2 point for writing a conclusion addressing the original claim. All work must be shown A study is done to test the claim that Company A retains its workers longer than Company B....
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”.
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.)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT