Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

A calling modem transmits each data bit 1 as a 1270 hertz tone lasting one time

ID: 3531219 • Letter: A

Question

A calling modem transmits each data bit 1 as a 1270 hertz tone lasting 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_____-hz tone for _____ time unit(s). Implementation: Create a digital.txt input file. Name must br digital.txt. Output file name must be tone.txt. Sample of contents could be: 1 0 0 0 0 1 1 0 1 0 1 1 1 1 0 0 0 1 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;

}