Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NANO 15/CENG 15: Homework 8 Due on Thursday, 12/03/2015 Problem 1: Write a script that will read from a file x and y data points

NANO 15/CENG 15: Homework 8 Due on Thursday, 12/03/2015 Problem 1: Write a script that will read from a file x and y data points in the following format: x 0 y 1 x 1.3 y 2.2 x 2.2 y 6 x 3.4 y 7.4 The format of every line in the file is the letter 'x', a space, the x value, space, the letter 'y', space, and the y value. First, create the data file with 10 lines in this format. Do this by using the Editor/Debugger, then File Save As xypts.dat. The script will attempt to open the data file and error-check to make sure it was opened. If so, it uses a for loop and fgetl to read each line as a string. In the loop, it creates x and y vectors for the data points. After the loop, it plots these points and attempts to close the file. The script should print whether or not the file was successfully closed. Problem 2: Modify the script from the previous problem. Assume that the data file is in exactly that format, but do not assume that the number of lines in the file is known. Instead of using a for loop, loop until the end of the file is reached. The number of points, however, should be in the plot title. Problem 3: Create a file \"parts_inv.dat\" that stores on each line a part number, cost, and quantity in inventory, in the following format: 123 5.99 52 456 3.97 100 333 2.22 567 Use fscanf to read this information, and print the total dollar amount of inventory (the sum of the cost multiplied by the quantity for each part). Problem 4: Create a file phonenos.dat of phone numbers in the following form: 6012425932 6178987654 8034562468 Read the phone numbers from the file and print them in the form: 601-242-5932 Use load to read the phone numbers. 1

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_2

Step: 3

blur-text-image_3

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

Calculus Early Transcendentals

Authors: James Stewart

7th edition

538497904, 978-0538497909

More Books

Students also viewed these Mathematics questions