Skip to content
Snippets Groups Projects
Forked from Configs / EC327 / Labs / Current
119 commits behind the upstream repository.
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
LabOne_ChapterFive.h 1.81 KiB
//
// Created by Ari Trachtenberg on 9/10/24.
//

// CHAPTER 5
#include <string>
using namespace std;

/**
 * @param nn A positive integer
 * @return The sum of the following values:
 *    a. The first digit of nn.
 *    b. The last digit of nn.
 *    c. The number of digits in nn.
 *
 *  @example
 *  labOne_pFour(1729) returns 14, because:
 *     a.  The first digit of 1729 = 1.
 *     b.  The last digit of 1729 = 9.
 *     c.  The number digits in 1729 = 4.
 */
int labOne_pFour(int nn);

/**
 * @param str Some string.
 * @return The reverse of [str]
 * @note Your function must be *recursive* in nature.
 * @hint Reverse the substring starting at the second character,
 *       then add the first character to the end.
 *
 * @example
 * labOne_pFive("wolf") returns "flow".
 */
string labOne_pFive(string str);

/**
 * @param str Some string.
 * @return true if and only if [str] is a palindrome
 * @see https://en.wikipedia.org/wiki/Palindrome
 *
 * @example 1
 * labOne_pSix("deed") == true because "deed" is the same forward as backward.
 *
 * @example 2
 * labOne_pSix("deeds") == false because "deeds" backwards is "sdeed", and the
 *     two strings are different.
 *
 * @example 3
 * labOne_pSix("aibophpobia") == true because the string is the same forward as backward.
 *
 */
bool labOne_pSix(string str);

/**
 * @param num A positive inteber <= 3628799.
 * @return The number [num] in the factorial number system.
 * @see https://en.wikipedia.org/wiki/Factorial
 * @see https://en.wikipedia.org/wiki/Factorial_number_system
 *
 * @example 1
 * labOne_pSeven(3) returns 11 because:
 *    3 = 1*2! + 1*1!
 *
 * @example 2
 * labOne_pSeven(10) returns 120 because:
 *    10 = 1*3! + 2*2! + 0*1!
 *
 * @example 3
 * labOne_pSeven(463) returns 34101 because:
 *    463 = 3*5! + 4*4! + 1*3! + 0*2! + 1*1!
 */
long labOne_pSeven(long num);