Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

ABAARSO TECH UNIVERSITY

DEGREE IN SOFTWARE ENGINEERING

Assignment: Mastering Dart Fundamentals

Instructions:

Implement solutions for the following 10 logic-based programming questions. Your


solutions should demonstrate your understanding of the key programming concepts listed
(boolean, conditionals, double, integer, loops, math, strings, variables, functions, lists,
classes, constructors, and inheritance).

1: Boolean and Conditional Statements: Leap Year

bool isLeapYear(int year) {


if (year % 4 == 0) {
if (year % 100 == 0) {
if (year % 400 == 0) {
return true;
} else {
return false;
}
} else {
return true;
}
} else {
return false;
}
}

2:Integers and Math Operations: GCD using Euclidean Algorithm

int gcd(int a, int b) {


while (b != 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}

3:Loops and Strings: Reverse String

String reverseString(String input) {


String reversed = '';
for (int i = input.length - 1; i >= 0; i--) {
reversed += input[i];
}
return reversed;
}

4:Variables and Functions: Average of List

double average(List<int> numbers) {


int sum = 0;
for (int number in numbers) {
sum += number;
}
return sum / numbers.length;
}

5:Conditional Statements and Loops: Fibonacci Numbers

List<int> evenFibonacciNumbers(int count) {


List<int> fib = [0, 1];
while (fib.length < count) {
fib.add(fib[fib.length - 1] + fib[fib.length - 2]);
}
List<int> evenFibs = [];
for (int number in fib) {
if (number % 2 == 0) {
evenFibs.add(number);
}
}
return evenFibs;
}

6: Double and Math Operations: Area and Circumference of Circle

Map<String, double> circleProperties(double radius) {


double area = 3.14159 * radius * radius;
double circumference = 2 * 3.14159 * radius;
return {'area': area, 'circumference': circumference};
}

7: and Lists: Unique Elements in List

List<int> uniqueElements(List<int> numbers) {


Set<int> uniqueSet = numbers.toSet();
return uniqueSet.toList();
}

8: Classes and Constructors: Bank Account Class

class BankAccount {
String accountNumber;
double balance;
String ownerName;

BankAccount(this.accountNumber, this.balance, this.ownerName);

void deposit(double amount) {


balance += amount;
}

void withdraw(double amount) {


if (amount <= balance) {
balance -= amount;
} else {
print('Insufficient funds');
}
}
double checkBalance() {
return balance;
}
}

9: Inheritance: Savings Account Class

class SavingsAccount extends BankAccount {


double interestRate;

SavingsAccount(String accountNumber, double balance, String ownerName,


this.interestRate)
: super(accountNumber, balance, ownerName);

double calculateMonthlyInterest() {
return balance * (interestRate / 12);
}
}

10: Variables and Conditionals: Anagram Check

bool isAnagram(String word1, String word2) {


if (word1.length != word2.length) return false;

List<int> count1 = List.filled(26, 0);


List<int> count2 = List.filled(26, 0);

for (int i = 0; i < word1.length; i++) {


count1[word1.codeUnitAt(i) - 'a'.codeUnitAt(0)]++;
count2[word2.codeUnitAt(i) - 'a'.codeUnitAt(0)]++;
}

for (int i = 0; i < 26; i++) {


if (count1[i] != count2[i]) return false;
}

return true;

You might also like