From e3c7e842f130a687d697d2f049e6c655ce4a71d7 Mon Sep 17 00:00:00 2001 From: adit26data <98691664+adit26data@users.noreply.github.com> Date: Sun, 29 May 2022 11:38:29 +0530 Subject: [PATCH] Update solution1 --- solution1 | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/solution1 b/solution1 index 7851930..50cc7ce 100644 --- a/solution1 +++ b/solution1 @@ -1 +1,51 @@ -Code for question 1 +//Code for question 1 written in c++ +#include +#include +#include +using namespace std; +class IQUEST +{ +public: + string demo; + int key; + int n; + void getstring() + { //getting input string + getline(cin, demo); + } + void getkey() + { //getting input key + cin >> key; + } + void operate(); + void shift(); +}; +void IQUEST::operate() +{ +//encoding the word as per key shift + int length = demo.length(); + char ch; + for (int i = 0; i <= length - 1; i++) + { + if ((demo[i] + key) > 122) //if the encoded character goes beyond the alphabet range + demo[i] = (char)(demo[i] + key - 97); + else + demo[i] = (char)(demo[i] + key); + } +} +void IQUEST::shift() +{//performing shift ie is actually a circular shift + demo = demo[demo.length() - 1] + demo.substr(0, demo.length() - 1); + cout << demo << endl; +} +int main() +{ + IQUEST obj; + obj.getstring(); + obj.getkey(); + obj.operate(); + int n;//getting number of shifts from the user + cin >> n; + for (int i = 1; i <= n; i++) + obj.shift(); +}