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

i want the answer of question 8.8 ... The program in Example 8.5 illustrated the

ID: 3624803 • Letter: I

Question

i want the answer of question 8.8 ...

The program in Example 8.5 illustrated the use of formatted I/O commands to read (x, y) pairs of data from a disk. However this could also be done with load - ascii function. Rewrite this program to use load instead of the formatted I/O output functions. Test your rewritten program to confirm that it gives the same answers as Example 8.5. Rewrite the program in Example 8.5 to use the textread function instead of the formatted I/O functions. How difficult was it to use textscan, compared to using textread, load-ascii, or the formatted I/O functions? Write program that reads an arbitrary number of real values from user specified input data file, rounds the value to the nearest integer, and writes the integers out to the user specified output file. Make sure that the input file exits, and if not, tell the user and ask for another input file. If the output file exits ask user whether or not to delete it. If not, prompt for the different output file name. Table of Sines and Cosines Write a program to generate a table continue the sine and cosine of 0 for 0 between 0degree and 90degree. in 1degree increments The program should properly label each of the column in the table File int. dat (available at this book's Web site) contains 25 integer values in 'int8' format. Write a program that reads these values into a single array using function fread. Interest Calculations Suppose that you have a sum of money P in an interest-bearing account at a local bank (P stands for present value) If the bank pays you interest on the money at a rate of i percent per year compounds the interest monthly, the amount of money that you will have in the bank after n months is given by the equation

Explanation / Answer

% Get the name of the file containing the input data.
filename1 = input('Enter the input file name: ','s');

% Check to see that file exists
while ~exist(filename1,'file')
   disp('Input file does not exist. Try again!');
   filename1 = input('Enter the input file name: ','s');
end

% Get the name of the file to write the output data to.
filename2 = input('Enter the output file name: ','s');

% Check to see if output file exists
while exist(filename2,'file')
   yn = input('Output file exists. Replace (Y/N)? ');
   if yn(1) == 'Y' | yn(1) == 'y'
     
      % Replace output file
      break;
  
   else
  
      % Get new file name
      filename2 = input('Enter new output file name: ','s');
   end
end

% Open the input file. The file permission is 'r' because
% the file must already exist.
fid1 = fopen(filename1,'r');

% Is the open OK?
if fid1 < 0

   % Open failed. Tell user.
   fprintf('Open failed on input file: FID = %d ',fid1);
  
else

   % File opened successfully. Open output file.
   fid2 = fopen(filename2,'w');
  
   % Is the open OK?
   if fid2 < 0

      % Open failed. Tell user.
      fprintf('Open failed on output file: FID = %d ',fid2);
  
   else
  
      % It all ready. Get the data now.
      while feof(fid1) == 0
     
         value = fscanf(fid1,'%f',1);
         fprintf(fid2,' %d ',round(value));
        
      end
     
      % All done. Close output file.
      fclose(fid2);
     
   end
  
   % All done. Close input file.
   fclose(fid1);
end