CS153/hw6/hw5programs/sp22_tests/programs.oat
jmug ee01a8f5b2 Change hw6 to an unsolved version.
Signed-off-by: jmug <u.g.a.mariano@gmail.com>
2025-01-24 23:10:01 -08:00

62 lines
No EOL
1.4 KiB
Text

struct Entity {
int position;
int velocity;
int acceleration
}
struct George {
int position;
int velocity;
int acceleration;
int age
}
struct Aidan {
int position;
int velocity;
int acceleration;
int height
}
void print_entity(Entity e) {
print_string("position: ");
print_int(e.position);
print_string(" velocity: ");
print_int(e.velocity);
print_string(" acceleration: ");
print_int(e.acceleration);
print_string(" ");
return;
}
int program(int argc, string[] argv) {
var aidan = new Aidan {
position = -10;
velocity = 1;
acceleration = 2;
height = 4
};
var george = new George {
position = 0;
velocity = -1;
acceleration = 3;
age = 4
};
var entities = new Entity[]{aidan, george};
for (var time = 0; time < 100; time = time + 1;) {
for (var i = 0; i < length(entities); i = i + 1;) {
entities[i].velocity = entities[i].acceleration + entities[i].velocity;
entities[i].position = entities[i].position + entities[i].velocity;
}
}
print_string("Printing Aidan info! ");
print_entity(aidan);
print_string("height: ");
print_int(aidan.height);
print_string(" Printing George info! ");
print_entity(george);
print_string("age: ");
print_int(george.age);
print_string(" ");
return 0;
}