求一c++程序设计 答案!急用!谢谢!!

来源:百度知道 编辑:UC知道 时间:2024/05/29 14:15:50
译密码。为使电文保密,往往按照一定规律将电文转换成密码,收报人再按照约定的规律将其译回原文。例如,可以按以下规律将电文变成密码:将字母A变成E,a变成e,即变成其后的第4个字母,W变成A,X变成B,Y变成C,Z变成D,见下图。字母按上述规律转换,非字母字符不变。如〃Wonderful!〃转换为〃Asrhivjyp!〃。输入一行字符,要求输出其相应的密码。

不好意思头文件写错了现在正确了
#include<iostream.h>
#include<stdio.h>
void main()

#include<iostream.h>
#include<stdio.h>
void main()
{
int i=0;
char str[100];
cout<<"电文为:\n"<<endl ;
gets(str);
while(str[i])
{if( (str[i]>='a'&&str[i]<'w')||(str[i]>='A'&&str[i]<'W') ) str[i]+='e'-'a';
else if( (str[i]>='w'&&str[i]<'z')||(str[i]>='W'&&str[i]<'Z') ) str[i]-='w'-'a';
i++;
}
cout<<"密码为:"<<endl;
puts(str);

}

//模块化的
#include <iostream>
#include <string>
using namespace std;

string& ToCode(string& str,const int n=4){ //加密
for(string::iterator it=str.begin();it!=str.end();it++){
if(*it>='A'&&*it<='Z'){