SuperTutor

(15)

$15/per page/Negotiable

About SuperTutor

Levels Tought:
Elementary,Middle School,High School,College,University,PHD

Expertise:
Accounting,Business & Finance See all
Accounting,Business & Finance,Economics,Engineering,HR Management,Math Hide all
Teaching Since: Apr 2017
Last Sign in: 327 Weeks Ago, 5 Days Ago
Questions Answered: 12843
Tutorials Posted: 12834

Education

  • MBA, Ph.D in Management
    Harvard university
    Feb-1997 - Aug-2003

Experience

  • Professor
    Strayer University
    Jan-2007 - Present

Category > Programming Posted 09 Jun 2017 My Price 15.00

CH3

CH3 Check for Valid Date MM/DD/YYYY

Requirement:

Write a program that reads a string from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid. The input date will have the format mm/dd/yyyy. A valid month value mm must be from 1 to 12 (January is 1). The day value dd must be from 1 to a value that is appropriate for the given month. September, April, June, and November each have 30 days. February has 28 days except for leap years when it has 29. The remaining months all have 31 days each. A leap year is any year that is divisible by 4 but not divisible by 100 unless it is also divisible by 400.

 

 

Design Notes:

1.  The input date should be a string (say inputDate) in the form of mm/dd/yyyy. To read it from the keyboard, you can use function getline() to retrieve the string from user. Note, you should NOT prompt the user for month, day, and year, separately.

 

2.  If we want to be ridged on the input format, then we can expect the input characters are at fixed positions. For example,

index

0

1

2

3

4

5

6

7

8

9

character

month1

month2

“/”

day1

day2

“/”

year1

year2

year3

year4

 

a.  We can retrieve those characters for month, day, and year by index. Note: index starts from 0. For example:

char month1 = inputDate[0];

char day1 = inputDate[3];                                    

b.   You can then convert those characters to integers, for example:

int day = (day1 - '0')*10 + (day2 -'0');         //why? See ASCII table

Attachments:

Answers

(15)
Status NEW Posted 09 Jun 2017 07:06 AM My Price 15.00

-----------

Attachments

file 1496992081-Solutions file.docx preview (51 words )
S-----------olu-----------tio-----------ns -----------fil-----------e -----------Hel-----------lo -----------Sir-----------/Ma-----------dam----------- T-----------han-----------k y-----------ou -----------for----------- yo-----------ur -----------int-----------ere-----------st -----------and----------- bu-----------yin-----------g m-----------y p-----------ost-----------ed -----------sol-----------uti-----------on.----------- Pl-----------eas-----------e p-----------ing----------- me----------- on----------- ch-----------at -----------I a-----------m o-----------nli-----------ne -----------or -----------inb-----------ox -----------me -----------a m-----------ess-----------age----------- I -----------wil-----------l b-----------e q-----------uic-----------kly----------- on-----------lin-----------e a-----------nd -----------giv-----------e y-----------ou -----------exa-----------ct -----------fil-----------e a-----------nd -----------the----------- sa-----------me -----------fil-----------e i-----------s a-----------lso----------- se-----------nt -----------to -----------you-----------r e-----------mai-----------l t-----------hat----------- is----------- re-----------gis-----------ter-----------ed -----------on-----------th-----------is -----------web-----------sit-----------e -----------Tha-----------nk -----------you----------- -----------
Not Rated(0)
Relevent Questions