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

C++ (cpp) PLEASE Write a complete function (prototype and definition) that takes an integer array and...
C++ (cpp) PLEASE Write a complete function (prototype and definition) that takes an integer array and the array dimensions as an input. The function should then square each value of the array in-place. At the completion of the function return a Boolean which indicates the process has completed.
Write a value returning function called isPrime. This function accepts integer number as parameter and checks...
Write a value returning function called isPrime. This function accepts integer number as parameter and checks whether it is prime or not. If the number is prime the function returns true. Otherwise, function returns false. A prime number is the number that can be divided by itself and 1 without any reminder, i.e. divisible by itself and 1 only. DO THIS USING C++ LANGUAGE .WITH UPTO CHAPTERS 5 (LOOP).
Write a value returning function named CountLower that counts the number of lower case letters on...
Write a value returning function named CountLower that counts the number of lower case letters on one line of standard input and returns that number. Document the dataflow of the function and show how it would be called from main().
C++ The minimum function. (a) Write a function that takes two integers and returns the value...
C++ The minimum function. (a) Write a function that takes two integers and returns the value of the smaller one. In the main() function provide 5 test cases to verify its correctness. (b) Write the function that takes two characters and return the smaller one in the lexicographical order. Write the main() function that tests that functions for 5 different pairs of character type variables. (c) Write a generic function that takes two numeric objects and returns the value of...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT