[Solved] CS302 Assignment 1: Fun with recursion

$25

File Name: CS302_Assignment_1:_Fun_with_recursion.zip
File Size: 357.96 KB

SKU: [Solved] CS302 Assignment 1: Fun with recursion Category: Tag:
5/5 - (1 vote)

Description

In this assignment, you will implement a series of problems using recursion, the problems are:

  1. Output a series of stars (refer to the sample output), you will need to implement the following recursive functions to perform this problem
    • void printStarsIncreasing(int) a function that prints out stars in a right triangle form, the first line has one star, the next row has two stars, the next row has three stars up to the integer passed in, if I pass in the value 4, then this function prints out one line with one star, next line with two stars, the next line with three stars, and the last line with 4 stars
    • void printStarsDecreasing(int) a function that prints out stars in a right triangle form using an integer passed in, the first line prints out the amount of stars passed into the function, the next line prints out one less star and so on, if I pass in the value 4, the first line prints out four stars, the next line prints out three stars, the next line prints out two stars, and the last line prints out one star
    • void printStarsUtil(int) this function takes in an integer and prints out that amount of stars, this function will be used in the printStarsIncreasing and printStarsDecreasing

You can visualize the problem in a way that you would need two nested loops, think of printStarsUtil as the inner loop and printStarsIncreasing and printStarsDecreasing as the two separate outer loops

  1. Verify if a string is a palindrome using the following recursive function: bool isPalindrome(string), the function takes in string object and returns true if the string is a palindrome and false otherwise, a palindrome is a string that reads the same from left to right and right to left
  2. Verify if the digits in a given number is increasing from left to right using the following recursive function: bool increasingDigits(unsigned long long) returns true if the number read from left to right is non decreasing, i.e. if I pass in 1234 or 111345 would return true and for 2314 or 98653 would return false

Specifications

  • Comment your code and your functions
  • Do not modify the function prototypes
  • Do not use global variables
  • Everything must be recursive, you can only use a loop structure for input

Example Output

$ g++ Assignment01.cpp

$ ./a.out

Enter the width: hi Seriously?! Wow!

Enter the width: -9 Seriously?! Wow!

Enter the width: 0 Seriously?! Wow!

Enter the width: 4

*

**

***

****

****

***

**

*

Ok hopefully that worked Enter a string: racecar racecar is a palindrome, nicely done

Hopefully we are still doing alright, last part

Enter a number: 1222345

Looks like the digits are increasing from left to right

$ ./a.out

Enter the width: 3

*

**

***

***

**

*

Ok hopefully that worked

Enter a string: everyvillainislemons

Oh well, everyvillainislemons is not a palindrome

Hopefully we are still doing alright, last part Enter a number: hi

Can we just NOT do this again?!?!?!?!

Enter a number: 2345671

Digits do not increase from left to right, oh well

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[Solved] CS302 Assignment 1: Fun with recursion
$25