Name: ____________________________________________________ Alpha: _____________________
Describe help received: _________________________________________________________________
string s = "happy";
string t = "sad";
string foo() {
return "good";
}
char bar(string str) {
int i = str.length()-1;
return str[i];
}
bool testcap(char c) {
return ('A' <= c && c <= 'Z');
}
| expression | type (or error!) | value (or error!) |
s[1] | ||
t[2] - 'a' + 'A' | ||
foo() + 2.5 | ||
s[0] = t[0] | ||
bar(foo()) | ||
foo()[3] | ||
bar(s[0]) | ||
testcap(s) | ||
testcap(s[0]) | ||
testcap(s[0] + t[0]) |
~/$ ./shift Enter a shift value: 3 Enter a plaintext message (lower-case letters only): abc def ~/$ ./shift Enter a shift value: 3 Enter a plaintext message (lower-case letters only): capitalize fdslwdolch ~/$ ./shift Enter a shift value: 20 Enter a plaintext message (lower-case letters only): capitalize wujcnufctyAssume that the plaintext always contain only the lower-case letters. I already wrote some code for you. Complete the function definitions that so the result code may work as above.
#include <iostream>
#include <string>
using namespace std;
//============================================================
// prototypes
// c: input character, n: shift amount
char shift(char c, int n);
// w: input string, n: shift amount
string shift(string w, int n);
//============================================================
// main function: I already wrote the easy part for you.
int main() {
// get a shift value from the user
int n;
cout << "Enter a shift value: ";
cin >> n;
// get a plaintext message from the user
string s;
cout << "Enter a plaintext message (lower-case letters only): ";
cin >> s;
// shift cipher!!
cout << shift(s,n) << endl;
}
//============================================================
// function definitions
char shift(char c, int n) {
// to do: fill in the code!!
}
string shift(string w, int n) {
// to do: fill in the code!!
}
Turn In: A screen capture of a terminal window showing the
program running on the sample inputs from above, and a codeprint
printout of the source code for the three programs.