Get a copy of the is_even.cpp file by:
—————————
// // Program to test "is_even" function. // #include <iostream> using namespace std; void is_even(int); // Function Prototype int main( ) { int num; cout << "Enter an integer:n"; cin >> num; cout << "Is " << num << " even? "; is_even(num); cout << endl; return 0; } // "is_even" function. // Prints "yes" if a is even, "no" otherwise. void is_even(int a) { // insert code here to complete the function // use if else structure }
—————————-
Entering the cp command: cp /net/data/ftp/pub/class/110/ftp/cpp/is_even.cpp is_even.cpp
or, using your mouse to copy and paste the program into Pico, or
using the Hercules command-line ftp program to copy this file from the CS Department’s anonymous ftp site.
The path: pub/class/110/ftp/cpp The file: is_even.cpp
The purpose of this program is to practice using user defined functions.
Add code to the program to complete it.
Compile and run this C++ program.
The program output should look like the following:
hercules[66]% CC is_even.cpp -o is_even hercules[67]% is_even Enter an integer: 12 Is 12 even? yes hercules[69]% is_even Enter an integer: 23 Is 23 even? no hercules[70]% is_even Enter an integer: -17 Is -17 even? no hercules[71]% is_even Enter an integer: 466 Is 466 even? yes hercules[72]%
Expert Answer
//
// Program to test “is_even” function.
//
#include <iostream>
using namespace std;
void is_even(int); // Function Prototype
int main( )
{
int num;
cout << “Enter an integer:n”;
cin >> num;
cout << “Is ” << num << ” even? “;
is_even(num);
cout << endl;
return 0;
}
// “is_even” function.
// Prints “yes” if a is even, “no” otherwise.
void is_even(int a)
{
if(a%2==0)//we will calutate the modules of number by 2 if that is equal to zero then no. is even else no. is odd
{
cout<< “yes”;
}
else{
cout<< “no”;
}
}
output: