From e00f4bd70389e1b88b2c766f26efb428848421a9 Mon Sep 17 00:00:00 2001 From: g5-chappell <gareth2.chappell@live.uwe.ac.uk> Date: Fri, 19 Nov 2021 03:09:07 +0000 Subject: [PATCH] Upload New File --- main.cpp | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 main.cpp diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..848fde1 --- /dev/null +++ b/main.cpp @@ -0,0 +1,95 @@ +// 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); +} -- GitLab