The aim for this tutorial is to get students to understand why we are studying programming language principles, types, structuring concepts and expressions.
1. Why do you think that object-oriented languages such as Smalltalk, C++ and Java are becoming the most popular new languages?
2. Explain the relationship between types and sets.
3. Analyse the types and expressions in C++ and answer the following:
(a) What is the set of values of each of the primitive types and what is its cardinality? (b) Can recursive types be defined? If so, how?
4. Examine the following program. Assume dynamic type checking. At which lines in the program will a type mismatch error be generated (assume execution begins in main and if a type error occurs the resulting test fails, that is evaluates to false, but execution continues)?
line# zoo() { 1 if (variable < 10) 2 variable = 4; else 3 variable = "harry"; return variable; } main() { 4 variable = "joe"; 5 if (zoo() < 23)) print "success!"; }
5. What is the conditional expression in C? What is the conditional command in C? Are two conditionals really needed?
6. Show the lifetimes of the variables in the following C program and indicate which are statically vs. dynamically allocated.
int m; void S () { float z; z = 1.0; } void R (int n) { if (n 0) R(n-1); S(); } int main() { m = 3; R(1); return 1; }
Note that R will be activated twice, recursively.
7. In the following C program skeleton, identify all the name spaces by stating to which name space each name belongs. Also indicate the scope of each name. Note, C has static scoping.
int x, y, z; int zoo() { { int x; } } zoo2(int x) { int y; } main() { int y; }
8. Can you explain what is wrong with the following C program in terms of name-spaces and scopes? What about if Pascal had dynamic scoping?
void zoo() { }; void zoo() { }; void main() { zoo(); };
9. In terms of name spaces and scopes, is the difference between variable x and variable y in the following C program?
int x; void zoo(int y) { }; void main() { zoo(x); };
10. Identify all the kinds of declarations in the following C program.
int x; typedef int shortInt; int zoo(int z, int *q) { int y; return z + *q; } void main() { }
11. Using the following C program discuss what bindings exist in the environments (global environment, main environment, foo environment) at various points in the code. Note that C has static binding or scoping.
int x; char hello; int zoo(int z, int q) { int y; return z + q; } void main() { int y[30]; char *str; str = "hello"; y[1] = zoo(23, 34); str = "good-bye"; }
13. Does C have multiple assignment? Does it have collateral assignment?
14. Write C program generated a weight conversion table using Command Line Argument to enter the desired weight in pounds. Hint: the ratio of kilo/pound = 0.45359.