Sale!

Lab 4 Functions

Original price was: $40.00.Current price is: $30.00.

Category:

Description

Rate this product

CPSC 121
Lab 4
Functions
Create a program that:
1. Declare a string and assign it an arbitrary starting value of your choosing
2. Display the current contents of your string, then displays the following menu. If a
function returns a string, it should replace the contents of your string, otherwise display
the resulting information and leave the string unchanged. Function headers are
provided; they should be used as-is in the manner appropriate.
a. string getInput()
i. MUST use getline (with cin)
1. Due to differences in treatment of the \n character when we hit
enter, cin.ignore may have to be used to fix the input buffer
ii. Reads user input from cin and stores it in the string being used. Contents
will set initial state for the string next loop through program.
b. string printBetween(int a, int b, int step = 1)
i. Will return a string containing all numbers between a and b, including a
and b, counting up
ii. E.G. a = 6, b = 3, output = “3456” (don’t use spaces)
1. If only two values are provided in the function call, assumes step
of 1
iii. Order is unassumed, but data is displayed counting up
c. string nonalnum_removed(string input)
i. Returns the string provided as input with all characters that are neither
digits nor alphabetic removed
1. Will probably involve function isalnum (slides/internet for
references)
2. If a string, str, has its length changed, any saved results from
str.length() calls will be STALE, meaning they no longer reflect our
data
d. string alphabet_numberified(string input)
i. Returns the string provided as input, except with (only) alphabetic
characters converted to their character codes within the string
1. “11a11” would become “119711”
e. int sumDigits(string digitString)
i. Attempts to read each character as a digit, and returns the sum
ii. Inclusion of non-digit characters should result in a notification (via cout) of
the character that could not be summed up
f. void saveString(string savedStr)
i. Prints the current string’s contents to a file named <your lab filename>.txt
1. You can overwrite the previous contents
3. Asks the user if they would like to return to step 2, or exit.
Points:
1 – Documentation, readability, format
3 – Proper use of functions
2 – Proper program flow (conditionals, loops, etc)
2 – Filename, Header, and Submission Process
1 – Files
1 – Output testing
Header
//Author: Eric May (your name)
//CPSC 121 Lab 4
//<MM/DD/YY> (Current Date)
Filename
<Last Name><First Initial>lab4.cpp, e.x. my assignment would be named MayElab4.cpp

Reviews

There are no reviews yet.

Be the first to review “Lab 4 Functions”

Your email address will not be published. Required fields are marked *