0% found this document useful (0 votes)
7 views6 pages

Midterm 1

Uploaded by

ibnhebesha
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 (0 votes)
7 views6 pages

Midterm 1

Uploaded by

ibnhebesha
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/ 6

Midterm 1

Midterm 1
Q1
1. What is the output of this code? 1 point

void main() {
var lInts = [1, 2, 3];
var lis = ['#0',for (var i in lInts)'#$i'];
assert(lis[1] == '#1');
}

Answer: No output because there's not print statements

2. Write dart function print the Fibonacci number? 1.5 point


Answer:

void main() {
for (int i = 0; i < 10; i++) {
print(fibonacci(i));
}
}

int fibonacci(int n) {
if (n <= 1) return n;
return fibonacci(n - 1) + fibonacci(n - 2);
}

3. Function that ask the user for a number and determine whether the number
is prime or not. 1.5 point
Answer:

import 'dart:io';

void main() {
stdout.write('Enter a number: ');
int number = int.parse(stdin.readLineSync()!);
if (isPrime(number)) {
print('$number is a prime number');

1/6
Midterm 1

} else {
print('$number is not a prime number');
}
}

bool isPrime(int n) {
if (n <= 1) return false;
for (int i = 2; i <= n ~/ 2; i++) {
if (n % i == 0) return false;
}
return true;
}

4. write code Flutter implements How to update text in Button when click? 3
point
Answer:

import 'package:flutter/material.dart';

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {


@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: Text('Welcome'),
),
body: Center(
child: ClickCounter(),
),
),
);
}
}

class ClickCounter extends StatefulWidget {


@override
_ClickCounterState createState() => _ClickCounterState();
}

2/6
Midterm 1

class _ClickCounterState extends State<ClickCounter> {


int _clickCount = 0;

void _incrementCounter() {
setState(() {
_clickCount++;
});
}

@override
Widget build(BuildContext context) {
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
'Clicked $_clickCount times',
style: TextStyle(fontSize: 24),
),
SizedBox(height: 20),
ElevatedButton(
onPressed: _incrementCounter,
child: Text('Click me!'),
),
],
);
}
}

Q2: Answer the following questions? 8 point

1. What is Dart?
a. Dart is a object-oriented programming language
b. Dart is used to create a frontend user interfaces
c. Both of the above
d. None of the above

2. What will be the output of this program: void main() { int num;
print(num);}
a. Error
b. Null

3/6
Midterm 1

c. Num
d. None of these

3. Which framework uses dart?


a. Python
b. Java
c. Flutter
d. React

4. Dart is an ...........
a. Open-source
b. Asynchronous
c. Programming language
d. All of the above

5. Dart is originally developed by ...........


a. Microsoft
b. Google
c. IBM
d. main()

6. The ........... function is a predefined method in Dart


a. declare()
b. list()
c. main()
d. return()

7. Dart is an Object-Oriented language


a. Yes
b. No

8. ........... is a real-time representation of any entity


a. Class
b. Method
c. Object
d. None of the above

4/6
Midterm 1

9. What is the extension of Dart file?


a. .dart
b. .py
c. .java
d. .drt

10. Which of the following statements does not use string interpolation correctly?
a. print('Your name in upper case is $"me".toUpperCase');
b. print("Your name in upper case is ${'me'.toUpperCase()}");
c. print('Your name in upper case is ${"me".toUpperCase()}');

11. Which keyword in Dart is used to create a subclass?


a. extends
b. subclass
c. super
d. none of these

12. Instance variables in Dart cannon be ...........


a. final
b. const
c. Both of these
d. none of these

13. split method in Dart takes ...........


a. one argument
b. two arguments
c. multiple arguments
d. user defined multiple arguments

14. ........... commonly known as a dictionary or hash


a. set
b. list
c. map
d. none of these

15. Dart is a case sensitive programming language


a. Yes
5/6
Midterm 1

b. No

6/6

You might also like