Quiz #5

Hello everyone,

Today I am going to show you my quiz number five. Lets start!!!

Instructions:

  1. Create a function called is_palindrome which receives a string as a parameter and returns true if that string is a palindrome, false otherwise. Remember that a palindrome is a word that is the same forward or backward. For full points your function must ignore case and must work with any character (not just letters). So (“Dad$dad” is a palindrome even though the D is capital and d is lower case).
  2. Create a function called find_threes that receives as a parameter a list (or Vector or array for C++ students) of numbers and returns the sum of all numbers in that list that are evenly divisible by 3. Note if using vectors, you will need an additional parameter to represent the number of numbers in the array. So if the list was [0,4,2,6,9,8,3,12], the function would return 30 (0+6+9+3+12)

FIRST CODE:

2016-03-29 (2)

First, we have to know what a palindrome is. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward or forward (https://en.wikipedia.org/wiki/Palindrome). We have to create a function which can detect if the word that we introduce is a palindrome or not.

The code is easy but the new thing is that we need to use two iterators: RBEGIN and REND -for more info you can check this web-. In fact the propose of those vectors is to flip the word then we have to check if the new word is the same as the first word that we introduced.

Another new thing is that we are using STRING and a string is variable made by characters. Here you can get more info abou a string and iterators.

 

SECOND CODE:

2016-03-29 (3)

This code doesn’t

new thing, I explained all the parts which are used in this code in my past posts and you can chek it. Here you only have to think logically and use math.

I made the codes by reading information about it and with help of my friends José Choza and Valeria Naranjo (you can check their blogs).

Top image by: https://www.flickr.com/photos/gmanviz/14946678167

CC BY-SA 4.0 Quiz #5 by sercho93 is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.