-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsample_program.cmm
50 lines (39 loc) · 1.03 KB
/
sample_program.cmm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
types {
struct {
int x;
int y;
} pos;
}
functions {
int getPosition(int initialPosition; int velocity; int time;);
} implementation {
# St = S0 + v * t
int getPosition(int initialPosition; int velocity; int time;) {
return initialPosition + velocity * time;
}
}
main {
int positionsX[256];
pos currentPosition;
int time = 0;
int velocityX;
int velocityY = 1;
currentPosition.x = 0;
currentPosition.y = 0;
print("Please type a velocity for the X axys: ");
read(velocityX);
# Calculate the position during 60 seconds
while (time <= 60) {
currentPosition.x = getPosition(currentPosition.x, velocityX, time);
currentPosition.y = getPosition(currentPosition.y, velocityY, time);
positionsX[time] = currentPosition.x;
# Print the updated time and position every 5 seconds
if (time % 5 == 0) {
print("\nTime: ");
print(time);
print("\nPosition: ");
print(currentPosition.x);
}
time = time + 1;
}
}