Homework 4
This commit is contained in:
parent
0afc86ceeb
commit
72cc3206c4
125 changed files with 4200 additions and 1636 deletions
22
javali_tests/HW4_nop90/method invocation/OkCallByValue.javali
Executable file
22
javali_tests/HW4_nop90/method invocation/OkCallByValue.javali
Executable file
|
@ -0,0 +1,22 @@
|
|||
// test that call-by-value is used
|
||||
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int x;
|
||||
A a;
|
||||
a = new A();
|
||||
a.a = 50;
|
||||
aux(a.a);
|
||||
x = a.a;
|
||||
write(x);
|
||||
}
|
||||
|
||||
void aux (int arg){
|
||||
arg = arg + 1;
|
||||
}
|
||||
}
|
||||
|
||||
class A {
|
||||
int a;
|
||||
}
|
18
javali_tests/HW4_nop90/method invocation/OkCallByValue2.javali
Executable file
18
javali_tests/HW4_nop90/method invocation/OkCallByValue2.javali
Executable file
|
@ -0,0 +1,18 @@
|
|||
// test that call-by-value is used
|
||||
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int[] y;
|
||||
int x;
|
||||
y = new int[5];
|
||||
y[2] = 50;
|
||||
aux(y[2]);
|
||||
x = y[2];
|
||||
write(x);
|
||||
}
|
||||
|
||||
void aux (int arg){
|
||||
arg = arg + 1;
|
||||
}
|
||||
}
|
18
javali_tests/HW4_nop90/method invocation/OkCallByValue3.javali
Executable file
18
javali_tests/HW4_nop90/method invocation/OkCallByValue3.javali
Executable file
|
@ -0,0 +1,18 @@
|
|||
// test that call-by-value is used
|
||||
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int[] y;
|
||||
int x;
|
||||
y = new int[5];
|
||||
y[2] = 50;
|
||||
aux(y);
|
||||
x = y[2];
|
||||
write(x);
|
||||
}
|
||||
|
||||
void aux (int[] arg){
|
||||
arg[2] = 100;
|
||||
}
|
||||
}
|
17
javali_tests/HW4_nop90/method invocation/OkCallInheritedMethod.javali
Executable file
17
javali_tests/HW4_nop90/method invocation/OkCallInheritedMethod.javali
Executable file
|
@ -0,0 +1,17 @@
|
|||
// call an method from a superclass
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
C2 c;
|
||||
c = new C2();
|
||||
c.aux();
|
||||
}
|
||||
}
|
||||
|
||||
class C1{
|
||||
void aux(){
|
||||
write(2);
|
||||
}
|
||||
}
|
||||
|
||||
class C2 extends C1 {}
|
19
javali_tests/HW4_nop90/method invocation/OkMethod.javali
Executable file
19
javali_tests/HW4_nop90/method invocation/OkMethod.javali
Executable file
|
@ -0,0 +1,19 @@
|
|||
// call a simple method and use its return value
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int a,b;
|
||||
C c;
|
||||
c = new C();
|
||||
a = 5;
|
||||
b = c.aux(a);
|
||||
}
|
||||
}
|
||||
|
||||
class C{
|
||||
int aux(int arg){
|
||||
return arg*2;
|
||||
}
|
||||
}
|
||||
|
||||
|
35
javali_tests/HW4_nop90/method invocation/OkMethod2.javali
Executable file
35
javali_tests/HW4_nop90/method invocation/OkMethod2.javali
Executable file
|
@ -0,0 +1,35 @@
|
|||
// call a method with many parameters and use its return value
|
||||
// also Test Register use, by allocating memory
|
||||
|
||||
class Main {
|
||||
void main() {
|
||||
int a,b,c,d,e,f,g,h,x;
|
||||
a = 5;
|
||||
b = 5;
|
||||
c = 5;
|
||||
d = 5;
|
||||
e = 5;
|
||||
f = 5;
|
||||
g = 5;
|
||||
h = 5;
|
||||
|
||||
x = aux(a,b,c,d,e,f,g,h);
|
||||
|
||||
}
|
||||
|
||||
int aux(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8){
|
||||
int[] x;
|
||||
int i;
|
||||
D d;
|
||||
x = new int[20];
|
||||
i = arg1 + arg2 + arg3 + arg4 - arg5 - arg6 + arg7 - arg8;
|
||||
d = new D();
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
class D{
|
||||
int[] x;
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue