Question: // Copyright 2018 name email // stringfunctions_original.cpp is a template // // make a copy of this file to stringfunctions.cpp to submit. // // error

// Copyright 2018 name email

// stringfunctions_original.cpp is a template // // make a copy of this file to stringfunctions.cpp to submit. // // error output is coded as follows:

// w - is_word // p - is_palindrome // a - add // c - convertbase // m - multibase

#include #include using std::string; using std::cerr; using std::cout; using std::cin;

bool is_word(string s) { return true; // fix this line }

bool is_palindrome(string num, bool * error) { return true; // fix this line }

string add(const string& num1, const string& num2) { return ""; // fix this line }

string convertbase(const string& numstr, const int frombase, const int tobase) { return ""; // fix this line }

string multibase(int x) { return ""; // fix this line }

// leave this line and everything below as is int main() { bool error;

cerr

// is_word basic tests if (not is_word("test")) cerr

if (is_word("123")) cerr

// is_palindrome basic tests if (not is_palindrome("12321", &error) or error) cerr

if (is_palindrome("abcba", &error) or not error) cerr

if (is_palindrome("123", &error) or error) cerr

// add basic tests if (add("123", "456") != "579") cerr

string longone(120, '2'); longone[0] = '3'; string longother(123, '1'); longother[0] = '4'; longother[3] = '2'; string longresult(123, '3'); longresult[0] = '4'; longresult[1] = '1'; longresult[2] = '1'; longresult[3] = '5';

if (add(longone, longother) != longresult ) cerr

// convertbase tests

if (convertbase("1111", 2, 10) != "15" ) cerr

if (convertbase("987123", 30, 30) != "987123" ) cerr

if (convertbase("azbc", 100, 2) != "10111101110000110010011011") cerr

// multibase tests

if (multibase(121) != "3 7 8 10 120") cerr

// ad-hoc tests from cin

string asktype; bool res; string userinput, num1, num2; int mbase, frombase, tobase;

while (cin >> asktype) { if (asktype == "w") { // is_word std::cin >> userinput; cout > userinput; res = is_palindrome(userinput, &error); cout > num1 >> num2; cout > userinput >> frombase >> tobase; cout > mbase; cout

 // Copyright 2018 name email // stringfunctions_original.cpp is a template //

// make a copy of this file to stringfunctions.cpp to submit. //

// error output is coded as follows: // w - is_word //

3 String Functions This assignment has a different structure than the first two. Instead of writing main), you will be provided main) and your task is to write functions to complete the required functionality. The functions calculate properties of strings or numbers as strings, and are described below The starting file is available on the website as stringfunctions_original.cpp The submitted file must be called stringfunctions.cpp 3.1 Word Strings Write a function is word with the following signature: bool is word(string s) that returns true is s is a word, and false otherwise. A word is defined as only having the characters a-zA-Z and nothing else all lowercase, capitalized at least one character long or all use (e test, Test, TEST) 3.2 Palindromic Number Strings Write a function is_palindrome with the following signature bool is palindrome (string num, bool *error) that returns true if num is a palindromic number string in base 10, and false otherwise The function also must set the error condition error, which should be true if num is not a valid positive integer So, if num contains any character other than 0-9 or if num contains leading zeros, err or should b e true and false otherwise. The number "0" should return true and *error as false

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!