SD234 - Unit 5 Assignment a&B

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.

Transcript of SD234 - Unit 5 Assignment a&B

Page 1: SD234 - Unit 5 Assignment a&B

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.

Page 2: SD234 - Unit 5 Assignment a&B

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", "678 67876", "444244", "123454321"}; //Procedure to check to see if value is a Palindrom e. 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 P alindrome 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 valu e." << endl; }; }; return 0; } =END CODE=