Assignment 19
Due Thursday, June 14 at 9:20am on Canvas

Assignment 19.1: Functions Worksheet 3 (10pts)

  • Copy and paste the starter code into a new file called funFunctions3.cpp
  • Write the required functions as described by the prototypes and comments.
  • The functions should be written below main.
  • Then, run the code when you are finished to see if you wrote the functions correctly.
  • Check the test results and make any alterations to your functions as necessary.
  • When all of the tests pass, submit your program.
/**
 *
 * CIS 22A
 */

#include <iostream>
using namespace std;

bool isLetter(char letter);
//Given a char, uses ASCII to determine if it is a letter
//Returns true if is a letter (a-z or A-Z)
//Returns false if it is not a letter
//isLetter('d') -> true
//isLetter('D') -> true
//isLetter('!') -> false

bool isNumber(char num);
//Given a char, uses ASCII to determine if it is a number
//Returns true if is a number (0-9)
//Returns false if it is not a number
//isNumber('a') -> false
//isNumber('3') -> true

char capitalizeLetter(char letter);
//Given a char that is a valid letter (a-z or A-Z)
//Capitalizes the letter if it is a lower case,
//Leaves the letter unaltered if it is an upperCase
//capitalizeLetter('a') - > 'A'
//capitalizeLetter('A') -> 'A'

string capitalizeString(string str);
//Given a string, capitalizes all letters in the string and returns it
//Hint: Look back at your Assignment 15.1
//capitalizeString("I love cookies!") - > "I LOVE COOKIES!"
//capitalizeString("124 East Central Ave") -> "124 EAST CENTRAL AVE"

string spaceToComma(string list);
//Given a string, alters any blank spaces in the string
//to be commas. Hint: Use a for loop, and string indexing
//returns the new string
//spaceToComma("cats hats bats") -> "cats,hats,bats"
//spaceToComma("I love cookies! ") -> "I,love,cookies!,"

string plusOut(string str);
//Given a string, converts any number in the string to a '+'
//and returns the string
//Hint: Use a for loop, and string indexing
//plusOut("123 East 9th St")-> "+++ East +th St"
//plusOut("Agent 007")-> "Agent +++"

int main()
{
    int result;
    bool answer;
    string value;

    cout << boolalpha << "***Testing isLetter***"<< endl << endl;
    answer = isLetter('d');
    cout << "Should be true: " << answer << endl;
    answer = isLetter('D');
    cout << "Should be true: " << answer << endl;
    answer = isLetter('!');
    cout << "Should be false: " << false << endl;

    cout << "***Testing isNumber***"<< endl << endl;
    answer = isNumber('a');
    cout << "Should be false: " << answer << endl;
    answer = isNumber('9');
    cout << "Should be true: " << answer << endl << endl;

    cout << "***Testing capitalizeLetter***"<< endl << endl;
    char lower = 'a';
    lower = capitalizeLetter(lower);
    cout << "Should print A: " << lower << endl;
    char upper = 'A';
    upper = capitalizeLetter(upper);
    cout << "Should print A: " << upper << endl << endl;

    cout << "***Testing capitalizeString***"<< endl << endl;
    string str = "I love cookies!";
    str = capitalizeString(str);
    cout << "Should print I LOVE COOKIES!: " << str << endl;
    str = "124 East Central Ave";
    str = capitalizeString(str);
    cout << "Should print 124 EAST CENTRAL AVE: " << str << endl << endl;

    cout << "***Testing spaceToComma***"<< endl << endl;
    str = "cats hats bats";
    str = spaceToComma(str);
    cout << "Should be cats,hats,bats: " << str << endl;
    str = "I love cookies! ";
    str = spaceToComma(str);
    cout << "Should be I,love,cookies!,: " << str << endl << endl;


    cout << "***Testing plusOut***"<< endl << endl;
    str = "123 East 9th St";
    str = plusOut(str);
    cout << "Should be +++ East +th St: " << str << endl;
    str = "Agent 007";
    str = plusOut(str);
    cout << "Should be Agent +++: " << str << endl << endl;

    cout << "***End of Tests***" << endl;

    return 0;

}