CS 202 – Bonus_Assignment
Spring 2022
Purpose: Practicing Simple and Basic Recursion Concepts.
Points: 30
Assignment:
In this assignment, you will write the definitions of 5 recursive functions that are listed in
ecFunctions.h file. This assignment is emphasized on recursion concepts. The function that calls
itself is known as recursive function.
Function Descriptions:
The following are more detailed descriptions of the required functions.
*
Calculate the power based on base and exponent; Ex: base=7; exponent=2;
output= 49
*
int power(int base, int exponent);
*
1st parameter is the a
ay,
2nd parameter is length;
3rd parameter is the item to be found
*
int recSequentialSearch(const int list[], int length, int item);
*
check if the entered number is in increasing order; Ex: given number is 189 then
it is increasing order;
if given number is 188 or 185 then it is not increasing order;
*
ool increasingOrderDigits(int num);
*
gcd-greatest common diviso
The greatest common divisor (GCD), also called the greatest common factor, of
two numbers is the largest number that divides them both.
1st parameter- first numbe
2nd parameter- second numbe
*
int gcd(int first, int second);
*
convert given decimal value to user choice of base 8 or base 16
if the number entered is 23 and if base 8 is selected then it should print 27
(23/8= 2; and 23%8 is 7 - so 27)
similarly if the number entered is 23 and if base 16 is selected then it should
print 17 (23/16= 1; and 23%16 is 7 - so 17)
*
void decToNewBase8or16(int num, int base);
*
count the number of vowels in the string;
1st parameter is the string entered by use
2nd parameter is the position of string; general usage str[pos]
3rd parameter is the length of the string
*
int vowels(string str, int pos, int length);
Find the number of vowels in a given
word
prints the menu
void showMenu();
void showMenu(){
cout
"***********************************************"
endl;
cout
"Select the option from the given MENU"
endl;
cout
"***********************************************"
endl;
cout
"0. Quit the program"
endl;
cout
"1. Power"
endl;
cout
"2. recSequentialSearch"
endl;
cout
"3. increasingOrderDigits"
endl;
cout
"4. gcd(greatest common divisor)"
endl;
cout
"5. Decimal number to base 8 or base 16"
endl;
cout
"6. Count vowels in a given word"
endl;
cout
"***********************************************"
endl;
}
Program Header Block
All program and header files must include your name, section number, assignment, NSHE
number, input and output summary. The required format is as follows:
*
Name: MY_NAME, NSHE, CLASS-SECTION, ASSIGNMENT
Description:
Input:
Output:
*
Failure to include your name in this format will result in a loss of up to 5%.
Code Quality Checks
A C++ linter1 is used to perform some basic checks on code quality. These checks include, but
are not limited to, the following:
• Unnecessary 'else' statements should not be used.
• Identifier naming style should be either camelCase or snake_case (consistently chosen).
• Named constants should be used in place of literals.
• Co
ect indentation should be used.
• Redundant return/continue statements should not be used.
• Selection conditions should be in the simplest form possible.
• Function prototypes should be free of top level const.
1 For more information, refer to: https:
en.wikipedia.org/wiki/Lint_(software)
Not all of these items will apply to every program. Failure to to address these guidelines will
esult in a loss of up to 5%.
Scoring Ru
ic
Scoring will include functionality, code quality, and documentation. Below is a summary of the
scoring ru
ic for this assignment.
Criteria Weight Summary
Compilation - Failure to compile will result in a score
of 0.
Program Header 5% Must include header block in the
equired format (see above).
General Comments 10% Must include an appropriate level of
program documentation.
Line Length 5% No lines should exceed more than eighty
(80) characters.
Code Quality 5% Must meet some basic code quality
checks (see above)
Program Functionality
(and on-time)
75% Program must meet the functional
equirements as outlined in the
assignment. Must be submitted on time
for full score.
Submission:
• Given Files : recFunctions.h, bonusRecursionMain.cpp
• Submit: Just submit your recFunctionsImp.cpp only.
• Things to Remember
• All files must compile and execute on Ubuntu and compile with C++11.
• Submit source files
◦ Submit a copy of the source file via the on-line submission
◦ You can re-submit an unlimited number of times before the due date/time.
• Late submissions will be accepted for a period of 24 hours after the due date/time for any
given lab. Late submissions will be subject to a ~2% reduction in points per an hour late.
If you submit 1 minute - 1 hour late -2%, 1-2 hours late -4%, … , 23-24 hours late -50%.
This means after 24 hours late submissions will receive an automatic 0.
• Check the Example Execution on next page
Example Execution:
Below is an example program execution.
Kishore-vm:% g++ -std=c++11 -Wall -Wpedantic bonusRecursionMain.cpp
ecFunctionsImp.cpp -o bounsOut
kishore-vm:% .
onusOut
***********************************************
Select the option from the given MENU
***********************************************
0. Quit the program
1. Powe
2. recSequentialSearch
3. increasingOrderDigits
4. gcd(greatest common divisor)
5. Decimal number to base 8 or base 16
6. Count vowels in a given word
***********************************************
Select your option: 1
You selected 1. Powe
Enter base: 2
Enter exponent: 6
2 to the power 6 = 64
***********************************************
Select the option from the given MENU
***********************************************
0. Quit the program
1. Powe
2. recSequentialSearch
3. increasingOrderDigits
4. gcd(greatest common divisor)
5. Decimal number to base 8 or base 16
6. Count vowels in a given word
***********************************************
Select your option: 2
You selected 2. recSequentialSearch
Enter search item: 21
21 is not in the list
***********************************************
Select the option from the given MENU
***********************************************
0. Quit the program
1. Powe
2. recSequentialSearch
3. increasingOrderDigits
4. gcd(greatest common divisor)
5. Decimal number to base 8 or base 16
6. Count vowels in a given word
***********************************************
Select your option: 3
You selected 3. increasingOrderDigits
Please enter an integer: 368
The digits of 368 are in increasing order.
***********************************************
Select the option from the given MENU
***********************************************
0. Quit the program
1. Powe
2. recSequentialSearch
3. increasingOrderDigits
4. gcd(greatest common divisor)
5. Decimal number to base 8 or base 16
6. Count vowels in a given word
***********************************************
Select your option: 4
You selected 4. gcd(greatest common divisor)
Enter first number: 45
Enter second number: 65
The gcd of 45 and 65 = 5
***********************************************
Select the option from the given MENU
***********************************************
0. Quit the program
1. Powe
2. recSequentialSearch
3. increasingOrderDigits
4. gcd(greatest common divisor)
5. Decimal number to base 8 or base 16
6. Count vowels in a given word
***********************************************
Select your option: 5
You selected 5. Decimal number to base 8 or base 16
Enter a non-negative integer: 23
Enter the base (8 or 16): 8
23 to the base 8 = 27
***********************************************
Select the option from the given MENU
***********************************************
0. Quit the program
1. Powe
2. recSequentialSearch
3. increasingOrderDigits
4. gcd(greatest common divisor)
5. Decimal number to base 8 or base 16
6. Count vowels in a given word
***********************************************
Select your option: 6
You selected 6. Find vowels in a given word
Enter a string: apple
Number of vowels in "apple" = 2
***********************************************
Select the option from the given MENU
***********************************************
0. Quit the program
1. Powe
2. recSequentialSearch
3. increasingOrderDigits
4. gcd(greatest common divisor)
5. Decimal number to base 8 or base 16
6. Count vowels in a given word
***********************************************
Select your option: 0
You selected 0. Quit the program
kishore-vm:%