You are on page 1of 5

Exam

Exercise1
Write a program that prompts the user to input an integer and then outputs the number with
the digits reversed. For example, if the input is 12345, the output should be 54321.

import 'dart:io';
import 'dart:convert';
void main() {
print("Enter your number");
var number = int.parse(stdin.readLineSync().toString());
var Reuslt=ReverseNumber(number);
print("the result is $Reuslt");
}

int? ReverseNumber (int? num){


String str=num.toString();
var x=str.split('').reversed.join();
x=x.toString();
var retI=int.parse(x);
return retI;
}

Exercise2
Write a Dart function which will take an array of numbers stored and find the second lowest
and second greatest numbers, respectively. Sample array : [7,2,10,41,35]

Expected Output : 7,35

import 'dart:io';
import 'dart:convert';
void main() {
var mylist2=[54,66,78,2,3,100];
maxSec(mylist2);
}

void maxSec (var mylist){


mylist.sort();
print("min 2nd is ${mylist[1]} while the max 2nd is ${mylist[mylist.length-2]}");
}
Exercise 3
The class "Point" is defined as follows:
class Point {
int _x, _y;
Point(this._x, this._y);
void move(int mx, int my) {
_x += mx;
_y += my;
}
void display() {
print("x = $_x y = $_y");
}}

1. Define a new class "PointCol" to manipulate colored points. This class is


a derived from Point.
2. Its constructor initializes the color of the object with a given integer
(the color reference).
3. Add a method "printColor" that print the color.
4. Create a small test program (main).
B. import 'dart:io';
import 'dart:convert';
void main() {
PointCol pointCol = PointCol(12, 7,5);
pointCol.printColor();
}

class Point {
int _x, _y;
Point(this._x, this._y);
void move(int mx, int my) {
_x += mx;
_y += my;
}
void display() {
print("x = $_x y = $_y");
}}
class PointCol extends Point {
int? Color_reference;

PointCol(int x, int y,int Color_reference) : super(x, y){


this.Color_reference=Color_reference;
}

void printColor (){


print("the required color is corresponding to reference number $
{this.Color_reference}");
}
}

Exercise 4
1. Create a class called BankClient that have 3 private attributes :

C. ID which is generated automatically and represents the order of the client in the bank
Data Base (starting from 1 and can't be changed).
D. Name (can't be changed).
E. Balance have 3 methods (get, add, subtractIfPossible).

2. Create a constructor that use "Initializer list" to initialize the name.


3. Create a static method that print the number of clients and the bank balance.
4. Create a small test program (main) .
Note The balance is initialized at 0 and can't be negative.
import 'dart:io';
import 'dart:convert';
void main() {
Bankclient bankclient=Bankclient("mohamed nader");
bankclient.addBalance(12345);
Bankclient.dispBalName();

class Bankclient{
int? _Id;
String? _Name;
double? _Balance;
static List namesList=[];
static List<double> BalanceList=[];
static List IdList=[];
Bankclient(String names){
_Name=names;
namesList.add(names);
}
double addBalance(double amount) {
double bal=amount;
BalanceList.add(bal);
return bal;
}
double getBalance() {
return _Balance!;
}
dynamic subtractIfPossible(double amount){
if(_Balance!>amount){
double bal =_Balance!-amount;
return bal;
}
else{
return "error!";
}
}
static void dispBalName() {
var sum=0.0;
BalanceList.forEach((ele) => sum += ele);
print("the number of clients is ${namesList.length} and the balance is ${sum}");
}
}

Exercise 5
1-Dart MCQs

1. Dart is an?

A. open-source
B. general-purpose
C. programming language
D. All of the above

2. Dart is originally developed by?

A. Microsoft
B. Google
C. IBM
D. Facebook

3. Dart has multiple interfaces.

A. TRUE
B. FALSE
C. Can be true or false
D. Can not say

4. The _______ function is a predefined method in Dart.

A. declare()
B. list()
C. main()
D. return()

5. --version command is used to ?

A. Enables assertions
B. Displays VM version information
C. Specifies the path
D. Specifies where to find imported libraries

6. Dart is an Object-Oriented language.

A. Yes
B. No
C. Can be yes or no
D. Can not say

2- What is pub in Dart?


Pub is the package manager for the Dart programming language, containing reusable libraries &
packages for Flutter, AngularDart, and general Dart programs.

You might also like