0% found this document useful (0 votes)
67 views2 pages

Algorithm 2

The document outlines algorithms for a weekday name program with the following functions: 1. A constructor to initialize variables including a weekday array. 2. An accept() function to accept a date and first day of the month, and extract the date. 3. A calc_n_disp() function that uses a series of checks on the date and first day to determine the weekday name, retrieving it from the array and displaying it. 4. A main() function that creates an object, and calls the accept() and calc_n_disp() functions.

Uploaded by

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

Algorithm 2

The document outlines algorithms for a weekday name program with the following functions: 1. A constructor to initialize variables including a weekday array. 2. An accept() function to accept a date and first day of the month, and extract the date. 3. A calc_n_disp() function that uses a series of checks on the date and first day to determine the weekday name, retrieving it from the array and displaying it. 4. A main() function that creates an object, and calls the accept() and calc_n_disp() functions.

Uploaded by

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

Algorithm for weekday_name program:

Step 1: Declare the instance variables as String variables s and wkd, String array wkar
and integer variable d. Initialize wkar with the names of the days available in a week.

Algorithm for weekday_name() constructor:

Step 1: START OF CONSTRUCTOR.


Step 2: Initialize s and wkd with null, and d with 0.
Step 3: END OF CONSTRUCTOR.

Algorithm for accept() function:

Step 1: START OF FUNCTION.


Step 2: Accept a date in DD/MM/YYYY format and store it in s.
Step 3: Accept the first day of that month and store it in wkd.
Step 4: Store only the date from the values in s, in d.
Step 5: END OF FUNCTION.

Algorithm for calc_n_disp () function:

Step 1: START OF FUNCTION.


Step 2: Declare three integer variables i, j and n. Initialize j with 0.
Step 3: Start a loop from i = 0 till I < wkar.length. Check if the value of the ith cell of the
array wkar is same as the value in wkd.
Step 4: If yes, assign the value of i to j and break the loop.
Step 5: Check if d+j < 7. If yes, display the value of (d+j-1)th cell of the array wkar.
Step 6: If not, check if d > j and d < 7. If yes, display the value of (d-j-2)th cell of the array
wkar.
Step 7: If not, check if the value stored in d is divisible by 7. If yes, display the value of
(j-1)th cell of the array wkar.
Step 8: If not, check if the value stored in d is not divisible by 7. If yes, store the value
(d%7)+j-1 in n.
Step 8: Check if n >= 7. If yes, If yes, subtract 7 from n and store it in n. Display the value
of nth cell of the array wkar.
Step 9: If not, display the value of nth cell of the array wkar.
Step 10: END OF FUNCTION.

Algorithm for main() function

PAGE 2.2
Step 1: START OF FUNCTION.
Step 2: Create an object ob of the class.
Step 3: Invoke the function accept() as ob.accept().
Step 4: Invoke the function calc_n_disp() as ob.calc_n_disp().
Step 5: END OF FUNCTION.

PAGE 2.3

You might also like