Question: Using c++/ need to download the following sDate.h /* * @topic S-0326-09-02-35 Assignment a9 Serial date class * @brief class SDate */ #ifndef SDATE_H_INCLUDED_ #define

Using c++/ need to download the following

sDate.h

/* * @topic S-0326-09-02-35 Assignment a9 Serial date class * @brief class SDate */

#ifndef SDATE_H_INCLUDED_ #define SDATE_H_INCLUDED_

class SDate { public: // Function to set calendar date. Returns: // -- false if given month/day/year are invalid // -- true if everything is okay. bool set( int mm, int dd, int yyyy );

//---------------------------------------------- // functions to manipulate serial value //---------------------------------------------- void serial( int sDate ); // set serial date

int serial(); // get serial date

void add( int days ); // add days to the serial value

//---------------------------------------------- // functions to change or get calendar parts: //---------------------------------------------- void set_month( int mm ); // set month

int month(); // get month

void day( int dd ); // set day

int day(); // get day

void year( int yyyy ); // set year

int year(); // get year

};//class SDate

#endif //SDATE_H_INCLUDED_

and

SDate_main.cpp

* * @topic S-0326-09-02-55 Assignment a9 Serial date class * @brief Assignment a9 test driver program */

#include #include "std_lib_facilities.h" #include "SDate.h"

int main() { SDate date; // 7/4/1776 2369916 date.set( 7, 4, 1776 ); assert( date.serial() == 2369916 );

date.serial( 2369916 ); assert( date.serial() == 2369916 ); assert( date.month() == 7 ); assert( date.day() == 4 ); assert( date.year() == 1776 );

date.add( 1 ); // 7/5/1776 assert( date.serial() == 2369917 ); assert( date.month() == 7 ); assert( date.day() == 5 ); assert( date.year() == 1776 );

// 12/31/2000 2451910 date.set( 12, 31, 2000 ); assert( date.serial() == 2451910 ); assert( date.month() == 12 ); assert( date.day() == 31 ); assert( date.year() == 2000 );

date.add( 1 ); // 1/1/2001 assert( date.month() == 1 ); assert( date.day() == 1 ); assert( date.year() == 2001 );

assert( date.set( 2, 29, 2000 ) ); // leap year assert( date.month() == 2 ); assert( date.day() == 29 ); assert( date.year() == 2000 );

// Test validation assert( !date.set( 2, 29, 2001 ) ); // bad day assert( !date.set( 13, 31, 2001 ) ); // bad month assert( !date.set( 1, 32, 2001 ) ); // bad day

std::cout << "Oll Korrect! "; keep_window_open(); return 0; }

and

serial_functions.cpp

* * @topic S-0326-09-01-20 Serial date mock-up for Assignment a9 * @brief mock-up definitions for serial date functions */

#include "serial_functions.h"

// CIS-155 // Please note: // This is a mock-up implementation of the serial date. // It is used for Assignment a9 demo -- Serial date class

int serial_julian_date( int Month, int Day, int Year ) { // return integer in format YYYYMMDD return Year * 10000 + Month * 100 + Day;

// The formulas to get back to the calendar parts:

// int Day = nDate % 100; // int Month = ( nDate - Day ) / 100 % 100; // int Year = ( nDate - Month * 100 - Day ) / 10000; }//serial_julian_date()

int serial_2_day( int nDate ) { return nDate % 100; }//serial_2_day()

int serial_2_month( int nDate ) { return ( nDate - serial_2_day( nDate ) ) / 100 % 100; }//serial_2_month()

int serial_2_year( int nDate ) { return ( nDate - serial_2_month( nDate ) * 100 - serial_2_day( nDate ) ) / 10000; }//serial_2_year()

and

serial_functions.h

/* * @topic S-0326-09-02-10 Assignment a9 Serial date class * @brief serial date function prototypes */

#ifndef SERIAL_FUNCTIONS_H_INCLUDED_ #define SERIAL_FUNCTIONS_H_INCLUDED_

// function prototypes for serial date int serial_julian_date( int Month, int Day, int Year ); int serial_2_day( int nDate ); int serial_2_month( int nDate ); int serial_2_year( int nDate );

#endif // SERIAL_FUNCTIONS_H_INCLUDED_

Create a new project. Add SDate_main.cpp (download ) to the list of source files in your project. This file contains the main() test driver program.

Create a new header file, serial_functions.h (download ) and a new source file serial_functions.cpp (download )

Add serial_functions.cpp to the list of source files in your project.

Open serial_functions.cpp, then copy and paste definitions of the corresponding functions that you wrote while working on the Serial Julian Date homework.

Take a look at the header guards in serial_functions.h. The declarations of the serial date functions are placed between those guards.

You also need SDate.h (download) header which declares new class SDate.

Your assignment is to finish the SDate implementation. Add a new source file named SDate.cpp to the project and write the code for SDate member functions in this file.

You should start by adding the member function definitions. For example,

void SDate::serial( int sDate ) { // Implementation code goes here } 

Notice how the member function name is prefixed by the name of the class and a double colon (highlighted). The double colon is the C++ scope resolution operator. It tells the compiler that the function SDate::serial() belongs to the scope of class SDate.

Coding requirements

Store only one integer in your SDate class - the value of the computed serial date.

When writing your implementation, call existing serial date functions to perform all low-level serial Julian date computations.

If bad parameters are detected by the set() member function, do not update the current serial date value -- simply return false. Do not print any error messages from your set() member function, let the caller deal with the problem.

Compile and test your class implementation against the main() function provided in SDate_main.cpp.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!