本文介绍了将此C ++代码转换为java代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 #include< fstream.h> #include< iostream.h> #include< conio.h> #include< ; stdlib.h> #include< string.h> fstream infile,outfile; char source [20],dest [20 ]; void fileopen(fstream& file,char * fn,int mode) { file.open(fn,mode) ; if(!file) { cout<<文件不退出; getch (); 退出(0); } } void readfilename() { cout<<输入执行加密/解密文件的来源:; cin>>来源; fileopen(infile,source,ios :: in | ios :: binary); cout<<输入目标文件来存储加密/解密文件:; cin>> dest; fileopen(outfile,dest,ios :: out | ios :: binary); } void subecn() { char ch; readfile name(); while(infile) { infile.get(ch); if(b) infile) outfile.put(ch + 1); } } void subdecr() b $ b $ charfilename(); while(infile) { infile.get(ch); if(infile) outfile.put(ch-1); } } void tranecn() { char ch,* buff,* str1,* str2; int i = 0,j = 0,k = 0; readfilename(); while(infile) { infile.get(ch); if(infile) buff [i ++] = ch ; } buff [i] ='\ 0'; str1 =(char *)malloc(strlen(buff)/ 2 + 1); str2 =(char *)malloc(strlen(buff)/ 2 + 1); for(i = 0; i< strlen(buff) ); i ++)> if(i%2 == 0) str1 [j ++] = buff [i]; else str2 [k ++] = buff [i]; str1 [j] ='\ 0 ; str2 [k] ='\ 0'; outfile<< str1<< str2; } void trandecr() { char ch,* buff,* str1,* str2; int i = 0 ,j = 0,mid; readfilename(); while(infile) { infile。 get(ch); if(infile) buff [i ++] = ch; } buff [i] ='\ 0'; cout<< buff; if(strlen(buff)%2 == 0) mid = strlen(buff)/ 2; else mid = strlen(buff)/ 2 + 1; str1 =( char *)malloc(mid + 1); str2 =(char *)malloc(mid + 1); strncpy(str1,buff,mid); for(i = mid; i< strlen(buff); i ++)> str2 [j ++] = buff [i]; str1 [mid] ='\ 0'; str2 [j] ='\ 0'; for(i = 0; i< mid; i ++)> ; outfile<< str1 [i]<< str2 [i]; } int main() { int choice; whil e(1) { cout<<1 sub encr,2 sub decr,3 tran encr 4 tran decr,5 exit\\\; cin>> choice; 开关(选择) { 案例1:subecn(); 休息; 案例2:subdecr(); 休息; 案例3:tranecn(); 休息; 案例4:trandecr(); 休息; 案例5:返回0; } infile.close(); outfile.close(); } }#include<fstream.h>#include<iostream.h>#include<conio.h>#include<stdlib.h>#include<string.h>fstream infile,outfile;char source[20],dest[20];void fileopen(fstream &file, char *fn, int mode){file.open(fn,mode);if(!file){cout<<"file doesnot exit";getch();exit(0);}}void readfilename(){cout<<"enter the source to perform encrpyt/decrypt the file:";cin>>source;fileopen(infile,source,ios::in|ios::binary);cout<<"enter the destination file to store encrypt/decrypted file:";cin>>dest;fileopen(outfile,dest,ios::out|ios::binary);}void subecn(){char ch;readfilename();while(infile){ infile.get(ch); if(infile)outfile.put(ch+1);}}void subdecr(){char ch;readfilename();while(infile){infile.get(ch); if(infile)outfile.put(ch-1);}}void tranecn(){char ch,*buff,*str1,*str2;int i=0,j=0,k=0;readfilename();while(infile){infile.get(ch);if(infile)buff[i++]=ch;}buff[i]='\0';str1=(char *)malloc(strlen(buff)/2+1);str2=(char *)malloc(strlen(buff)/2+1);for(i=0;i<strlen(buff);i++)>if(i%2==0)str1[j++]=buff[i];elsestr2[k++]=buff[i];str1[j]='\0';str2[k]='\0';outfile<<str1<<str2;}void trandecr(){char ch,*buff,*str1,*str2;int i=0,j=0,mid;readfilename();while(infile){infile.get(ch);if(infile)buff[i++]=ch;}buff[i]='\0';cout<<buff;if(strlen(buff)%2==0)mid=strlen(buff)/2;elsemid = strlen(buff)/2+1;str1=(char *)malloc(mid+1);str2=(char *)malloc(mid+1);strncpy(str1,buff,mid);for(i=mid;i<strlen(buff);i++)>str2[j++]=buff[i];str1[mid]='\0';str2[j]='\0';for(i=0;i<mid;i++)>outfile<<str1[i]<<str2[i];}int main(){int choice;while(1){cout<<"1 sub encr, 2 sub decr, 3 tran encr 4 tran decr, 5 exit\n";cin>>choice;switch(choice){case 1: subecn();break;case 2: subdecr();break;case 3: tranecn();break;case 4: trandecr();break;case 5: return 0;}infile.close();outfile.close();}}推荐答案 根本不是问题。 没有(大不了),我们不会为你写任何东西。这是你需要做的事情。 我认为这是一个功课;它不会在这里受理。 如果你希望我们做你的功课,那就不行了。这背后有一个很好的理由:你不会学到任何东西,如果你希望别人为你做你的工作。 你可以尝试一下一开始就拥有,当你卡在任何地方时,来自这里的任何人都会尽力帮助你。 感谢理查德 [ ^ ],请阅读第6个点:指南的链接 [ ^ ] -KRNot a question at all.And no (a big no), we're not going to write anything for you. That's is something you need to do.As I assume, this a homework; it won't entertained here.If you expect us to do your homework, that's not going to work. There's a pretty good reason behind this: "You won't be learn anything, if you expect others do your work for you".You can try something on your own at first and when you stuck anywhere, anyone from here would do his/her best to help you out.Thanks to Richard [^], please read the 6th point from this: A link to the Guidelines[^]-KR 这篇关于将此C ++代码转换为java代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
09-11 10:46