Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update solution1 #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 51 additions & 1 deletion solution1
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
Code for question 1
//Code for question 1 written in c++
#include <iostream>
#include <cstring>
#include <cstdlib>
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();
}