Uploaded by Disintegrated Being

ADO Week 6 Mock Exam

advertisement
Mock Test ADO – Week 6
Duration: 80 minutes.
Allowed materials: Only a pen.
Question
Maximum
points
1
1
2
1
3
1
4
3
5
1
6
1
7
1
8
1
9
2
10
2
11
2
1. What is the value of variable c after running this piece of code?
int a = 2;
int b = 4;
int c = a / b + b * b;
2. What is the value of variable p after running this piece of code?
int m = 10;
int n = 2;
int p = m * n;
p--;
3. What is the value of variable sum after running this piece of code?
string nr1 = "321";
int nr2 = 123;
string sum = nr1 + nr2;
12
4
Total
20
4. What are the values of variable x, y and z after running this piece of code?
int x = 123;
int y = 10;
int z;
x += y;
z = x / y;
5. What is the value of variable finalPrice after running this piece of code?
If the code cannot be executed, explain why.
int percent = 5;
double price = 99.99,
int reduction = price / percent;
double finalPrice = price - reduction;
6. What is the value of variable d after running this piece of code?
int
int
int
int
int
givenNumber = 163;
a = givenNumber / 100;
b = givenNumber / 10 % 10;
c = givenNumber % 10;
d = a + b + c;
7. What is the value of variable receiptTotal after running this piece of code?
If the code cannot be executed, explain why.
double pricePerKilo = 12.5;
double amount = 10;
string receiptTotal = pricePerKilo * amount;
8. What is the message that the user will receive in a MessageBox after running this piece of
code, if the user types 2020 in the textbox tbGivenYear?
int year = Convert.ToInt32(tbGivenYear.Text);
if (year % 400==0 || (year % 4==0 && year % 100!=0))
{
MessageBox.Show("yes, year " + year);
}
else
{
MessageBox.Show(("no, year " + year);
}
9. What is the value of variable n after running this piece of code, if the user types 5 in the
textbox tbNumber and 100 in the textbox tbLimit?
int n = Convert.ToInt32(tbNumber.Text);
int limit = Convert.ToInt32(tbLimit.Text);
while(n < limit)
{
n *= n;
}
10. What is the value of variable finalPrice after running this piece of code, if the user types 31
in the textbox tbAge?
int age = Convert.ToInt32(tbAge.Text);
double finalPrice = 100;
if (age < 18)
{
if (age > 50)
{
finalPrice -= 10;
}
}
else
{
finalPrice -= 20;
}
11. What is the value of variable sum after running this piece of code?
int limit = 5;
int sum = 0;
for (int i = 0; i < 5; i++)
{
sum += i + 1;
sum += limit - i;
}
12. We have the following definitions of methods:
public int getAnswer ( int p, int q )
{
if ( q > 10 ) { return p; }
else { return p + q ; }
}
public String getAnswerToo ( String p, int q)
{
if ( q > 10 ) { return p; }
else { return p + q ; }
}
What are then the values of variables answer1, answer2, answer3 and answer4 after
running this piece of code?
int answer1 = 5;
answer1 = getAnswer ( 6, 7) + getAnswer (10, 20);
int answer2 = 5;
answer2 = getAnswer( getAnswer ( 6, 7) , 10);
String answer3 = "heyo";
answer3 = getAnswerToo( answer3, 7);
String answer4 = "heyo";
answer4 = getAnswerToo(getAnswerToo( answer4, 2),3);
End of test.
Download