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

  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 ..

  Implement linear support vector machine to classify data

code to implement linear Support vector machine to classify data (without using matlab built in function).

  Symmetry in the rod

matlab programming

  Create from the stack a structure string stac

Design a structure stack that represents a stack of elements of some arbitrary type. Include the functions: create(returns an empty stack), push(add an element to the top of the stack and return the resulting stack), pop(delete the top element and re..

  Describe how you would access these 4 members

Create a namespace titled global Type that contains four members. The members should be two named constants, n and rate. It should also contain a variable count and the function printResult. Describe how you would access these 4 members in a progr..

  Finite difference method

Use the finite difference method to calculate the temperature at the point specified since it is easier.

  Design and synthesis of continuous time controllers

Design and synthesis of continuous time controllers - A graphical user interface (GUI) is a human-computer interface that uses menus, dialogue box, and button which can be manipulated by a mouse

  Fit the exponential function to the relaxation data

Fit the exponential function to the relaxation data and report the filename as well as the A, tau and B values and run all 3 functions in sequence to analyze ALL data

  Create a matlab program

Create a MATLAB program that will use MATLAB's fzero function to determine d for the following parameters: R = 0.5 m and in steps of 0.1. Create a table consisting of S and d .

  Develop a simulation program

Develop a simulation program

  write a function under the name "write2"

a)Write a function under the name "write2" so that it will save the diagonal component of the given matrix...

  Matlab program to compute how much money will accumulate

Write a MATLAB program to compute how much money will accumulate in 5 years in the account and in any CDs you buy. Run the program for two different savings interest rates: 4 percent and 5 percent.

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