In: Computer Science
C++
It may seem hard but the instructions are listed, it's all about loops
yippee
A-bba cc xyyz
Sample Run #1 (bold, underlined text is what the user types):
? 1 file1.txt y
Sample Run #2 (bold, underlined text is what the user types):
? 2 file1.txt b
Sample Run #3 (bold, underlined text is what the user types):
? 3 file1.txt v
Sample Run #4 (bold, underlined text is what the user types):
? 4 file1.txt 21
Sample Run #5 (bold, underlined text is what the user types):
? 1 file2.txt A
Sample Run #6 (bold, underlined text is what the user types):
? 2 file2.txt A
Sample Run #7 (bold, underlined text is what the user types):
? 4 file2.txt 0
#include <bits/stdc++.h>
using namespace std;
int main(){
int choice;
ifstream i;
string fileName;
cout<<"? ";
cin>>choice>>fileName;
i.open(fileName);
char c;
if(choice==1){
cout<<c;
}
if(choice==2){
i>>c;
if(islower(c)){
int x = c;
x+=3;
if(x>122){
x-=26;
}
cout<<(char)x;
}
else{
cout<<c;
}
}
if(choice==3){
i>>c;
if(islower(c)){
int x = c;
x-=3;
if(x<97){
x+=26;
}
cout<<(char)x;
}
else{
cout<<c;
}
}
if(choice==4){
int x=0;
while(i>>c){
x+=(int)c;
}
cout<<(x%100);
}
return 0;
}
The main idea of the code lies in the fact that typecasting a char value to int by writing the (int) before it returns the ascii value of the character.