Homework 4

This commit is contained in:
Carlos Galindo 2020-01-15 22:34:57 +01:00
parent 0afc86ceeb
commit 72cc3206c4
Signed by: kauron
GPG key ID: 83E68706DEE119A3
125 changed files with 4200 additions and 1636 deletions

View 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;
}

View 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;
}
}

View 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;
}
}

View 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 {}

View 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;
}
}

View 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;
}