1) Study the following Program #include <iostream> #include <iomanip> #include <
ID: 3630969 • Letter: 1
Question
1) Study the following Program#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
//Program name: Decoder
const int Inverse = 19, Intercept = 21, SizeAlpha = 26;
int main(void)
{
fstream InFile;
int Shift;
bool StopFlag;
char C;
InFile.open("g:\InLab91.txt", ios::in);
do
{
InFile>>C;
StopFlag = (C == '#');
if (!StopFlag)
{
Shift = C - 'A';
C = char(Inverse * (Shift+Intercept) % SizeAlpha + 'A');
cout<<C;
}
}
while ( !StopFlag );
InFile.close();
cin.get(); cin.get();
return 0;
}
Problem: Modify the Decoder program contained in this file by replacing the DO-WHILE loop with a WHILE-LOOP. The modified program should give the same output as with the DO-WHILE loop. Test your program for correctness.
Explanation / Answer
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
//Program name: Decoder
const int Inverse = 19, Intercept = 21, SizeAlpha = 26;
int main(void)
{
fstream InFile;
int Shift;
bool StopFlag;
char C;
InFile.open("g:\InLab91.txt", ios::in);
InFile>>C;
StopFlag = (C == '#');
while ( !StopFlag )
{
Shift = C - 'A';
C = char(Inverse * (Shift+Intercept) % SizeAlpha + 'A');
cout<<C;
InFile>>C;
StopFlag = (C == '#');
}
InFile.close();
cin.get(); cin.get();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.