Exercise

Create the following directory tree :



  1. msg.dart
  2. Create two fuctions the first print "Program starts" and the second print "Program ends".

  3. trigo.dart
  4. Create three functions that print the sin , cos and tan of a given number using math library.

  5. cal.dart
  6. Create two functions that print the square and the logarithm of a given number using math library.

  7. main.dart
  8. - Import msg.dart and cal.dart.
    - Import trigo.dart with a perfix "trigo".
    - Use all functions inside all these 3 files.




Solution:

Solution

  1. msg.dart

  2. void printStart() {

      print("Program start");

    }

     

    void printEnd() {

      print("Program end");

    }



  3. trigo.dart

  4. import 'dart:math';

     

    void printSin(double x) {

      print("sin($x) = ${sin(x)}");

    }

     

    void printCos(double x) {

      print("cos($x) = ${cos(x)}");

    }

     

    void printTan(double x) {

      print("Tan($x) = ${tan(x)}");

    }



  5. cal.dart

  6. import 'dart:math';

     

    void printSqrt(double x) {

      print("the sqrt of $x is ${sqrt(x)}");

    }

     

    void printLog(double x) {

      print("the log of $x is ${log(x)}");

    }



  7. main.dart

  8. import './messages/msg.dart';

    import './math/cal.dart';

    import './math/trigo.dart' as trigo;

     

    void main() {

      printStart();

      trigo.printSin(0.5);

      trigo.printCos(0.75);

      trigo.printTan(0.25);

      printSqrt(9);

      printLog(1);

      printEnd();

    }




    Program start
    sin(0.5) = 0.479425538604203
    cos(0.75) = 0.7316888688738209
    Tan(0.25) = 0.25534192122103627
    the sqrt of 9.0 is 3.0
    the log of 1.0 is 0.0
    Program end