Software Engineering for Students A Programming Approach

Software Engineering for Students A Programming Approach Software Engineering for Students A Programming Approach

web.firat.edu.tr
from web.firat.edu.tr More from this publisher
21.08.2013 Views

The following issues are considered to be important: ■ matching the language to the application area of the project ■ clarity, simplicity, and orthogonality ■ syntax ■ control abstractions ■ primitive data types ■ data typing ■ enumerations ■ arrays ■ records (structures). Exercises 197 • Exercises 14.1 Suppose that you were asked to design a new programming language for software engineering. ■ select and justify a set of control structures ■ select and justify a set of primitive data types. 14.2 Argue either for or against strong typing in a programming language. 14.3 How many kinds of looping structure do we need in a programming language? Make suggestions. 14.4 From the discussion in this chapter, list the possible problem features with either programming languages in general or a programming language of your choice. 14.5 “In language design, small is beautiful.” Discuss. 14.6 Argue for or against the inclusion of the break statement in a programming language 14.7 The language LISP has the ultimate simple syntax. Every statement is a list. For example: (+ 1 2) returns the sum of the parameters. Investigate the syntax of Lisp and discuss whether every language could and should have syntax that is as simple.

198 Chapter 14 ■ The basics Answers to self-test questions 14.1 When some input from the user’s keyboard is required. It must be checked and, if necessary, new input solicited until the input is correct. 14.2 int[] table; boolean search(int wanted) { boolean found = false; int i = 0; } endSearch: while (i < table.length) { if (table[i] == wanted) { found = true; break endSearch; } i++; } return found; Without using break: int[] table; boolean search(int wanted) { boolean found = false; int i = 0; } while (i < table.length and found == false) { if (table[i] == wanted) found = true; else i++; } return found; 14.3 Yes and no. Clearly these operations are not something that should be allowed with integers and reals. But in Java the bit structure of these data types is precisely defined. Also the effects of these operations are precisely defined. So these particular data types have an extended set of valid operations.

198 Chapter 14 ■ The basics<br />

Answers to self-test questions<br />

14.1 When some input from the user’s keyboard is required. It must be<br />

checked and, if necessary, new input solicited until the input is correct.<br />

14.2 int[] table;<br />

boolean search(int wanted) {<br />

boolean found = false;<br />

int i = 0;<br />

}<br />

endSearch:<br />

while (i < table.length) {<br />

if (table[i] == wanted) {<br />

found = true;<br />

break endSearch;<br />

}<br />

i++;<br />

}<br />

return found;<br />

Without using break:<br />

int[] table;<br />

boolean search(int wanted) {<br />

boolean found = false;<br />

int i = 0;<br />

}<br />

while (i < table.length and found == false) {<br />

if (table[i] == wanted)<br />

found = true;<br />

else<br />

i++;<br />

}<br />

return found;<br />

14.3 Yes and no.<br />

Clearly these operations are not something that should be allowed<br />

with integers and reals.<br />

But in Java the bit structure of these data types is precisely defined.<br />

Also the effects of these operations are precisely defined. So these particular<br />

data types have an extended set of valid operations.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!