Generalize the program below to allow negative integers

Assignment Help MATLAB Programming
Reference no: EM13166800

Using SML: Generalize the program below to allow negative integers on the input. We assume that negative integers are preceded by the minus sign(-) rather than the tilde (~). Note that we not only have to recognize negative integers but we can no longer use -1 as a convenient value to indicate that the end of file has been reached. Hint: Return an integer option that tells whether the end of file has been reached.

 

open TextIO;

 

val END = ~1;

 

fun digit(c) = c >= #"0" andalso c <= #"9";

 

fun startInt(file) = startInt1(file,input1(file))

 

and startInt1(file, NONE) = END

| startInt1(file, SOME c) =

if digit(c) then ord(c) - ord(#"0")

else startInt(file);

 

fun finishInt(i,file) =

if i = END then END

else finishInt1(i,file,input1(file))

 

and finishInt1(i, file, NONE) = i

| finishInt1(i, file, SOME c) =

if digit(c) then

finishInt(10*i+ord(c)-ord(#"0"), file)

else i;

 

fun getInt(file) = finishInt(startInt(file), file)

 

fun sumInts1(file) =

let

val i = getInt(file)

in

if i = END then 0

else i + sumInts1(file)

end;

 

fun sumInts(filename) = sumInts1(openIn(filename));

 

 

Reference no: EM13166800

Questions Cloud

Describe what is meant by cybersecurity design : Describe what is meant by Cybersecurity Design.List and describe the principles that must be supported.
Create a program that contains 4 methods : Create a program that contains 4 methods / functions... main(), getTestScores(), calcAverage(), and displayAverage(). The main() method should call the getTestScores() method to get and return each of 3 test scores.
Describe what is meant by cybersecurity architecture : Describe what is meant by Cybersecurity Architecture. List and describe the principles that must be supported.
Threat, risk and vulnerability : Threat, Risk and Vulnerability are related to Cybersecurity. Describe these three terms and provide a business case example.
Generalize the program below to allow negative integers : Using SML: Generalize the program below to allow negative integers on the input. We assume that negative integers are preceded by the minus sign(-) rather than the tilde (~). Note that we not only have to recognize negative integers but we can no lon..
Table of hurricane categories and associated wind speeds : Review the following table of Hurricane categories and associated wind speeds (miles per hour) and storm surge levels (feet above normal).
Explain the ph of the solution is found : A saturated solution of Mg(OH)2 in contact with undissolved Mg(OH)2(s) is prepared at 25 degrees C. The pH of the solution is found to be 10.17.
Line of developmental training and inspirational materials : The Becoming Company is a full service provider for a line of developmental training and inspirational materials including videos, music, and books called Drive Change.
What fraction of thiocyanate ion is converted in complex ion : What fraction of thiocyanate ion is accually converted into the complex ion?

Reviews

Write a Review

MATLAB Programming Questions & Answers

  Symmetry in the rod

matlab programming

  Mat lab programming problem

In case the problem in the code I want you to modify it give the correct temperature.

  Write a matlab function that takes in one argument

Write a MatLab function that takes in one argument, a vector or 2-D matrix and returns a single value, the highest value in the vector or matrix. Use nested for loops to accomplish this task. Assume that all of the values in the vector or matrix are ..

  Design simple interface hardware

Evaluate the capability in selecting and configuring a microcontroller unit designing simple interface hardware and writing subroutines to operate those interfaces

  Create a matrix of 5x6

Prepare a matrix of 5x6. with identical columns and rows ranging from 200 to 1000 in equal increments

  Plot with three different shading scheme (one plot per each

create two vectors X and Y of values from (-pi) to pr with a spacing of pi/10. Define the vector Z as: Z=(sin(sqrt(x^2+y^2)))/sqrt(x^2+y^2)

  Generate by means data.m an array

Generate by measdata.m an array A withsize (365,24), containing temperature measurements for an entire year [1 January,..., 31 December], 24 hours a day [00.00h,...,23.00h].

  Filtering – biomedical application

Prepare a filter that removes noise produced by electronic medical equipment.

  In matlab to illustrate the different format specifiers

1.) Write a program in matlab to illustrate the different format specifiers that can be used for obtaining formatted output.

  Compare with the true value

compare with the true value of 6.737947 x 10 -3  . Use 20 terms to evaluate each series and compute true and approximate relative errors as terms are added.

  Create functions in file

Create Functions in File and how to code this function - Declare function inputs, and outputs

  Matlab m-script that will generate a damped sinusoid

1.) Write a MATLAB m-script that will generate a damped sinusoid (frequency = 440 Hz) with a time constant of 0.25 sec. Set the time axis for 0 to 6 time constants.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd