UMUC Asia - CMSC330 - Advanced Programming Languages
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
単語検索
|
最終更新
|
ヘルプ
]
開始行:
#contents
//** Week1 Introduction
//
//- Question
//
//Please introduce yourself in this conference. Start a n...
//
//- Answer
//
//Hello class, my name is Yuji Shimojo and I'm 25. I am f...
//
//In my spare time, I enjoy travelling. I've been to Cali...
//
//I also enjoy scuba diving. Okinawa is known as one of t...
** Week1 Discussion [#ce97172d]
- Question
What programming languages have you used? What is your f...
How familiar are you with attribute grammars, syntax anal...
Describe with specific examples, how an attribute grammar...
Describe the function of a lexical analyzer vs. a syntax ...
- Answer
''What programming languages have you used? What is your...
I have learned C, C++, Java, and CASL II in schools. In m...
Among them, my favorite language is Java because it has m...
''How familiar are you with attribute grammars, syntax an...
Honestly, I haven't heard these terms before. If I took a...
''Describe with specific examples, how an attribute gramm...
An attribute grammer is used for giving semantics to cont...
An example is shown in Sebesta (2012) Chapter 3 Example 3...
Derivation:
1. <assign> -> <var> = <expr>
2. -> A = <expr>
3. -> A = <var>[2] + <var>[3]
4. -> A = A + B
Evaluation of attributes:
1. <var>.actual_type <- look-up(A)
2. <expr>.expected_type <- <var>.actual_type
3. <var>[2].actual_type <- look-up(A)
<var>[3].actual_type <- look-up(B)
4. <expr>.actual_type <- either int or real
5. <expr>.expected_type == <expr>.actual_type is eit...
Attributes:
1. <var>.actual_type = real_type
2. <expr>.expected_type = real_type
3. <var>[2].actual_type = real_type
<var>[3].actual_type = int_type
4. <expr>.actual_type = real_type
''Describe the function of a lexical analyzer vs. a synta...
A lexical analyser is a morphological alanyser which extr...
A syntax analyzer, or a parser is a program which inputs ...
** Week1 Homework1 (6 points) [#rd437baf]
- Question
(Adapted from Sebasta (2012) Chapter 3 Problem 7)
Using the grammar in text Example 3.4 (with terminals X, ...
X = (X * Y) + ((X + Y) * Z)
- Answer
#ref(CMSC330_Homework1.pdf)
** Week2 Writing Recursive Descent Parsing Methods [#e3b5...
- Question
Choose one of the following productions and write a Java ...
<program> ->
<statement_list>.
<statement_list> ->
<statement> |
<statement> ; <statement_list>
<statement> ->
<assignment_statement> |
<write_statement> |
<read_statement> |
<if_statement> |
<while_statement>
<assignment_statement> ->
ASSIGN VARIABLE TO <expression>
<write_statement> ->
WRITE <expression>
<read_statement> ->
READ VARIABLE
<if_statement> ->
IF <expression> THEN <statement_list> [ELSE <statemen...
<while_statement> ->
WHILE <expression> DO <statement_list>
<expression> ->
VARIABLE |
LITERAL
Use the examples in section V-B of Module 1 as a guide.
- Answer
<assignment_statement> ->
ASSIGN VARIABLE TO <expression>
boolean assignmentStatement() {
if (token == ASSIGN) {
token = getNextToken();
if (token == VARIABLE) {
token == getNextToken();
if (token == TO) {
token == getNextToken();
if (expression()) {
return true;
}
}
}
}
return false;
}
** Week2 Grammar Restrictions for Recursive Descent Parse...
- Question
There are two restrictions on the type of grammars that c...
The second restriction is that the grammar must not requi...
- Answer
''The first is that the grammar cannot have any left recu...
A recursive descent parser is a kind of top-down parser. ...
For example, a simple LL(1) parser written in C is as fo...
int term ()
{
int d;
token(); /* look ahead a token */
switch(last_token) {
case '0': /* if last token is a numbe...
d = value; /* put the number to d */
token(); /* look ahead a token */
return d; /* return d */
}
}
By using term() above, a multiplying function is as below.
int mexpr()
{
int d;
d = term(); /* calculate term */
switch(last_token) { /* if last token */
case '*': /* is '*' */
d *= mexpr(); /* recurse mexpr() and the r...
return d; /* return d */
}
}
The grammar above can be expressed as "<mexpr> -> term * ...
int mexpr()
{
int d;
d = mexpr(); /* calculate mexpr. This is ...
switch(last_token) { /* if last token */
case '*': /* is '*' */
d *= term(); /* recurse mexpr() and the r...
return d; /* return d */
}
}
''The second restriction is that the grammar must not req...
The grammar requires only one token look ahead to prevent...
(a)
-> if exp then state |
if exp then state else state
(b)
-> if exp then state SD
-> else state | ε
LL(k) parsing (for k > 1) which requires two or more toke...
** Week2 Homework2 (6 points) [#wf16a810]
- Question
(Adapted from Sebasta (2012) Chapter 4 Problem 7)
Show a complete parse, including the parse stack contents...
- Answer
#ref(CMSC330_Homework2.pdf)
** Week3 Examining the Scope Rules of Java [#w4c14c05]
- Question
The scope rules of modern programming languages are roote...
Let's consider Java, a language with which everyone shoul...
One consequence of scope rules in most languages is that ...
- Answer
Here is my code.
public class ScopeRulesTest {
public static void main(String[] args) {
ScopeRulesTest scopeRulesTest = new ScopeRulesTe...
scopeRulesTest.legalSameNameVariables(false);
scopeRulesTest.legalForwardReferences();
scopeRulesTest.illegalForwardReferences();
}
/** Two local variables with same name exit in same ...
public void legalSameNameVariables(boolean b) {
boolean isTrue = b;
if (isTrue == true) {
int x = 1; // Adds 1 to local variable x.
System.out.println("x is " + x);
} else {
int x = 0; // Adds 0 to local variable x.
System.out.println("x is " + x);
}
}
/** Forward references are not always illegal. **/
public void legalForwardReferences() {
int x = y; // Adds global variable y to local va...
System.out.println("x is " + x);
}
private static int y = 1; // Defines static global v...
public void illegalForwardReferences() {
int y = x; // x is unresolved. You get a compile...
System.out.println("y is " + y);
}
}
** Week3 Pointers, References, and Object Allocation Stra...
- Question
The trend in newer languages is to replace explicit point...
Another related issue is whether the language allows obje...
- Answer
''The trend in newer languages is to replace explicit poi...
C/C++ and Ada can have pointer variables, which are calle...
On the other hand, Java, for example, doesn't have pointe...
From a perspective of program readability, I think that a...
''Another related issue is whether the language allows ob...
Java and C# support garbage collection, which automatical...
On the other hand, C++ and Ada don't support garbage coll...
Garbage collection is very convenient and it allows progr...
Therefore, using both stack and heap flexibly is important.
In C++ and C#, you can make structures by using struct op...
In conclusion, from a perspective of freedom to choose, I...
** Week3 Homework3 (6 points) [#r63ef949]
- Question
1. Scope and lifetime are distinct yet related issues in ...
class AnonymousInnerClassInMethod
{
public static void main(String[] args)
{
int local = 1;
Comparable compare = new Comparable ()
{
public int compareTo(Object value)
{
return (Integer)value - local;
}
};
System.out.println(compare.compareTo(5));
}
}
Why does this code fail to compile? What could it be modi...
2. C++ allows pointers to stack-dynamic variables. Consid...
int twice(int x)
{
int *y;
*y = x * 2;
return *y;
}
Will the above function compile in C++? Is it correct? If...
- Answer
#ref(CMSC330_Homework3.pdf)
** Week4 Operand Evaluation Order [#s1ae071e]
- Question
Although Java has the rule that the left operand of every...
** Week4 Should Indentation Have Semantic Significance? [...
- Question
Most modern programming languages are free format. Aside ...
** Week4 Project1 (25 points) [#gf5461d1]
- Question
The first programming project involves completing a progr...
gui ::=
Window STRING '(' NUMBER ',' NUMBER ')' layout widge...
layout ::=
Layout layout_type ':'
layout_type ::=
Flow |
Grid '(' NUMBER ',' NUMBER [',' NUMBER ',' NUMBER] ')'
widgets ::=
widget widgets |
widget
widget ::=
Button STRING ';' |
Group radio_buttons End ';' |
Label STRING ';' |
Panel layout widgets End ';' |
Textfield NUMBER ';'
radio_buttons ::=
radio_button radio_buttons |
radio_button
radio_button ::=
Radio STRING ';'
In the above grammar, the red symbols are nonterminals, t...
Below is an explanation of the meaning of some of the sym...
-- In the window production the string is name that is to...
-- In the production for layout_type that define the grid...
-- In the production for widget that defines a button, th...
-- In the production for widget that defines a label, the...
-- In the production for widget that defines a text field...
-- In the production for radio_button, the string is the ...
You parser should properly handle the fact that panels ca...
Below is an example of an input file:
Window "Calculator" (200, 200) Layout Flow:
TextField 20;
Panel Layout Grid(4, 3, 5, 5):
Button "7";
Button "8";
Button "9";
Button "4";
Button "5";
Button "6";
Button "1";
Button "2";
Button "3";
Label "";
Button "0";
End;
End.
The above input file should produce the GUI shown below:
- Answer
- GitHub Repository: https://github.com/yujishimojo/CMSC3...
-- InputFileAnalyzer.java
-- GUIGenerator.java
-- input.txt
** Week5 Parameter Passing [#lc00900d]
- Question
One characteristic of programming languages that varies w...
- Answer
I believe Ada is the best approach to parameter passing b...
** Week5 Nested Subprograms vs. Nested Blocks [#v302358b]
- Question
All the languages in the C family of languages allow nest...
What is the rationale for prohibiting nested subprograms?...
- Answer
Scopes of variables in if-statements, loop-statements, an...
This language specification strongly promotes standardiza...
I don't think all the programming languages should adopt ...
However, I agree with the idea in scripting languages inc...
** Week5 Homework4 (6 points) [#u07a7360]
- Question
1. What is the output of the following Java program? Expl...
import java.awt.*;
class PointParameters
{
public static void main(String [] args)
{
int x = 1, y = 1;
Point p = new Point(x, y), q = new Point(x, y);
doubleScale(x, y, p, q);
System.out.println( "(x,y) = " + new Point(x, y) +
" p = " + p + " q = " + q);
}
private static void doubleScale(int x, int y, Point ...
{
x *= 2;
y *= 2;
p.x *= 2;
p.y *= 2;
q = new Point(x, y);
}
}
Suppose a similar program were written in C# in which all...
2. Examine the following C++ program, in which a IntList ...
#include <iostream>
using name std;
class IntList
{
private:
int list[1];
public:
IntList() {list[0] = 0;}
int& operator[] (const int index) {return list[index...
};
int main()
{
IntList list;
cout << list[0] << endl;
list[0] = 1;
cout << list[0] << endl;
return 0;
}
Notice that the overloaded [] operator returns a referenc...
- Answer
#ref(CMSC330_Homework4.pdf)
** Week6 Separating the Specification and Implementation ...
- Question
One important difference between languages that provide s...
Compare Ada with both C++ and Java in this regard. Take a...
- Answer
** Week6 Type Parameterization [#cfc2de98]
- Question
Implementing type parameterization in Java was a much sim...
What about C#? Do some investigation and explore whether ...
- Answer
** Week6 Homework5 (6 points) [#h8702c8b]
- Question
1. Consider the following Java definition of a mutable st...
class MutableString
{
private char[] chars = new char[200];
private int size = 0;
public boolean set(char aChar, int index)
{
if (index < 0 || index >= chars.length)
return false;
chars[index] = aChar;
return true;
}
public String toString()
{
String result = "";
for (int i = 0; i < size; i++)
result += chars[i];
return result;
}
}
Suppose this class was rewritten in C++ in two ways, the ...
2. Consider the following C++ template class.
template <typename T, int length>
class Vector
{
public:
Vector(T values[length])
{
for (int i = 0; i < length; i++)
list[i] = values[i];
}
friend bool operator<(const Vector<T, length>& left,...
{
bool result = true;
for (int i = 0; i < length; i++)
result &= left.list[i] < right.list[i];
return result;
}
private:
T list[length];
};
int main()
{
int first[] = {1, 2}, second[] = {2, 3};
Vector<int, 2> vector1(first), vector2(second);
cout << (vector1 < vector2) << endl;
return 0;
}
The class Vector cannot be instantiated for any arbitrary...
class Int
{
public:
Int(int i = 0) {this->i = i;}
private:
int i;
};
int main()
{
Int first[] = {Int(1), Int(2)}, second[] = {Int(2), ...
Vector<Int, 2> vector1(first), vector2(second);
cout << (vector1 < vector2) << endl;
return 0;
}
Explain why the second implementation fails. What must be...
Java does have one limitation, however. Although wrapper ...
- Answer
#ref(CMSC330_Homework5.pdf)
** Week7 Homework6 (6 points) [#y82f4d4d]
- Answer
#ref(CMSC330_Homework6.pdf)
** Week8 Project2 (25 points) [#t8b6e442]
- Question
#ref(CMSC330_Project2_Specification.pdf)
#ref(CMSC330_Module3_Case_Study.pdf)
- GitHub Repository: https://github.com/yujishimojo/CMSC3...
-- C++ Header Files
-- C++ Source Files
- Test Case
#ref(CMSC330_TestCase(Project2).pdf)
** Flash Videos [#we1b3617]
*** Week1 Videos [#nd6fee56]
- [[Language Design - Part 1:http://nova.umuc.edu/~jarc/c...
- [[Language Design - Part 2:http://nova.umuc.edu/~jarc/c...
- [[Language Translators- Part 1:http://nova.umuc.edu/~ja...
- [[Language Translators- Part 2:http://nova.umuc.edu/~ja...
*** Week2 Videos [#d47cb272]
- [[Recursive Descent Parsing - Part 1:http://nova.umuc.e...
- [[Recursive Descent Parsing - Part 2:http://nova.umuc.e...
*** Week3 Videos [#ja08bda0]
- [[Scope, Visibility and Lifetime- Part 1:http://nova.um...
- [[Scope, Visibility and Lifetime- Part 2:http://nova.um...
- [[Memory Allocation- Part 1:http://nova.umuc.edu/~jarc/...
- [[Memory Allocation- Part 2:http://nova.umuc.edu/~jarc/...
*** Week4 Videos [#s8e9fe6a]
- [[Intermediate Code Generation - Part 1:http://nova.umu...
- [[Intermediate Code Generation - Part 2:http://nova.umu...
*** Week5 Videos [#n60d8132]
- [[Parameter Passing Techniques- Part 1:http://nova.umuc...
- [[Parameter Passing Techniques- Part 2:http://nova.umuc...
- [[Parameter Passing Techniques- Part 3:http://nova.umuc...
- [[Parameter Passing Techniques- Part 4:http://nova.umuc...
*** Week6 Videos [#a2b97092]
- [[Type Parameterization - Part 1:http://nova.umuc.edu/~...
- [[Type Parameterization - Part 2:http://nova.umuc.edu/~...
- [[Type Parameterization - Part 3:http://nova.umuc.edu/~...
- [[Type Parameterization - Part 4:http://nova.umuc.edu/~...
*** Week7 Videos [#c89a5a29]
- [[Uses of Inheritance - Part 1:http://nova.umuc.edu/~ja...
- [[Uses of Inheritance - Part 2:http://nova.umuc.edu/~ja...
*** Week8 Videos [#d1433b96]
- [[Competition Synchronization - Part 1:http://nova.umuc...
- [[Competition Synchronization - Part 2:http://nova.umuc...
終了行:
#contents
//** Week1 Introduction
//
//- Question
//
//Please introduce yourself in this conference. Start a n...
//
//- Answer
//
//Hello class, my name is Yuji Shimojo and I'm 25. I am f...
//
//In my spare time, I enjoy travelling. I've been to Cali...
//
//I also enjoy scuba diving. Okinawa is known as one of t...
** Week1 Discussion [#ce97172d]
- Question
What programming languages have you used? What is your f...
How familiar are you with attribute grammars, syntax anal...
Describe with specific examples, how an attribute grammar...
Describe the function of a lexical analyzer vs. a syntax ...
- Answer
''What programming languages have you used? What is your...
I have learned C, C++, Java, and CASL II in schools. In m...
Among them, my favorite language is Java because it has m...
''How familiar are you with attribute grammars, syntax an...
Honestly, I haven't heard these terms before. If I took a...
''Describe with specific examples, how an attribute gramm...
An attribute grammer is used for giving semantics to cont...
An example is shown in Sebesta (2012) Chapter 3 Example 3...
Derivation:
1. <assign> -> <var> = <expr>
2. -> A = <expr>
3. -> A = <var>[2] + <var>[3]
4. -> A = A + B
Evaluation of attributes:
1. <var>.actual_type <- look-up(A)
2. <expr>.expected_type <- <var>.actual_type
3. <var>[2].actual_type <- look-up(A)
<var>[3].actual_type <- look-up(B)
4. <expr>.actual_type <- either int or real
5. <expr>.expected_type == <expr>.actual_type is eit...
Attributes:
1. <var>.actual_type = real_type
2. <expr>.expected_type = real_type
3. <var>[2].actual_type = real_type
<var>[3].actual_type = int_type
4. <expr>.actual_type = real_type
''Describe the function of a lexical analyzer vs. a synta...
A lexical analyser is a morphological alanyser which extr...
A syntax analyzer, or a parser is a program which inputs ...
** Week1 Homework1 (6 points) [#rd437baf]
- Question
(Adapted from Sebasta (2012) Chapter 3 Problem 7)
Using the grammar in text Example 3.4 (with terminals X, ...
X = (X * Y) + ((X + Y) * Z)
- Answer
#ref(CMSC330_Homework1.pdf)
** Week2 Writing Recursive Descent Parsing Methods [#e3b5...
- Question
Choose one of the following productions and write a Java ...
<program> ->
<statement_list>.
<statement_list> ->
<statement> |
<statement> ; <statement_list>
<statement> ->
<assignment_statement> |
<write_statement> |
<read_statement> |
<if_statement> |
<while_statement>
<assignment_statement> ->
ASSIGN VARIABLE TO <expression>
<write_statement> ->
WRITE <expression>
<read_statement> ->
READ VARIABLE
<if_statement> ->
IF <expression> THEN <statement_list> [ELSE <statemen...
<while_statement> ->
WHILE <expression> DO <statement_list>
<expression> ->
VARIABLE |
LITERAL
Use the examples in section V-B of Module 1 as a guide.
- Answer
<assignment_statement> ->
ASSIGN VARIABLE TO <expression>
boolean assignmentStatement() {
if (token == ASSIGN) {
token = getNextToken();
if (token == VARIABLE) {
token == getNextToken();
if (token == TO) {
token == getNextToken();
if (expression()) {
return true;
}
}
}
}
return false;
}
** Week2 Grammar Restrictions for Recursive Descent Parse...
- Question
There are two restrictions on the type of grammars that c...
The second restriction is that the grammar must not requi...
- Answer
''The first is that the grammar cannot have any left recu...
A recursive descent parser is a kind of top-down parser. ...
For example, a simple LL(1) parser written in C is as fo...
int term ()
{
int d;
token(); /* look ahead a token */
switch(last_token) {
case '0': /* if last token is a numbe...
d = value; /* put the number to d */
token(); /* look ahead a token */
return d; /* return d */
}
}
By using term() above, a multiplying function is as below.
int mexpr()
{
int d;
d = term(); /* calculate term */
switch(last_token) { /* if last token */
case '*': /* is '*' */
d *= mexpr(); /* recurse mexpr() and the r...
return d; /* return d */
}
}
The grammar above can be expressed as "<mexpr> -> term * ...
int mexpr()
{
int d;
d = mexpr(); /* calculate mexpr. This is ...
switch(last_token) { /* if last token */
case '*': /* is '*' */
d *= term(); /* recurse mexpr() and the r...
return d; /* return d */
}
}
''The second restriction is that the grammar must not req...
The grammar requires only one token look ahead to prevent...
(a)
-> if exp then state |
if exp then state else state
(b)
-> if exp then state SD
-> else state | ε
LL(k) parsing (for k > 1) which requires two or more toke...
** Week2 Homework2 (6 points) [#wf16a810]
- Question
(Adapted from Sebasta (2012) Chapter 4 Problem 7)
Show a complete parse, including the parse stack contents...
- Answer
#ref(CMSC330_Homework2.pdf)
** Week3 Examining the Scope Rules of Java [#w4c14c05]
- Question
The scope rules of modern programming languages are roote...
Let's consider Java, a language with which everyone shoul...
One consequence of scope rules in most languages is that ...
- Answer
Here is my code.
public class ScopeRulesTest {
public static void main(String[] args) {
ScopeRulesTest scopeRulesTest = new ScopeRulesTe...
scopeRulesTest.legalSameNameVariables(false);
scopeRulesTest.legalForwardReferences();
scopeRulesTest.illegalForwardReferences();
}
/** Two local variables with same name exit in same ...
public void legalSameNameVariables(boolean b) {
boolean isTrue = b;
if (isTrue == true) {
int x = 1; // Adds 1 to local variable x.
System.out.println("x is " + x);
} else {
int x = 0; // Adds 0 to local variable x.
System.out.println("x is " + x);
}
}
/** Forward references are not always illegal. **/
public void legalForwardReferences() {
int x = y; // Adds global variable y to local va...
System.out.println("x is " + x);
}
private static int y = 1; // Defines static global v...
public void illegalForwardReferences() {
int y = x; // x is unresolved. You get a compile...
System.out.println("y is " + y);
}
}
** Week3 Pointers, References, and Object Allocation Stra...
- Question
The trend in newer languages is to replace explicit point...
Another related issue is whether the language allows obje...
- Answer
''The trend in newer languages is to replace explicit poi...
C/C++ and Ada can have pointer variables, which are calle...
On the other hand, Java, for example, doesn't have pointe...
From a perspective of program readability, I think that a...
''Another related issue is whether the language allows ob...
Java and C# support garbage collection, which automatical...
On the other hand, C++ and Ada don't support garbage coll...
Garbage collection is very convenient and it allows progr...
Therefore, using both stack and heap flexibly is important.
In C++ and C#, you can make structures by using struct op...
In conclusion, from a perspective of freedom to choose, I...
** Week3 Homework3 (6 points) [#r63ef949]
- Question
1. Scope and lifetime are distinct yet related issues in ...
class AnonymousInnerClassInMethod
{
public static void main(String[] args)
{
int local = 1;
Comparable compare = new Comparable ()
{
public int compareTo(Object value)
{
return (Integer)value - local;
}
};
System.out.println(compare.compareTo(5));
}
}
Why does this code fail to compile? What could it be modi...
2. C++ allows pointers to stack-dynamic variables. Consid...
int twice(int x)
{
int *y;
*y = x * 2;
return *y;
}
Will the above function compile in C++? Is it correct? If...
- Answer
#ref(CMSC330_Homework3.pdf)
** Week4 Operand Evaluation Order [#s1ae071e]
- Question
Although Java has the rule that the left operand of every...
** Week4 Should Indentation Have Semantic Significance? [...
- Question
Most modern programming languages are free format. Aside ...
** Week4 Project1 (25 points) [#gf5461d1]
- Question
The first programming project involves completing a progr...
gui ::=
Window STRING '(' NUMBER ',' NUMBER ')' layout widge...
layout ::=
Layout layout_type ':'
layout_type ::=
Flow |
Grid '(' NUMBER ',' NUMBER [',' NUMBER ',' NUMBER] ')'
widgets ::=
widget widgets |
widget
widget ::=
Button STRING ';' |
Group radio_buttons End ';' |
Label STRING ';' |
Panel layout widgets End ';' |
Textfield NUMBER ';'
radio_buttons ::=
radio_button radio_buttons |
radio_button
radio_button ::=
Radio STRING ';'
In the above grammar, the red symbols are nonterminals, t...
Below is an explanation of the meaning of some of the sym...
-- In the window production the string is name that is to...
-- In the production for layout_type that define the grid...
-- In the production for widget that defines a button, th...
-- In the production for widget that defines a label, the...
-- In the production for widget that defines a text field...
-- In the production for radio_button, the string is the ...
You parser should properly handle the fact that panels ca...
Below is an example of an input file:
Window "Calculator" (200, 200) Layout Flow:
TextField 20;
Panel Layout Grid(4, 3, 5, 5):
Button "7";
Button "8";
Button "9";
Button "4";
Button "5";
Button "6";
Button "1";
Button "2";
Button "3";
Label "";
Button "0";
End;
End.
The above input file should produce the GUI shown below:
- Answer
- GitHub Repository: https://github.com/yujishimojo/CMSC3...
-- InputFileAnalyzer.java
-- GUIGenerator.java
-- input.txt
** Week5 Parameter Passing [#lc00900d]
- Question
One characteristic of programming languages that varies w...
- Answer
I believe Ada is the best approach to parameter passing b...
** Week5 Nested Subprograms vs. Nested Blocks [#v302358b]
- Question
All the languages in the C family of languages allow nest...
What is the rationale for prohibiting nested subprograms?...
- Answer
Scopes of variables in if-statements, loop-statements, an...
This language specification strongly promotes standardiza...
I don't think all the programming languages should adopt ...
However, I agree with the idea in scripting languages inc...
** Week5 Homework4 (6 points) [#u07a7360]
- Question
1. What is the output of the following Java program? Expl...
import java.awt.*;
class PointParameters
{
public static void main(String [] args)
{
int x = 1, y = 1;
Point p = new Point(x, y), q = new Point(x, y);
doubleScale(x, y, p, q);
System.out.println( "(x,y) = " + new Point(x, y) +
" p = " + p + " q = " + q);
}
private static void doubleScale(int x, int y, Point ...
{
x *= 2;
y *= 2;
p.x *= 2;
p.y *= 2;
q = new Point(x, y);
}
}
Suppose a similar program were written in C# in which all...
2. Examine the following C++ program, in which a IntList ...
#include <iostream>
using name std;
class IntList
{
private:
int list[1];
public:
IntList() {list[0] = 0;}
int& operator[] (const int index) {return list[index...
};
int main()
{
IntList list;
cout << list[0] << endl;
list[0] = 1;
cout << list[0] << endl;
return 0;
}
Notice that the overloaded [] operator returns a referenc...
- Answer
#ref(CMSC330_Homework4.pdf)
** Week6 Separating the Specification and Implementation ...
- Question
One important difference between languages that provide s...
Compare Ada with both C++ and Java in this regard. Take a...
- Answer
** Week6 Type Parameterization [#cfc2de98]
- Question
Implementing type parameterization in Java was a much sim...
What about C#? Do some investigation and explore whether ...
- Answer
** Week6 Homework5 (6 points) [#h8702c8b]
- Question
1. Consider the following Java definition of a mutable st...
class MutableString
{
private char[] chars = new char[200];
private int size = 0;
public boolean set(char aChar, int index)
{
if (index < 0 || index >= chars.length)
return false;
chars[index] = aChar;
return true;
}
public String toString()
{
String result = "";
for (int i = 0; i < size; i++)
result += chars[i];
return result;
}
}
Suppose this class was rewritten in C++ in two ways, the ...
2. Consider the following C++ template class.
template <typename T, int length>
class Vector
{
public:
Vector(T values[length])
{
for (int i = 0; i < length; i++)
list[i] = values[i];
}
friend bool operator<(const Vector<T, length>& left,...
{
bool result = true;
for (int i = 0; i < length; i++)
result &= left.list[i] < right.list[i];
return result;
}
private:
T list[length];
};
int main()
{
int first[] = {1, 2}, second[] = {2, 3};
Vector<int, 2> vector1(first), vector2(second);
cout << (vector1 < vector2) << endl;
return 0;
}
The class Vector cannot be instantiated for any arbitrary...
class Int
{
public:
Int(int i = 0) {this->i = i;}
private:
int i;
};
int main()
{
Int first[] = {Int(1), Int(2)}, second[] = {Int(2), ...
Vector<Int, 2> vector1(first), vector2(second);
cout << (vector1 < vector2) << endl;
return 0;
}
Explain why the second implementation fails. What must be...
Java does have one limitation, however. Although wrapper ...
- Answer
#ref(CMSC330_Homework5.pdf)
** Week7 Homework6 (6 points) [#y82f4d4d]
- Answer
#ref(CMSC330_Homework6.pdf)
** Week8 Project2 (25 points) [#t8b6e442]
- Question
#ref(CMSC330_Project2_Specification.pdf)
#ref(CMSC330_Module3_Case_Study.pdf)
- GitHub Repository: https://github.com/yujishimojo/CMSC3...
-- C++ Header Files
-- C++ Source Files
- Test Case
#ref(CMSC330_TestCase(Project2).pdf)
** Flash Videos [#we1b3617]
*** Week1 Videos [#nd6fee56]
- [[Language Design - Part 1:http://nova.umuc.edu/~jarc/c...
- [[Language Design - Part 2:http://nova.umuc.edu/~jarc/c...
- [[Language Translators- Part 1:http://nova.umuc.edu/~ja...
- [[Language Translators- Part 2:http://nova.umuc.edu/~ja...
*** Week2 Videos [#d47cb272]
- [[Recursive Descent Parsing - Part 1:http://nova.umuc.e...
- [[Recursive Descent Parsing - Part 2:http://nova.umuc.e...
*** Week3 Videos [#ja08bda0]
- [[Scope, Visibility and Lifetime- Part 1:http://nova.um...
- [[Scope, Visibility and Lifetime- Part 2:http://nova.um...
- [[Memory Allocation- Part 1:http://nova.umuc.edu/~jarc/...
- [[Memory Allocation- Part 2:http://nova.umuc.edu/~jarc/...
*** Week4 Videos [#s8e9fe6a]
- [[Intermediate Code Generation - Part 1:http://nova.umu...
- [[Intermediate Code Generation - Part 2:http://nova.umu...
*** Week5 Videos [#n60d8132]
- [[Parameter Passing Techniques- Part 1:http://nova.umuc...
- [[Parameter Passing Techniques- Part 2:http://nova.umuc...
- [[Parameter Passing Techniques- Part 3:http://nova.umuc...
- [[Parameter Passing Techniques- Part 4:http://nova.umuc...
*** Week6 Videos [#a2b97092]
- [[Type Parameterization - Part 1:http://nova.umuc.edu/~...
- [[Type Parameterization - Part 2:http://nova.umuc.edu/~...
- [[Type Parameterization - Part 3:http://nova.umuc.edu/~...
- [[Type Parameterization - Part 4:http://nova.umuc.edu/~...
*** Week7 Videos [#c89a5a29]
- [[Uses of Inheritance - Part 1:http://nova.umuc.edu/~ja...
- [[Uses of Inheritance - Part 2:http://nova.umuc.edu/~ja...
*** Week8 Videos [#d1433b96]
- [[Competition Synchronization - Part 1:http://nova.umuc...
- [[Competition Synchronization - Part 2:http://nova.umuc...
ページ名: