How to resolve the algorithm Last Friday of each month step by step in the Visual FoxPro programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Last Friday of each month step by step in the Visual FoxPro programming language

Table of Contents

Problem Statement

Write a program or a script that returns the date of the last Fridays of each month of a given year. The year may be given through any simple input method in your language (command line, std in, etc).

Example of an expected output:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Last Friday of each month step by step in the Visual FoxPro programming language

Source code in the visual programming language

*!* OOP implementaion
LOCAL lnYear As Integer, oCalc As fricalc
CLEAR
lnYear = VAL(INPUTBOX("Year", "Year"))
oCalc = NEWOBJECT("fricalc")
oCalc.LastFriday(lnYear)

DEFINE CLASS fricalc As Session
DataSession = 2	&& Private

PROCEDURE Init
*!* These date settings are private to this class
SET DATE YMD
SET CENTURY ON
SET MARK TO "-"
ENDPROC

FUNCTION LastFriday(tnYear As Integer) As VOID
LOCAL i As Integer, ldDate As Date
CLEAR
? "Last Fridays in the year " + TRANSFORM(tnYear)
FOR i = 1 TO 12
	ldDate = DATE(tnYear, i, 1)	&& 1st of month
	ldDate = GOMONTH(ldDate, 1) - 1	&& last day of month
	*!* Use the built in function to return the day of the week
	*!* 6 is Friday
	DO WHILE DOW(ldDate) # 6
		ldDate = ldDate - 1 
	ENDDO
	? ldDate
ENDFOR
ENDFUNC

ENDDEFINE


  

You may also check:How to resolve the algorithm Pointers and references step by step in the D programming language
You may also check:How to resolve the algorithm Sort a list of object identifiers step by step in the Java programming language
You may also check:How to resolve the algorithm Introspection step by step in the jq programming language
You may also check:How to resolve the algorithm String matching step by step in the MIPS Assembly programming language
You may also check:How to resolve the algorithm Numerical integration step by step in the AutoHotkey programming language