Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ input.txt 11 12 13 14 15 16 99 99 99 99 99 99 7 8 9 0 1 2 1 2 3 4 5

C++
input.txt
11 12 13 14 15 16
99 99 99 99 99 99
7 8 9 0 1 2
1 2 3 4 5 6
9 8 7 1 2 3
image text in transcribed
image text in transcribed
image text in transcribed
Skills Required .Read and write Files Work with arrays and vectors, Create Functions, Include Headers and other files, Loops (while, for), Conditional (if, switch), Datatypes, assignment, etc Basic git commands 1. Follow the link that was given on Canvas for this Assignment to create your repository 2. Use the directions and skills from Week 1 to clone the repository into the directory of your 3. 4. choosing Open the starter solution provided Assignment You may have learned the distance formula in math or physics class. It lets you know the distance between any two points in space using x and y-coordinates in a two-dimensional space. The same formula can be modified to work in three-dimensional space if you know both x, y, and z coordinates: 21-y2)(-2 This lab will read in several sets of point coordinates from a file calculate their distances, then write those calculated distances to a file. Introduction to Reading and Writing to Files Using ifstream (input file streams) and ofstream (output file streams) variables, you can load in data from one file and out to another. First, you need to create two variables called fin and fout which will correspond to your input and output files ifstream fin("input.txt"); ofstream fout("output.txt"); You can stream in data to or from your variables from input or output files in the same way you use cin and cout to get data to and from the console (keyboard/screen): // Reads in data from input.txt to the variable x // Writes out data from the variable x to output.txt fin x; fout > x 11 If you don't know how many data elements you are reading in while (fin.good()) // While the file still has elements to read in fin > x; For the case of this lab, Writing the Distance Function You need to write a function called calcDistance().It should take in 6 parameters (all doubles which correspond to the twox, two y, and two z coordinates), calculate the distance between the two points, and return that calculation to the main() function as a double. Obviously there's no way to type in a v into your program, but C++ has a built-in function called sqrt() that looks like this: double sqrt (double x); It takes in a double and returns the square root back. There is a function to do exponents as well. You can use the pow() function like so: double pow (double x, double y); // Corresponds to x There is another way to square numbers. Just multiply the number twice (likex * x). Breaking down the formula, you should be able to figure out how to take several values and build a function out of it. Storing in Vectors ore the information in vectors. Remember you can resize a vector or use push_back to add a new value to a vector. This keeps your program easy to maintain if the number of values in the input file changes. The input file that the grader uses may have a different number of input lines to work with. St Sorting the Values (Stretch Goal) Write out to a new file called output_sorted.txt all the distances sorted from lowest to highest. You can use any of the searching algorithms found in your textbook

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Temporal Databases Research And Practice Lncs 1399

Authors: Opher Etzion ,Sushil Jajodia ,Suryanarayana Sripada

1st Edition

3540645195, 978-3540645191

Students also viewed these Databases questions

Question

What is IEEE 802.1q?

Answered: 1 week ago

Question

Organizing Your Speech Points

Answered: 1 week ago