0% found this document useful (0 votes)
19 views

SD234 - Unit 5 Assignment A&b

1. The function check() has three parameters - an integer, and two doubles. It returns no value. 2. The function findAbs() takes an integer as a parameter and returns a double. It either returns the integer passed in, or takes a double as a parameter and returns it. 3. True statements: a function can return 1 value; parameters allow different values each call; false statements: a function needs only the name to use it; a function only returns integers.

Uploaded by

Tim Williams
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

SD234 - Unit 5 Assignment A&b

1. The function check() has three parameters - an integer, and two doubles. It returns no value. 2. The function findAbs() takes an integer as a parameter and returns a double. It either returns the integer passed in, or takes a double as a parameter and returns it. 3. True statements: a function can return 1 value; parameters allow different values each call; false statements: a function needs only the name to use it; a function only returns integers.

Uploaded by

Tim Williams
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Unit 5 Assignment A

#1: A function named check() that has three parameters. The first parameter should accept an integer number,
and the second and third parameters should accept variables of type double. The function returns no value.
=START CODE=
check(int i, double z, double x) {
return 0;
}
=END CODE=

#2: A function named findAbs() that accepts a integer passed to it and returns a double.
=START CODE=
double findAbs( int i ) {
double z = i;
return z;
}
=END CODE=
OR
=START CODE=
double findAbs( double i ) {
return i;
}
=END CODE=

#3: Mark the following as True or False


False
a. To use a predefined function in a program, you need to know only the
name of the function and how to use it.
True
b. A value-returning function returns only 1 value.
True
c. Parameters allow you to use different values each time the function is
called.
False
d. A value-returning function returns only integer values.

Unit 5 Assignment B
Programming Exercise #1 (Chapter 6):
Write a program that uses the function isNumPalindrome given in Chapter 6 - Example 6-5. Test your program
on the following numbers by making the calls in your program (do not take in user input):
"10", "34", "222", "abba", "67867876", "444244", "123454321"
=START CODE=
#include<iostream>
#include <string>
using namespace std;
string testStr[] = {"10", "34", "222", "abba", "67867876", "444244", "123454321"};
//Procedure to check to see if value is a Palindrome.
bool isNumPalindrome( string str ) {
int length = str.length();
//Check each value in the string to see if current values matches
//corresponding value at end.
for (int i=0; i < length / 2; i++) {
if (str[i] != str[(length - 1) - i]) {
//If the value doesn't match, return false.
return false;
}
}
//Return true if the value has matched.
return true;
}
int main() {
//Check each value in the array to see if it's a Palindrome value.
for (int i=0; i < 7; i++) {
if (isNumPalindrome( testStr[i] ) == true) {
cout << testStr[i] << " is a Palindrome value." << endl;
} else {
cout << testStr[i] << " is not a Palindrome value." << endl;
};
};

return 0;
}
=END CODE=

You might also like