#include <iostream> // I/O #include <string> // allows access to string object #
ID: 3656298 • Letter: #
Question
#include <iostream> // I/O
#include <string> // allows access to string object
#include <cstdlib> // allows access to EXIT_SUCCESS
#include <list> // allows access to the STL list
#include <algorithm> // allows access to the find algorithm
using namespace std;
/*
Description: converts uppercase letters to lowercase letters in a string
In: a string to change
Out: the new string with all lowercase letters
Side: none
*/
string lowercase(string str);
int main( )
{
// variable declarations
list<char> alphabet; // the alphabet that will be deranged
list<char>::iterator list_iter; // iterator to go through the alphabet
string keyword; // a string to hold the user keyword
string::reverse_iterator str_rev_iter; // reverse iterator to go backward through keyword
// * 1 *
// put the lowercase letters 'a' through 'z' into the list
for(list_iter = alphabet.begin(); list_iter != alphabet.end(); list_iter++)
{
cout<<*list_iter<<' ';
}
cout << endl;
// output the list contents showing that all of the letters are there
for(char ch= 'a'; ch <= 'z'; ch++)
{
cout << ch;
}
cout << endl << endl;
// ask the user to enter a word
cout << "Please enter a keyword: ";
getline(cin, keyword);
cout << endl;
// * 2 *
// for each character in keyword remove it from the list
for ()
How do you make a for-loop to remove each character in a certain keyword from the alphabet?
Explanation / Answer
alphabet = ["A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"] print "Alphabet" print alphabet # Lets get the keyword keyword = raw_input ("What is the keyword?: " ) print keyword keyword = keyword.upper() print keyword alphabet.append(keyword) print alphabet # Now somehow remove repeated letters # And place the keyword at the beggining alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" keyword = raw_input().upper() # You may want to check that the keyword contains only letters from A-Z # if not keyword.isalpha(): # do something for letter in keyword: # remove keyword letters from alphabet alphabet = alphabet.replace(letter, "") d = int(raw_input()) #displacement value/replace with stronger integer retrieval code. strVar.isdecimal() can help here. cipher = alphabet[-d:] + keyword+ alphabet[:-d]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.