Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In matlab.write a program that converts a numerical date given by the user into

ID: 3747573 • Letter: I

Question

In matlab.write a program that converts a numerical date given by the user into a month, day, and year. Specifically, the user should input a sequence of eight numbers 05141956.

the program should print out the same date in complete format. In this example it would print "The date is May 14th, 1956". Notice the "th" addition after the day. This changes depending on the number. Make sure this feature is included. MATLAB has built-in date conversion functions. You cannot use them in this exercise.

Explanation / Answer

prompt = 'Enter date ( mmddyyyy ) : ';

% read string date from user

date = input(prompt , 's');

new_date = '';

% strcat() concatenates the string

% str2num() converts string to number

month = str2num(['uint32(', strcat( date(1) , date(2) ) ,')']);

% strcat() concatenates the string

% str2num() converts string to number

day = str2num(['uint32(', strcat( date(3) , date(4) ) ,')']);

% strcat() concatenates the string

% str2num() converts string to number

year = str2num(['uint32(', strcat( strcat( date(5) , date(6) ) , strcat( date(7) , date(8) ) ) ,')']);

% print the appropriate month

if month == 1

   

    fprintf('January ');

elseif month == 2

   

    fprintf('February ');

   

elseif month == 3

   

    fprintf('March ');

   

elseif month == 4

   

    fprintf('April ');

   

elseif month == 5

   

    fprintf('May ');

   

elseif month == 6

   

    fprintf('June ');

   

elseif month == 7

   

    fprintf('July ');

   

elseif month == 8

   

    fprintf('August ');

   

elseif month == 9

   

    fprintf('Septembet ');

   

elseif month == 10

   

    fprintf('October ');

   

elseif month == 11

   

    fprintf('November ');

   

elseif month == 12

   

    fprintf('December ');

   

end

fprintf('%d' , day);

if day == 1

   

    fprintf('st, ');

   

elseif day == 2

   

    fprintf('nd, ');

   

elseif day == 3

   

    fprintf('rd, ');

   

else

   

    fprintf('th ');

   

end

fprintf('%d ', year);

Sample Output

Enter date ( mmddyyyy ) : 09082018
Septembet 8th 2018

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote