Download Our Beta Android App And Help Us Build Awesome Stuff!  Download Now.

Decision Table Testing Next Date C Program

next_date.txt
File size: 896 Bytes

File content type: text/plain

Category: Notes, Practical Files, and Assignment

Course: B.Tech.

Semester: 7

#include <stdio.h>
#include <stdbool.h>
#define YEAR_MIN 1900
#define YEAR_MAX 2100

int month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};

bool isLeapYear(int y) {
	return ((y % 400 == 0) || (y % 4 == 0 && y % 100 != 0));
}

bool isNotValid(int d, int m, int y) {
	return (d <= 0 || d > month[m] || m < 0 || m > 12 || y < YEAR_MIN || y > YEAR_MAX);
}

void test(int d, int m, int y) {
	int d1 = d, m1= m, y1 = y;
	if(isLeapYear(y)) {
		month[2] = 29;
	} else {
		month[2] = 28;
	}
	
	if(isNotValid(d,m,y)) {
		printf("%d\t%d\t%d\t%s\n",d1,m1,y1,"Not a valid date");
	} else {
		d++;
		if(d > month[m]) {
			d = 1;
			m++;
		}
		
		if(m > 12) {
			m = 1;
			y++;
		}
		printf("%d\t%d\t%d\t%d/%d/%d\n",d1,m1,y1,d,m,y);
	}
}

int main(void) {
	
	test(0,0,1899);
	test(0,0,1900);
	test(0,3,1899);
	test(0,3,1900);
	test(20,0,1899);
	test(20,0,1900);
	test(20,3,1899);
	test(20,3,1900);
	
	return 0;
}

Added by passhojao

Comments