Skip to content
Snippets Groups Projects
Commit e00f4bd7 authored by g5-chappell's avatar g5-chappell
Browse files

Upload New File

parent eeefa3a7
No related branches found
No related tags found
No related merge requests found
main.cpp 0 → 100644
// Worksheet 5
#include "cipher.hpp"
#include <iostream>
//-----------------------------------------------------------------
// Task 1 - Implement the name_to_initials function
// This function should return the user’s initials (i.e., the first letter of each word in their name) with no spaces.
// You may assume that the user’s input will contain only letters (uppercase and/or lowercase) plus spaces.
// You don’t need to worry about punctuated names like Augusta Ada King-Noel, Conan O’Brien, or David J. Malan!
//But the user’s input might be sloppy! In which case there might be one or more spaces at the start and/or end
// of the user’s input or even multiple spaces in a row. You should correctly provide Initials in these cases.
//-----------------------------------------------------------------
std::string name_to_initials(std::string name)
{
// User inputs their name
char name[];
cout << "Input first and last name:\n";
cin >> name;
// Determine length of string (to do the for loop)
int length = sizeof(name);
// Variable for writing the initials
int initials_count = 0;
char initials_string[];
// For loop - Process string for capital letters
for (int i = 0; i > length; i++)
{
if (name[i] = " ")
{
length = length + 1;
}
else if (isupper(name[i]))
{
initials_string[initials_count] = name[i];
initials_count = initials_count + 1;
}
}
for (int j = 0; j > length; j++)
{
cout << initials_string[j];
}
return name;
}
//-----------------------------------------------------------------
// Task 2 - Caesar Cypher
// Implement the set_shift and encode functions
// Set shift provides you with the shift value from the web interface.
// You should use this value to set your own variable that can be used in the encode function to
// indicate how many latters to shift. (Hint: think about the scope of this variable to ensure it can be used)
// The encode function recieves a the message from the web interface to be encoded and should return the encoded output.
//-----------------------------------------------------------------
void set_shift(unsigned int value) {
std::cout << value << '\n';
}
std::string encode(std::string message) {
return message;
}
//-----------------------------------------------------------------
// Task 3 - Substitution Cypher
// Implement substitution_set and substitution_encode functions
// substitution_set provides a substituion string from the web interface.
// You should use this string to set your own variable that can be used in the substitution_encode function to
// indicate what letters are substituded for what. (Hint: think about the scope of this variable to ensure it can be used)
// The substitution_encode function recieves a the string message from the web interface to be encoded and should return the substituted/cyphered output.
//-----------------------------------------------------------------
void substitution_set(std::string sub) {
std::cout << sub << '\n';
}
std::string substitution_encode(std::string message) {
return message;
}
//Nothing to do here, main just runs the project which is defined elsewhere for you...
// run() will call your functions as appropriate.
int main(int argc, char **argv) {
run(argc, argv);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment