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;
}
6. You pilot a small plane. Your plane receives the following information from nearby planes: the...
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-) 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 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 -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 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 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 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: ▪ 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 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 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...