Question

6. You pilot a small plane. Your plane receives the following information from nearby planes: their three digit ID, and dista
Write a program that reads in a series of characters from a file called chars.txt. Count the total number of characters and t
8. Write a program the reads in a series of integers from a file called numbers.txt Sample output: There were 82 numbers in t

C language
6. You pilot a small plane. Your plane receives the following information from nearby planes: their three digit ID, and distance away in the x, y, and z directions Write a program that reads in the information from the file air test.txt and prints out the ID and distance of the nearby planes. If the distance is less than 12 miles print a warning message. (The file has one aircraft entry per line in the format 123 45 67 89. Distance is calculated by the equation sqrt(x+y'+z2). Submit the ID(s) of planes too close: Sample output: Aircraft ID: 557 Distance away: 27.09 Aircraft ID: 801 Distance away: 31.32 Aircraft ID: 665 Distance away: 98.31 Aircraft ID: 999 Distance away: 10.25**WARNING - -TOO CLOSE Aircraft ID: 414 Distance away: 110.81
Write a program that reads in a series of characters from a file called chars.txt. Count the total number of characters and the number of vowels and print it out (Vowels are a,e,i,o,u). 7. Submit the number of characters and of vowels in the file Sample output: There were 38 characters and 12 vowels in the file
8. Write a program the reads in a series of integers from a file called numbers.txt Sample output: There were 82 numbers in the file. Their average was 24.6 Calculate the average of the numbers in the file and submit that number and how many numbers were in the file: a. b. Write the square root of the number out to a text file.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer 6
======

#include <stdio.h>
int main(){
   int id;
   int x, y, z;
   double dist;
   FILE *fin = fopen("air_test.txt", "r");
   if(fin == NULL){
       printf("ERROR: could not open input file air_test.txt\n");
       return 1;
   }
  
  
   fscanf(fin, "%d %d %d %d", &id, &x, &y, &z);
   while(!feof(fin)){
       dist = sqrt(x*x + y*y + z*z);
       printf("Aircraft ID: %d Distance away: %.2f", id, dist);
       if(dist < 12)
           printf("*** WARNING -- TOO CLOSE");
       printf("\n");
       fscanf(fin, "%d %d %d %d", &id, &x, &y, &z);
   }
   fclose(fin);
}


Answer 7
=========
#include <stdio.h>
int main(){
   FILE *in = fopen("chars.txt", "r");
   char ch;
   int total = 0 , vowels = 0;
  
   if(in == NULL){
       printf("ERROR: could not open input file chars.txt\n");
       return 1;
   }
  
   ch = fgetc(in);
   while(!feof(in)){
       total++;
       if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u' ||
       ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U' )
           vowels++;
      
       ch = fgetc(in);

   }
   fclose(in);
  
   printf("There were %d characters and %d vowels in the file.\n", total , vowels);
   return 0;
}

Answer 8
========
#include <stdio.h>
#include <math.h>
int main(){
   FILE *fin = fopen("numbers.txt", "r");
   int num;
   int count = 0;
   double total = 0, avg;
   FILE *fout = fopen("output.txt", "w");
   if(fin == NULL){
       printf("ERROR: could not open input file numbers.txt\n");
       return 1;
   }
  
   fscanf(fin, "%d", &num);
   while(!feof(fin)){
       count++;
       total += num;
       fscanf(fin, "%d", &num);
   }
   fclose(fin);
   avg = total / count;
  
   printf("There were %d numbers in the file. Their average was %.1f.\n", count , avg);
  
   //write the sqrt to output.txt
   fprintf(fout, "square root of %d = %.2f\n", count , sqrt(count));
   printf("Please check output.txt for square root\n");
  
   return 0;
}

Add a comment
Know the answer?
Add Answer to:
6. You pilot a small plane. Your plane receives the following information from nearby planes: the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please put the comment each line, make sure i will have output too. write a program,...

    please put the comment each line, make sure i will have output too. write a program, Summarize (Summarize.java), containing the main() method, that first writes 10,000 random positive double type numbers, to the full accuracy of the number (15/16 decimal places), to a text file named DataValues.txt, one number per line. The program must then close that file, and reopen it for reading. Read back the values from the file and write the following information to a file named Summary.txt:...

  • FINAL Project 1-) Please submit the solution of your final as Ms-word or PDF document 2-)...

    FINAL Project 1-) Please submit the solution of your final as Ms-word or PDF document 2-) Complete THREE QUESTIONS out of the four exam questions below. 3-) FOR EACH QUESTION, IT IS REQUIRED to include Ms-Word or Pdf file contains the following A. Source file and sample of your output screen shots. B. Up to one page of your program discussion. In the discussion, state the issues that you may have problem with if there is any. Why your program...

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • Implement the Stack Class with an ArrayList instead of an array, including the following functions: -empty...

    Implement the Stack Class with an ArrayList instead of an array, including the following functions: -empty -push -peek -pop -overrided toString() function which returns all of the stack's contents Things to note: -You no longer need a size. -You no longer need to define a constant DEFAULT_CAPACITY. since ArrayLists grow dynamically. -Whenever possible, use ArrayList functions instead of the [ ] (index operator) to implement your stack functions Then write a driver program to do palindrome check. A string is...

  • Lab 5.1 C++ Utilizing the code from Lab 4.2, replace your Cargo class with a new...

    Lab 5.1 C++ Utilizing the code from Lab 4.2, replace your Cargo class with a new base class. This will be the base for two classes created through inheritance. The Cargo class will need to have virtual functions in order to have them redefined in the child classes. You will be able to use many parts of the new Cargo class in the child classes since they will have the same arguments/parameters and the same functionality. Child class one will...

  • You will be writing a simple Java program that implements an ancient form of encryption known...

    You will be writing a simple Java program that implements an ancient form of encryption known as a substitution cipher or a Caesar cipher (after Julius Caesar, who reportedly used it to send messages to his armies) or a shift cipher. In a Caesar cipher, the letters in a message are replaced by the letters of a "shifted" alphabet. So for example if we had a shift of 3 we might have the following replacements: Original alphabet: A B C...

  • C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require...

    C++ please Programming Assignment #6 Help Me Find The Secret Message Description: This assignment will require that you read in an encrypted message from a file, decode the message, and then output the message to a file. The encryption method being used on the file is called a shift cipher (Info Here). I will provide you with a sample encrypted message, the offset, and the decrypted message for testing. For this project I will provide you main.cpp, ShiftCipher.h, and ShiftCipher.cpp....

  • C++ Programming Question: This programming assignment is intended to demonstrate your knowledge of the following: ▪...

    C++ Programming Question: This programming assignment is intended to demonstrate your knowledge of the following: ▪ Writing a while loop ▪ Write functions and calling functions Text Processing [50 points] We would like to demonstrate our ability to control strings and use methods. There are times when a program has to search for and replace certain characters in a string with other characters. This program will look for an individual character, called the key character, inside a target string. It...

  • I need help with this assignment in C++, please! *** The instructions and programming style detai...

    I need help with this assignment in C++, please! *** The instructions and programming style details are crucial for this assignment! Goal: Your assignment is to write a C+ program to read in a list of phone call records from a file, and output them in a more user-friendly format to the standard output (cout). In so doing, you will practice using the ifstream class, I'O manipulators, and the string class. File format: Here is an example of a file...

  • :) Problem: ??? Your task: implement in CH the algorithm solution shown below. Then analyze it...

    :) Problem: ??? Your task: implement in CH the algorithm solution shown below. Then analyze it and explain, using just one or two sentences, what it does. Write this explanation as a comment at the top of your program. This explanation will be worth 5 points of your total grade. Do not be too detailed (for example, do not write it opens a file and then declares variables, and then reads from a file...), it should look like the problem...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT