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

Looking for some help on my C++ program, I am a relatively new and learning prog

ID: 3872476 • Letter: L

Question

Looking for some help on my C++ program, I am a relatively new and learning programmer so I find it very useful resource to be able to relate back and forth to a more experienced programmer's code. I will give you all the instructions I am provided so we are on the same page, some if might be excess, I appreciate any help/tips given.

These functions are required

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: 12345 is a metadrome, 11223 is not. 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, 54432 is not. nialpdrome: An integer whose digits are the same or decreasing: 554432 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 allow you to make the above distinctions in the context of a numeric base. For 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-1, f-15, , z- 35.

Explanation / Answer

Below are the codes for the functions asked:

//metadrome function

bool metadrome(string n, int base)

{

                // stores the length of the string

                int len = n.length();

               

                // initiallises the prev_no with first element of the string

                int prev_no = n[0];

               

                for(int i=1 ; i<len ; i++)

                {

                                int curr_no = n[i];

                                int x = curr_no-48;        //for base comparision

                               

                                if(curr_no>=97)

                                                x = curr_no - 97 + 10;

                                               

                               

                                if(curr_no<=prev_no || x>=base)

                                                return false;

                                else

                                                prev_no = curr_no;

                }

               

                return true;

               

}

//palindrome function

bool plaindrome(string n, int base)

{

                // stores the length of the string

                int len = n.length();

               

                // initiallises the prev_no with first element of the string

                int prev_no = n[0];

               

                for(int i=1 ; i<len ; i++)

                {

                                int curr_no = n[i];

                                int x = curr_no-48;        //for base comparision

                               

                                if(curr_no>=97)

                                                x = curr_no - 97 + 10;

                                               

                               

                                if(curr_no<prev_no || x>=base)

                                                return false;

                                else

                                                prev_no = curr_no;

                }

               

                return true;

}

//ketadrome function

bool ketadrome(string n, int base)

{

                // stores the length of the string

                int len = n.length();

               

                // initiallises the prev_no with first element of the string

                int prev_no = n[0];

               

                for(int i=1 ; i<len ; i++)

                {

                                int curr_no = n[i];

                                int x = curr_no-48;        //for base comparision

                               

                                if(curr_no>=97)

                                                x = curr_no - 97 + 10;

                                               

                               

                                if(curr_no>=prev_no || x>=base)

                                                return false;

                                else

                                                prev_no = curr_no;

                }

               

                return true;

               

}

//nialpdrome function

bool nialpdrome(string n, int base)

{

                // stores the length of the string

                int len = n.length();

               

                // initiallises the prev_no with first element of the string

                int prev_no = n[0];

               

                for(int i=1 ; i<len ; i++)

                {

                                int curr_no = n[i];

                                int x = curr_no-48;        //for base comparision

                               

                                if(curr_no>=97)

                                                x = curr_no - 97 + 10;

                                               

                               

                                if(curr_no>prev_no || x>=base)

                                                return false;

                                else

                                                prev_no = curr_no;

                }

               

                return true;

               

}

// classify function

string classify(string n, int base)

{

               

                if(metadrome(n, base))

                                return "metadrome";

                else if(plaindrome(n, base))

                                return "plaindrome";

                else if(ketadrome(n, base))

                                return "ketadrome";

                else if(nialpdrome(n, base))

                                return "nialpdrome";

                else

                                return "nondrome";

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote