You are on page 1of 2

Mid Term Exam

(Lab)

Total Marks: 100 Time: 120 min

Instructions: Please provide answers to the following questions and


include Dart code to illustrate your explanations:

Questions
1. Write a Dart function named calculateSum that takes two integers
as input and returns their sum.
2. Complete the following Dart code to print the numbers from 1 to 10
using a loop:

void main() {
for (int i = 1; i <= 10; i++) {
print(i);
// Write your code here
}
}

3. Write a Dart class named Rectangle with the following properties:


● Width (double)
● Height (double)
Implement a method named calculateArea that calculates and
returns the area of the rectangle.
4. What is polymorphism? How can it be used to achieve code
reusability and flexibility?
5. Modify the existing Dart code to implement a function named isOdd
that takes an integer as input and returns true if the number is odd,
and false otherwise.

bool isOdd(int number) {


// Write your code here
}

void main() {
int num = 7;
bool result = isOdd(num);

This document is the intellectual property of Hazza Institute of Technology, Lahore that can only be
used for particular training purposes. This material may not be quoted, photocopied, reproduced in
any form without the prior written consent of Hazza Institute of Technology.
print(result);
}

This document is the intellectual property of Hazza Institute of Technology, Lahore that can only be
used for particular training purposes. This material may not be quoted, photocopied, reproduced in
any form without the prior written consent of Hazza Institute of Technology.

You might also like