Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Design a class dayType that implements the day of the week as an abstract data type. The class dayType should store the day as a

Design a class dayType that implements the day of the week as an abstract data type. The class dayType should store the day as a string. The class should be able to perform the following operations on an object of type dayType:

Set the day.

Print the day.

Get the day.

Get the next day.

Get the previous day.

Calculate and return the day obtained by adding a certain number of days to the current day. For example, if the current day is Monday and we add 4 days, the day to be returned is Friday. Similarly, if today is Tuesday and we add 13 days, the day to be returned is Monday.

The class should also include a static array member which specifies the valid strings that can be used to set the day instance variable. Provide static functions that allow the user to retrieve the day strings and to set the day strings to different values (for example, the user might want the day strings to be the full name such as Sunday, Monday, Tuesday, etc. or they may want to use abbreviations such as Sun, Mon, Tues, etc. Your user may also want to start the week on Monday rather than Sunday. Initialize the static array to an initial set of strings which will be used by default if not changed by the user. To ensure that your day is consistent with the strings in the dayNames array, store the day as an integer between 0 and 6 and use it to index into the dayNames array. However, this must be kept hidden from the user. The user should only use strings to interface with your class.

You are to add member functions to manipulate the data members. Follow the convention that the instance variables are private and the member functions are public. Write the header file including documentation for the function prototypes specifying the purpose of the function, any preconditions that may exist, and the postconditions. The viewpoint of the documentation is for someone who might want to use your class. Write the implementation file. Make sure any data provided to modifier functions does not violate the preconditions and that the private instance variables do not become invalid. Write a test program to show that the class is working as specified..

Turn in your dayType.h, dayType.cpp, and test program files. Also turn in one or more screen shots showing the results of your testing.

Once this exercise is completed, you will demonstrate that you are able to:

Write a C++ class that implements an abstract data type

Utilize the concept of information hiding

Utilize static members in a class

Specify preconditions and postconditions for the member functions in the header file

Translate preconditions to code which maintains the validity of the private variables

Write a program that demonstrates that your class is working as specified

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

c. How is trust demonstrated?

Answered: 1 week ago

Question

c. Will leaders rotate periodically?

Answered: 1 week ago

Question

b. Will there be one assigned leader?

Answered: 1 week ago