A calling modem transmits each data bit 1 as a 1270 hertz tonelasting one time u
ID: 3531328 • Letter: A
Question
A calling modem transmits each data bit 1 as a 1270 hertz tonelasting one time unit, and each data bit 0 as a 1070 hertz tone.Write a program that displays messages in an output file and on the screen indicating the tones that would be emitted for the data in the file digital.txt, a file of zeros and ones separated by spaces.The messages should take the form:
Emit_____ -hztonefor _____ time unit(s).
Implementation:
Create a digital.txt input file.Name must be digital.txt.Output file name must be
tone.txt.
Sample of contents could be:
100001101011110001
Output messages for sample data above:
Emit 1270-hz tone for 1 time unit(s).
Emit 1070-hz tone for 4 time unit(s).
Emit 1270-hz tone for 2 time unit(s).
Emit 1070-hz tone for 1 time unit(s).
Emit 1270-hz tone for 1 time unit(s).
Emit 1070-hz tone for 1 time unit(s).
Emit 1270-hz tone for 4 time unit(s).
Emit 1070-hz tone for 3 time unit(s).
Emit 1270-hz tone for 1 time unit(s).
Explanation / Answer
//please rate
#include<iostream>
#include<fstream>
using namespace std;
int main(){
char bit,pbit;
int count=0;
ifstream infile("digital.txt");
//if failed to open, exit
if(!infile){
cout<<"Input file failed to open. Press any key to continue. . . ";
cin.get();
return 0;
}
pbit=infile.get();
count=1;
while(infile){
bit=infile.get();
if(bit==pbit)
count++;
else{
if(pbit=='1')
cout<<"Emit "<<1270<<"-hz tone for "<<count<<" time unit(s)."<<endl;
else
cout<<"Emit "<<1070<<"-hz tone for "<<count<<" time unit(s)."<<endl;
count=1;
}
pbit=bit;
}
infile.close();
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.