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

A CALLING MODEM A calling modem transmits each data bit 1 as a 1270 hertz tone l

ID: 3931032 • Letter: A

Question

A CALLING MODEM

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 and writes to an output file messages indicating the tones that would be emitted for the input data , a file of zeros and ones separated by spaces. The messages should take the form:

Emit____ -hz tone for ___________  time unit(s).

Be sure to prompt the user for file names.

input file:

1  0  0  0  0  1  1  0  1  0 1  1   1  1  0  0  0  1

output:

Emit 1270-hz tone for 1 time unit(s).

Emit 1070-hz tone for 4 time units(s).

Emit 1270-hr tone for 2 time units(s).

Explanation / Answer

//This is a C code. It takes an "output.txt" as input.

#include <stdio.h>

int main(void)

{

FILE *fp;

char c;

int i,count1=0,count0=0;

fp = fopen("output.txt", "r"); // error check this!

while((c = fgetc(fp)) != EOF) {

if (c == '1') {

if(count0!=0)

{

printf("Emit 1070-hz tone for %d time unit(s). ",count0);

count0=0;

}

count1++;

}

if(c == '0')

{

if(count1!=0)

{

printf("Emit 1270-hz tone for %d time unit(s). ",count1);

count1=0;

}

count0++;

}

}

if(count1!=0)

{

printf("Emit 1270-hz tone for %d time unit(s). ",count1);

count1=0;

}

if(count0!=0)

{

printf("Emit 1070-hz tone for %d time unit(s). ",count0);

count0=0;

}

fclose(fp);

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote