0% found this document useful (0 votes)
12 views4 pages

MaD LAB Task 4

Uploaded by

abid khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

MaD LAB Task 4

Uploaded by

abid khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

MAD LAB Task 4

Name: Muhammad Abdullah Khan


Reg#: FA21-BCS-107

void main() {

// Task 1: Function definition and call with named parameters

print(calculateArea(length: 10, width: 5));

// Task 2: Arrow functions for the given equations

var A1 = (a, b) => a * a + b * b * b * b;

var Z1 = (p, t, A) => p * p + 5 * t + A1(p, t);

print("Equation Z1 result: ${Z1(2, 3, 5)}");


// Task 3: Arrow functions for another set of equations

var A2 = (x, y, p, Z) => x * x + 2 * x * y + p * Z;

var Z2 = (a, b) => a * a + 4 * b * b - 8 * b + 2 * a;

var B = (n, q) => n * n + q * n + 1;

print("Equation Z2 result: ${Z2(1, 2)}");

// Task 4: Nested arrow function

var Z3 = (x, y, p, q) {

var N = (p, q) => p * p + q * q;

return x * x + 4 * y * y - 8 * N(p, q);

};

print("Nested equation Z result: ${Z3(1, 2, 2, 3)}");

// Task 5: List manipulation

var fruits = ['apples', 'bananas', 'oranges'];

fruits = fruits.map((fruit) => fruit.toUpperCase() + " is tasty").toList();

fruits.forEach(print);

// Task 6: Calculator using typedef functions

typedef MathOperation = int Function(int, int);

MathOperation add = (a, b) => a + b;

MathOperation subtract = (a, b) => a - b;

MathOperation multiply = (a, b) => a * b;

MathOperation divide = (a, b) => a ~/ b;

print("Add: ${add(10, 5)} Subtract: ${subtract(10, 5)}");

// Task 7: Display key-value pairs of array

List<Map<String, String>> myArray = [


{'name': 'Ali', 'age': '45'},

{'name': 'Noman', 'age': '34'},

];

myArray.forEach((element) => element.forEach((key, value) =>


print("$key: $value")));

// Task 8: Append myArray2 into myArray1

var myArray1 = [3, 4, 5];

var myArray2 = [6, 7, 8];

myArray1.addAll(myArray2);

print("Merged Array: $myArray1");

// Task 9: Arrow function within another arrow function

var nestedFunc = (a, b) => (c) => a + b + c;

print("Nested function result: ${nestedFunc(2, 3)(4)}");

// Task 10: Filter and print objects based on conditions

List<Student> myObjects = [

Student(name: 'Alice', age: 25, marks: 55),

Student(name: 'Bob', age: 30, marks: 50),

Student(name: 'Alice', age: 27, marks: 40),

Student(name: 'Charlie', age: 22, marks: 45),

];

myObjects.where((s) => s.age > 25 && s.marks >= 50 && (s.name ==


'Alice' || s.name == 'Bob')).forEach(print);

// Task 11: Filter and print objects with different conditions

List<Student> myOtherObjects = [

Student(name: 'Ali', age: 45, marks: 32),

Student(name: 'Faisal', age: 41, marks: 43),


Student(name: 'Noman', age: 11, marks: 43),

Student(name: 'Faisal', age: 8, marks: 43),

];

myOtherObjects.where((s) => s.age > 30 && (s.name == 'Noman' ||


s.name == 'Faisal')).forEach(print);

// Function for task 1

int calculateArea({required int length, required int width}) {

return length * width;

// Student class for tasks 10 and 11

class Student {

String name;

int age;

int marks;

Student({required this.name, required this.age, required this.marks});

@override

String toString() {

return 'Name: $name, Age: $age, Marks: $marks';

You might also like