0% found this document useful (1 vote)
362 views

CUATL

Learn about cautl

Uploaded by

Muhammad Salman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (1 vote)
362 views

CUATL

Learn about cautl

Uploaded by

Muhammad Salman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

‭The Chester University Aptitude Test Language (CUATL)‬

‭ or your aptitude test you’ll be asked to use a simple, new programming language called‬
F
‭CUATL, which contains only a few features compared to more commonly used languages‬
‭such as C++ or Python. This document contains everything you need to know about the‬
‭language before you take your test. You can check your knowledge by attempting the‬
‭sample questions at the end.‬

‭Datatypes‬

‭‬ C
● ‭ UATL has only two datatypes‬‭.‬‭These are‬‭integers‬‭and‬‭lists‬‭of integers.‬
‭●‬ ‭Integers are always declared with a single letter such as‬‭x‭,‬‬‭y‭,‬‬‭z‬‭,‬‭a‭,‬‬‭b‬‭,‬‭c‬‭etc.‬
‭●‬ ‭Lists are always declared by adding‬‭s‬‭to a variable‬‭name, such as‬‭xs‬‭,‬‭ys‬‭etc.‬
‭○‬ ‭We can define a list with the - operator, so we might create a list called‬‭xs‬
‭with the literal value 1-2-3-4, for example‬
‭○‬ ‭Values can be added to the end of a list with the <- operator, e.g.‬
‭■‬ ‭xs <- 5‬
‭■‬ ‭so 1-2-3 <- 4 is 1-2-3-4‬
‭○‬ ‭We index lists using integers, eg xs1, xs2, xsi‬
‭○‬ ‭Indexes begin at 1, not zero‬
‭■‬ ‭So if xs is 3-4-5 then xs1 is 3 and xs2 is 4‬

‭Operators‬

‭Some of the operators in CUATL are different from most languages.‬

‭●‬ F ‭ or arithmetic, we use‬‭pl‬‭,‬‭mi‬‭,‬‭mu‬‭and‬‭dv‬‭instead of‬‭+, -, * and / for addition,‬


‭subtraction, multiplication and division respectively.‬
‭●‬ ‭We can also use‬‭rm‬‭for the modulus operator (% in‬‭most languages)‬
‭●‬ ‭Values are assigned using an operator which looks like equals but isn’t. It is typed‬
‭like this ::: (exactly three colons).‬
‭●‬ ‭We can use the relational operators <, > and == as in most languages, and they‬
‭return the value 1 or 0 (as there are no booleans in CUATL).‬

‭Control Structures‬

‭ here is only one kind of loop, which is a for-each style loop iterating over a list. It uses the‬
T
‭syntax‬‭ over(xs)‬‭and will iterate over each value in‬‭the xs list, referring to each element as x‬
‭in this case. There are no do or while loops. Scope is defined by the braces { and } as in C++‬
‭and Java. A simple example might be:‬

‭ver(xs)‬
o
{‬

x ::: 0‬

}‬

‭This would set every element of xs to 0‬


‭There is no if or switch statement in CUATL but we can use conditionals in the following form‬

x ::: y < 5 ? y , 0‬

‭This will assign x the value of y if y is less than 5 and 0 otherwise.‬

‭Functions‬

I‭n addition, we may define functions. Function names always begin with the word ‘do’, apart‬
‭from ‘main’, which serves its usual purpose. They may accept parameters in round brackets‬
‭and return an integer or nothing at all. We return a value by putting it in quotes. The following‬
‭example returns the value t, which is the sum of the elements of the list xs.‬

‭ oSum(xs)‬
d
‭{‬
‭t ::: 0‬
‭over(xs)‬
‭{‬
‭t ::: t pl x‬
‭}‬
‭“t”‬
‭}‬

‭As a final note, there are no semicolons in CUATL. A statement must occupy a single line.‬

‭Practice Questions‬

‭ ave a go at these questions to make sure you’ve understood how the language works‬
H
‭before you take your test. The answers are at the end of the document.‬

‭Question 1:‬

‭What is the value assigned to y by the following‬‭code?‬

‭ain()‬
m
{‬

x ::: 10‬

x ::: 11‬

y ::: x rm 3‬

}‬

‭Question 2:‬

‭Give the value assigned to q by the following code‬

main()‬

{‬

‭s ::: 1-11-5-2-4‬
x
b ::: xs2 mi xs3‬

q ::: b dv xs4‬

}‬

‭Question 3:‬

‭What is the value assigned to z in the following code?‬

‭ain()‬
m
{‬

xs ::: 1-1-1-1‬

over(xs)‬

{‬

x ::: x pl 2‬

}‬

z ::: xs4 mu 2‬

}‬

‭Question 4:‬

‭Consider the following code‬

‭oMysteryThings(xs, n)‬
d
{‬

c ::: 0‬

t ::: 0‬

over(xs)‬

{‬

t ::: c < n ? t pl x , t‬

c ::: c pl 1‬

}‬

“t”‬

}‬

‭ain()‬
m
{‬

ys ::: 1-2-3-4-5-6-7-8-23-65‬

f ::: doMysteryThings(ys,4)‬

}‬

‭What is the value assigned to f?‬


‭Answers:‬

‭1.‬ y ‭ is 2. x is overwritten in the second line to the value 11. The modulus operation‬
‭gives the remainder after dividing 11 by 3, which is 2.‬
‭2.‬ ‭q is 3. The value of b is assigned to 6. This is then divided by 2.‬
‭3.‬ ‭z is 6. All elements are 3 once the loop has completed. The last element is then‬
‭multiplied by 2 to obtain z.‬
‭4.‬ ‭f is 10. The function stops adding elements to the total after 4 iterations.‬

You might also like