Algorithms

  1. PROBLEM STATEMENT: Algorithm for working of an alarm
    Alarm needs to be set for a specific time for the user to wake up at that time.
    We may give options to the user like, switching off the alarm or snoozing it etc.

    SOLUTION:
    // Input : Give some standard time
    //Output : we will get the notification
    1. Get system time
    2.Get input alarm time from user
    3.Convert the input pattern to standard format
    4.Wait
    Unit system time hits the input time
    5.Notify the user with user notification
    6. Stop the alarm after certain time
    7. Or based on the user, input alarm can have below two options
    a) Switch off the alarm as he gets the notification or
    b) Snooze it for some specific time to perform the same operation after the snooze time

    8.Stop

    2. PROBLEM STATEMENT: Algorithm for working of a calculator (basic operations)
    Basic functionality of a calculator are addition, subtraction, multiplication and division

    SOLUTION:
    //Input : Perform addition, subtraction, multiplication and division depending on the input from the user
    // Output : Result from the operations

    //Initialization :
    char operator
    double firstnum, secondnum;

    print ‘enter an operator (+,-,*,/)’;
    Enter the two numbers

    // From switch case
    case ‘+’ : (firstnum+secondnum) Then break;
    case ‘-‘ : (firstnum-secondnum) Then break;
    case ‘*’ : (firstnum*secondnum) Then break;
    case ‘/’ : (firstnum/secondnum) Then break;

    //Operator doesn’t match any case statement (+,-,*,/)
    default: Operator is not correct

    // return 0;                                                                                Author -Deepti (1cr15is022)

Leave a comment