Skip to content

Compozent/Dart-Programming

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dart Programming Worksheet

This worksheet includes questions on Dart programming concepts, starting from basic syntax to intermediate and advanced levels.


Basic Questions

1. Print a Message

Write a Dart program that prints:

Hello, Dart! Welcome to Programming.

Expected Output:

Hello, Dart! Welcome to Programming.

2. Simple Arithmetic Operations

Write a Dart program to perform and print the following operations on two numbers a and b:

  • Sum
  • Difference
  • Product
  • Quotient

Assign a = 10 and b = 5.

Expected Output:

Sum: 15  
Difference: 5  
Product: 50  
Quotient: 2.0

3. Check Odd or Even

Write a Dart program to check if a given number is odd or even.

  • Define a variable num = 11.
  • Print "Even" if the number is even.
  • Print "Odd" if the number is odd.

Expected Output:

The number is Odd.

Intermediate Questions

4. Simple Calculator Using Functions

Write a Dart program to perform addition, subtraction, multiplication, and division using functions.

  • Use two inputs a = 8 and b = 4.
  • Create separate functions for each operation.

Expected Output:

Addition: 12  
Subtraction: 4  
Multiplication: 32  
Division: 2.0

5. Fibonacci Series

Write a Dart program to print the first 10 terms of the Fibonacci series.
The Fibonacci series starts with 0 and 1.

Expected Output:

Fibonacci Series:  
0 1 1 2 3 5 8 13 21 34

6. Working with Lists

Write a Dart program to:

  1. Create a list of integers: [5, 3, 8, 1, 2].
  2. Add the number 7 to the list.
  3. Sort the list in ascending order.
  4. Print the sorted list.

Expected Output:

Sorted List: [1, 2, 3, 5, 7, 8]

7. Working with Sets

Write a Dart program to:

  1. Create a set of unique integers: {1, 2, 3, 4}.
  2. Add a new number 5 to the set.
  3. Remove the number 2 from the set.
  4. Print the final set.

Expected Output:

Final Set: {1, 3, 4, 5}

8. Working with Maps

Write a Dart program to:

  1. Create a map with the following key-value pairs: {'name': 'Alice', 'age': 25, 'city': 'New York'}.
  2. Add a new key-value pair: 'country': 'USA'.
  3. Update the value of 'age' to 26.
  4. Print the updated map.

Expected Output:

Updated Map: {name: Alice, age: 26, city: New York, country: USA}

9. Bubble Sort

Write a Dart program to implement the Bubble Sort algorithm and sort a list of integers [5, 2, 9, 1, 5, 6] in ascending order.

Expected Output:

Sorted List: [1, 2, 5, 5, 6, 9]

10. Binary Search

Write a Dart program to implement the Binary Search algorithm. Search for the number 7 in the sorted list [1, 3, 5, 7, 9, 11]. If found, print its index.

Expected Output:

Number found at index: 3

Advanced Questions

11. Class and Object

Write a Dart program to create a class Car with the following properties:

  • brand (String)
  • model (String)
  • year (int)

Add a method displayInfo() that prints the car's details. Create an object of the Car class and call the displayInfo() method.

Expected Output:

Car Details:  
Brand: Toyota  
Model: Corolla  
Year: 2020

12. Inheritance

Write a Dart program to demonstrate inheritance. Create a base class Animal with a method makeSound() that prints "Animal makes a sound". Create a derived class Dog that overrides the makeSound() method to print "Dog barks".

Expected Output:

Animal makes a sound  
Dog barks

13. Optional Parameters

Write a Dart program with a function greet that takes two parameters: name (required) and message (optional). If message is not provided, default it to "Welcome".

Example Call:

greet("Alice");
greet("Bob", "Good Morning");

Expected Output:

Hello Alice, Welcome  
Hello Bob, Good Morning

14. Anonymous Function

Write a Dart program that uses an anonymous function to print the square of each number in a list: [1, 2, 3, 4, 5].

Expected Output:

Square of 1: 1  
Square of 2: 4  
Square of 3: 9  
Square of 4: 16  
Square of 5: 25

Bonus Question

15. Palindrome Checker

Write a Dart program to check if a given string is a palindrome. A string is a palindrome if it reads the same backward as forward. Test with the string "madam".

Expected Output:

The string 'madam' is a palindrome.

Solutions Hints

  1. Use print() for output.
  2. Arithmetic operations: +, -, *, /.
  3. Lists: Use .add(), .sort().
  4. Sets: Use .add() and .remove().
  5. Maps: Use map[key] = value.
  6. Sorting: Implement loops for Bubble Sort.
  7. Binary Search: Use iterative or recursive logic.
  8. Classes: Use class and object instantiation.
  9. Inheritance: Use extends for a subclass.
  10. Optional parameters: Use [] or {} for optional/ named parameters.
  11. Anonymous functions: Use list.forEach() with a lambda function.

Good Luck with Dart Programming! 🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages