Lab 5
Lab 5
Abbottabad Campus
Department of Computer Science
Lab 5 Tasks
1. Write an example of function definition and function call with named parameters.
Code:
void main() {
test(name: "Safa", age: 25, city: "Karachi");
test(name: "Ali", city: "Lahore");
test(name: "Aisha", age: 30);
}
Output:
2. Write arrow functions for the following equations:
2 4
A=a +b
2
Z= p +5 t+ A
Code:
void main() {
double a = 2;
double b = 3;
double p = 4;
double t = 1;
print("A: $A");
print("Z: $Z");
}
Output:
3. Write arrow functions for the following equations:
2
A=x +2 xy + p . Z
Z = a 2 + 4.B2 – 8b + 2a
2
B=n + qn+1
Code:
void main() {
double x = 3;
double y = 2;
double p = 1.5;
double a = 2;
double b = 4;
double n = 5;
double q = 1;
print("B: $B");
print("Z: $Z");
print("A: $A");
}
Output:
Code:
void main() {
double x = 3;
double y = 2;
double p = 1;
double q = 2;
Output:
5. Given the following list: ['apples', 'bananas', 'oranges'];
Append a string with each element of the list and capitalize each element of list. Use a
combination of map and forEach function.
Code:
void main() {
modifiedhome.forEach((item) {
print(item);
});
}
Output:
void main(){
Output:
void main() {
List<Map<String, String>> myArray = [
{'name': 'ali', 'age': '45'},
{'name': 'noman', 'age': '34'},
];
print("\nValues only:");
myArray.forEach((element) {
element.values.forEach((value) {
print(value);
});
});
}
Output:
8. Suppose we have the following arrays:
var myArray1 = [3, 4, 5]
var myArray2 = [6, 7, 8]
Write code to append the myArray2 into myArray1.
Code:
void main() {
var myArray1 = [3, 4, 5];
var myArray2 = [6, 7, 8];
var combinedArray = [...myArray1, ...myArray2];
print(combinedArray);
}
Output:
void main() {
var outerFunction = (int x) => (int y) {
var innerFunction = (int z) => x + y + z;
return innerFunction;
};
Output: