Lab Assignment 5 Due date Saturday Feb 11 11 00pm Getting st

Lab Assignment #5 Due date: Saturday, Feb 11, 11 00pm. Getting started Create a new directory called labos under your cse220 directory Implement the programs below in your labo5 directory Project Description Write a program that asks the user to enter their birthdate in mm/ddWyyyyformat and reads the user input. Call your program Your program should first check if the date is valid The month is between 1 and 12. The day is between 1 and 31. The day does not exceed the number of days of the month (eg an 31 is valid, April 31 is not). You do not have to check if the year is a leap year. the date is not valid, your program should output an error message and exit. the date is valid, your program should output the following: You were born on a Compute the day of week as follows: Compute the month coefficient, me, for each month according to the following table Mar Sep 4 May Nov Decrement the year by 1 if the month is an or Feb, otherwise keepit the same 3. Compute the rank as follows Compute the folowing value year year/4-year o0+ yearA00 of the previous value when divided by 7 You will an integer b. Find the remainder between 0 and 6. Find the day according to the following schedule:

Solution

Code:

#include<stdio.h>
#include<stdlib.h>
#include<string.h>

//Month coefficient
int mc[12]={0,3,2,5,0,3,5,1,4,6,2,4};

//Number of days in month - not considering leap/non-leap
int days[12]={31,29,31,30,31,30,31,31,30,31,30,31};

//day of the week
char *dw[]={\"Sunday\", \"Monday\", \"Tuesday\", \"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"};

int main(void)
{

char birthdate[12];

printf(\"Enter birthdate mm/dd/yyyy:\");
scanf(\"%s\", birthdate);
int d[3],day,year;
int monthCoeff;
int val;

char *tt=strtok(birthdate,\"/\");
int i=0;

//Splitting the given string mm/dd/yyyy and storing int array d[] in that order
while(tt!=0){
   d[i++]=atoi(tt);
   tt=strtok(NULL,\"/\");
}

if(d[0]<1 || d[0]>12) { printf(\"Month not in range\ \"); return 0;}

if(d[1]<1 || d[1]>31) { printf(\"Day not in range\ \"); return 0;}


if(d[1] > days[d[0]-1] )
{
   printf(\"Days in a month is exceeding beyond assigned\ \");
    return 0;
}

monthCoeff=mc[d[0]-1];

if(d[0]== 1 || d[0] == 2) year=d[2]-1;
else
   year=d[2];

val= year + year/4 - year/100 + year/400+ monthCoeff + d[1];

day=val%7;


printf(\"You were born on %s\ \", dw[day]);

return 0;
}

Output:

Enter birthdate mm/dd/yyyy:09/18/1988
You were born on Sunday

 Lab Assignment #5 Due date: Saturday, Feb 11, 11 00pm. Getting started Create a new directory called labos under your cse220 directory Implement the programs b
 Lab Assignment #5 Due date: Saturday, Feb 11, 11 00pm. Getting started Create a new directory called labos under your cse220 directory Implement the programs b

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site