SD234 - Unit 5 Assignment A&b
SD234 - Unit 5 Assignment A&b
#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=
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=