Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CSE 232 Fall 2017 Programming Project 04 This assignment is worth 30 points (3%

ID: 3870433 • Letter: C

Question

CSE 232 Fall 2017 Programming Project 04 This assignment is worth 30 points (3% of the course grade) and must be completed and turned in before 11:59 on Monday, October 2 This assignment will give you more experience with functions and a little work with strings Basically, we are going to play games with an integer number and its sequence of digits. We can classify numbers as to the order of its digits and their relationship. There are 4, rather odd, categorizations which are metadrome: An integer whose digits are strictly increasing: 12343 is a metadrome, 11223 is tot. plaindrome: An integer whose digits are either the same or increasing: 11223 is a plaindrome, 11221 is not . . .katadrome: An integer whose digits are strictly decreasing: 54321 is a katadrome, 34432 is tot. nialpdrome: An integer whose digits are the same or decreasing: 334432 is a nialpdrome, 54323 is not. nondrome: If an integer is not classified as any of the above, it is a nondrome. . . Different Bases to a number We are also going to example, if the number were base 2, then only 0,1 are allowed in the integer. If the number were base 16, then 0-9 and a-f would be allowed. We are going to extend that idea all the way to base 36 by allowing the lower case letters a-z to signify a multidigit number: a-10, b-l, f-15, , z- 35. allow you to make the above distinctions in the context ofa numeric base. For Project Description/Specification Just a reminder. We peovide exact our function specifications: the function name, its return type, its arguments and each argument's type. Do not change the function declarations! Functions function: metadrome: Boolean return. Arguments are astringn, the input number, and an int base. If n is a metadrome in the provided base the function returns true, otherwise it returns false. function: plaindroce: Boolean return. Arguments are . astringn, the input number, and an int base. If n is a plaindrome in the peovided base the function returns true, otherwise it returns Ealse. function: katadrome: Boolean return. Arguments are . astringn, the input number, and an int base. If n is a katadrome in the provided base the function returns true, otherwise it returns false.

Explanation / Answer

Given below is the implementaion of the all the functions and test main function.

NOTE: YOU ONLY NEED TO COPY THE FUNCTIONS INTO YOUR STARTER FILE Prog04.cpp.  DO NOT REPLACE THE main() FUNCTION GIVEN IN Prog04.cpp.

The 5 functions to be copied are - metadrome(), plaindrome(), katadrome(), nialdrome() and classify().

Since the starter code for Prog04.cp is not provided in the question, I have written the main() function. Please don't replace the main in your starter file. Use the functions in your file and post a comment if any issues. If the code worked for you, please don't forget to rate the answer. Thank you.

#include <iostream>
using namespace std;
const string base_vals = "0123456789abcdefghijklmnopqrskuvwxyz";

bool metadrome(string n, int base)
{
string legal = base_vals.substr(0, base); //find the list of legal digits
  
if(n.length() > 0 && legal.find(n[0]) != string::npos) //if the first digit is a legal digit
{
for(int i = 1; i < n.length(); i++)
{
if(legal.find(n[i]) == string::npos || n[i] <= n[i-1]) //if illegal digit or current digit is <= previous
return false;
}
  
//all characters satisfied condition
return true;
}
else
return false;
}

bool plaindrome(string n, int base)
{
string legal = base_vals.substr(0, base); //find the list of legal digits
  
if(n.length() > 0 && legal.find(n[0]) != string::npos) //if the first digit is a legal digit
{
for(int i = 1; i < n.length(); i++)
{
if(legal.find(n[i]) == string::npos || n[i] < n[i-1]) //if illegal digit or current digit is < previous
return false;
}
  
//all characters satisfied condition
return true;
}
else
return false;
}

bool katadrome(string n, int base)
{
string legal = base_vals.substr(0, base); //find the list of legal digits
  
if(n.length() > 0 && legal.find(n[0]) != string::npos) //if the first digit is a legal digit
{
for(int i = 1; i < n.length(); i++)
{
if(legal.find(n[i]) == string::npos || n[i] >= n[i-1]) //if illegal digit or current digit is >= previous
return false;
}
  
//all characters satisfied condition
return true;
}
else
return false;
}


bool nialdrome(string n, int base)
{
{
string legal = base_vals.substr(0, base); //find the list of legal digits
  
if(n.length() > 0 && legal.find(n[0]) != string::npos) //if the first digit is a legal digit
{
for(int i = 1; i < n.length(); i++)
{
if(legal.find(n[i]) == string::npos || n[i] > n[i-1]) //if illegal digit or current digit is > previous
return false;
}
  
//all characters satisfied condition
return true;
}
else
return false;
}

}

string classify(string n, int base)
{
if(metadrome(n, base))
return "metadrome";
else if(plaindrome(n, base))
return "plaindrome";
else if(katadrome(n, base))
return "katadrome";
else if(nialdrome(n, base))
return "nialdrome";
else
return "nondrome";
}


int main()
{
string numbers[] = {"12345", "11223", "54321", "554432", "12312"};
for(int i = 0; i < 5; i++)
cout << numbers[i] << " is " << classify(numbers[i], 10) << endl;
}

output

12345 is metadrome
11223 is plaindrome
54321 is katadrome
554432 is nialdrome
12312 is nondrome