Programming Assignment #2

Similar documents
Assignment 2: Temperature Class

Assignment 3: Distance COP3330 Fall 2017

Operator overloading: extra examples

CSC-140 Assignment 6

Handout 7. Defining Classes part 1. Instance variables and instance methods.

Assignment 5: MyString COP3330 Fall 2017

Title. Syntax. stata.com. datetime business calendars creation Business calendars creation

HW3: CS 110X C Domain Information. Final Version: 1/29/2014

CSCI-1200 Data Structures Fall 2018 Lecture 3 Classes I

Lecture 7. Log into Linux New documents posted to course webpage

PIC 10B Lecture 1 Winter 2014 Homework Assignment #1

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Arrays. What if you have a 1000 line file? Arrays

CS31 Discussion 1E. Jie(Jay) Wang Week5 Oct.27

Note : Your program must contain the following 6 functions :

typedef int Array[10]; String name; Array ages;

Project 1 System Calls

ACORN.COM CS 1110 SPRING 2012: ASSIGNMENT A1

Task 1: Print a series of random integers between 0 and 99 until the value 77 is printed. Use the Random class to generate random numbers.

Section Handout #4: Classes, Pointers, and Dynamic Memory

AIMMS Function Reference - Date Time Related Identifiers

CIS 190: C/C++ Programming. Classes in C++

ADVANCED ALGORITHMS TABLE OF CONTENTS

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 3: SEP. 13TH INSTRUCTOR: JIAYIN WANG

Lab 2: ADT Design & Implementation

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

CS 211 Programming Practicum Fall 2018

CS 61B, Spring 1996 Midterm #1 Professor M. Clancy

} Evaluate the following expressions: 1. int x = 5 / 2 + 2; 2. int x = / 2; 3. int x = 5 / ; 4. double x = 5 / 2.

CS 426 Fall Machine Problem 1. Machine Problem 1. CS 426 Compiler Construction Fall Semester 2017

! A literal represents a constant value used in a. ! Numbers: 0, 34, , -1.8e12, etc. ! Characters: 'A', 'z', '!', '5', etc.

CS 61B, Spring 1996 Midterm #1 Professor M. Clancy

Claremont McKenna College Computer Science

Computer Science II Lecture 1 Introduction and Background

A class is a user-defined type. It is composed of built-in types, other user-defined types and

Spring 2003 Instructor: Dr. Shahadat Hossain. Administrative Matters Course Information Introduction to Programming Techniques

Data Management, Spring 2015: Project #1

CSE 303, Spring 2009 Final Exam Wednesday, June 10, 2009

Programming. C++ Basics

Why Jan 1, 1960? See:

Genesys Info Mart. date-time Section

Constants, References

Programming Date and Time APIs

Fast Introduction to Object Oriented Programming and C++

Assignment 3: Inheritance

COMP 202 Java in one week

Final Exam Practice. Partial credit will be awarded.

Programming Project 4: COOL Code Generation

Assignment: 2. CS 135 Winter 2018 Graham, Nijjar

Programming Assignment IV Due Thursday, November 18th, 2010 at 11:59 PM

Homework Assignment #3

Programming Standards: You must conform to good programming/documentation standards. Some specifics:

4. Structure of a C++ program

Abstract Data Types. Different Views of Data:

CS 225. Data Structures. Wade Fagen-Ulmschneider

CSCI 135 Software Design and Analysis, C++ Homework 2 Due 2/21/2014

BITG 1233: Introduction to C++

Makefiles Makefiles should begin with a comment section of the following form and with the following information filled in:

CSC 309/404 Section 901/910 Spring 2017 Midterm Exam Due: May 7 (Sun) 2015, 11:59 pm

CS Homework 11 p. 1. CS Homework 11

HP Project and Portfolio Management Center

Calendar PPF Production Cycles Non-Production Activities and Events

Lab#5 Due Wednesday, February 25, at the start of class. Purpose: To develop familiarity with C++ pointer variables

Arrays. Arrays (8.1) Arrays. One variable that can store a group of values of the same type. Storing a number of related values.

CSE 403 Lecture 13. Black/White-Box Testing. Reading: Software Testing: Principles and Practices, Ch. 3-4 (Desikan, Ramesh)

C++ Basics. Data Processing Course, I. Hrivnacova, IPN Orsay

MIT AITI Python Software Development

CSCD 255 HW 2. No string (char arrays) or any other kinds of array variables are allowed

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis

CSC 172 Intermediate Progamming

CS2141 Software Development using C/C++ C++ Basics

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE

Payflow Implementer's Guide FAQs

CS 342 Software Design Spring 2018 Term Project Part II Development of Question, Answer, and Exam Classes

INFORMATION TECHNOLOGY SPREADSHEETS. Part 1

CpSc 111 Lab 5 Conditional Statements, Loops, the Math Library, and Redirecting Input

CS : Programming for Non-majors, Fall 2018 Programming Project #2: Census Due by 10:20am Wednesday September

Package RcppBDT. August 29, 2016

CS Programming I: Arrays

CS 225. Data Structures

CS 142 Style Guide Grading and Details

Final. Your Name CS Fall 2014 December 13, points total Your Instructor and Section

Exercises Software Development I. 02 Algorithm Testing & Language Description Manual inspection, test plan, grammar, metasyntax notations (BNF, EBNF)

static CS106L Spring 2009 Handout #21 May 12, 2009 Introduction

Ch 6. Structures and Classes

Chapter 9 Technicalities: Classes

Chapter-8 DATA TYPES. Introduction. Variable:

Starting Savitch Chapter 10. A class is a data type whose variables are objects. Some pre-defined classes in C++ include int,

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Chapter 9 Technicalities: Classes, etc. Walter C. Daugherity Lawrence Pete Petersen Bjarne Stroustrup Fall 2007

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Chapter 9 Technicalities: Classes, etc.

Flashback Technicalities: Classes, etc. Lecture 11 Hartmut Kaiser

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Functions. Lecture 6 COP 3014 Spring February 11, 2018

Homework 3. Due: Feb 25, 23:59pm. Section 1 (20 pts, 2 pts each) Multiple Choice Questions

CSE 142, Winter 2007 Final Exam. Name:

Chapter 9 Technicalities: Classes, etc.

CS 322 Operating Systems Programming Assignment 2 Using malloc and free Due: February 15, 11:30 PM

Section #4 Solutions

Transcription:

Programming Assignment #2 Due: 11:59pm, Wednesday, Feb. 13th Objective: This assignment will provide further practice with classes and objects, and deepen the understanding of basic OO programming. Task: For this homework, you will write a class called Date, in the files date.h and date.cpp, for creating and using objects that will store valid dates of the year. This class should be portable, so it should work with any up-to-date C++ compiler. Make sure that it works with g++ on linprog before you hand it in. You should write test programs of your own to test the functionality of the class. Details: 1. An object of type Date should represent a calendar date in terms of month, day, and year, as on a 12-month A.D. calendar. The valid months are January through December, a valid day must correspond to a valid day for the given month, and the year must be a positive number no less than 1900. The class features (public interface) should work exactly as specified, regardless of what program might be using Date objects; Note: For purposes of easy input (from keyboard or into functions), date values will be specified with integers. Month values will be 1 for January, 2 for February, and so on up to 12 for December. A valid day value will be an integer between 1 and the number of days in the month (definitely no more than 31). Valid year values are positive integer numbers greater than or equal to 1900. 2. Your Date class must provide the following services (i.e. member functions) in its public section. These functions will make up the interface of the class. Make sure you use function prototypes as specified here. (You may write any other private functions you feel necessary, but the public interface must include all the functionality described here. For each function and each parameter, you need to think carefully if const is needed for declaration and definition. 2.1. Constructor(s): The Date class should have one (or multiple) constructor that allows the user to specify the values for the month, day, and year, using integer values, when the object is declared. If any of the values would result in an invalid date, the constructor should throw out the erroneous information and initialize the object to represent 1/1/2019 (January 1, 2019) instead. Also, you should allow a Date object to be declared without

specified values, in which case it should initialize to 1/1/2019 also. Examples: These declarations should be legal, and the comment gives the initialized date: Date d1; // initializes to Jan 1, 2019 Date d2(3,4,1992); // initializes to March 4, 1992 Date d3(13,30,1990); // invalid month, initializes to Jan 1, 2019 instead. 2.2. void Input(): This function should prompt the user to enter a date (like "Input date in month/day/year format: "), and then allow the user to input a date from the keyboard. User input is expected to be in the format month/day/year, where month, day, and year are integer values. Whenever the user attempts to enter an invalid date, the Input function should display an appropriate error message (like "Invalid date. Try again: ") and make the user re-enter the whole date. A few examples of some good and bad inputs: Legal: 1/4/2000, 2/28/1996, 12/31/1945 Illegal: 13/12/1985, 11/31/2002, 8/30/-2000 You may assume that the user entry will always be of the form: M/D/Y, where M, D, and Y are integers, and the slash characters (/ with the ASCII code 47) are always present. 2.3. int GetMonth() int GetDay() int GetYear() These are "accessor" functions, and they should return the month, day, and year, respectively, to the caller. 2.4. bool Set(int m, int d, int y) This function should set the date to the specified values (the first parameter represents the month, the second represents the day, and the third represents the year). If the resulting date is an invalid date, the operation should abort (i.e. the existing stored date should not be changed). This function should return true for success and false for failure (i.e. invalid date sent in). 2.5. void Increment() This function should move the date forward by ONE calendar day. Examples: Date d1(10, 31, 1998); // Oct 31, 1998 Date d2(2, 28, 2016); // Feb 28, 2016 d1.increment(); // d1 is now Nov 1, 1998

d2.increment(); // d2 is now Feb 29, 2016 (a leap year) 2.6. int DayofWeek() This function determines day of the week for a valid Date object, and the returned values range from 0 to 6: 0 stands for Sunday, 1 for Monday,.., and 6 for Saturday. Here is one algorithm to compute day of the week, called Sakamoto s Algorithm, from Wikipedia for your reference: int dayofweek(y, m, d) /* 1 <= m <= 12, y > 1752 (in the U.K.) */ { } static int t[] = {0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4}; y -= m < 3; return (y + y/4 - y/100 + y/400 + t[m-1] + d) % 7; 2.7. int Compare(const Date& d) This function should compare two Date objects (the calling object and the parameter), and should return: -1 if the calling object comes first chronologically, 0 if the objects are the same date, and 1 if the parameter object comes first chronologically. The function should not change either object. Example: Date d1(12,25,2003); // Dec 25, 2003 Date d2(5,18,2002); // May 18, 2002 d1.compare(d2); // returns 1 (since d2 comes first) d2.compare(d1); // returns -1 (calling object is d2, comes first) 2.8. void ShowByDay() This function will print out the detailed information for a Date object. The output format is like day-of-week month/day/year. Here day-of-week should be a literal string, namely Sunday, Monday,, Saturday, rather than 0, 1,, 6. Example: Date d1(2,17,2019); // Feb 17, 2019 d1.showbyday(); // Output: Sunday 2/17/2019 2.9. void ShowByMonth() This function will print out all the days of the month in which the Date object is in a calendar format. Specifically, the first line of output will be a header consisting of a static line of string like Su Mo Tu We Th Fr Sa

where Su stands for Sunday, Mo stands for Monday, and so forth. Each two-letter abbreviation is separated from the right one (if there exists) with FOUR spaces. Su (for Sunday) is at the beginning of the line, and Sa (for Saturday) is at the end of the line. In the following content lines, each day of the month, from the first day to the last day of that month, is printed out that is perfectly aligned with its corresponding day-of-week (Note that a line need to be wrapped up to the next new line after a Saturday has been printed out). For a day that is in the range of 1 and 9 (inclusive), a character 0 should be added as a prefix for output. Example: Date d1(2,17,2019); // Feb 17, 2019 d1.showbymonth(); And the output should look like: Hints: You may consider implement a series of private functions that are invisible to end-users of your class, but frequent invoked by public member functions. Here are some examples: 1. This class may need to determine if a given year is a leap year or not. A leap year has one extra day in it (Feb. 29), and the rule for leap years is as follows: A year is a leap year if it is divisible by 4, except for century years (years ending in 00). A century year is a leap year only if it is divisible by 400. (For instance, 2000 is a leap year, but 1900 is not). 2. This class may need to determine for a given month and a year, how many days there are in that month. For example, there are 29 days in February 2016 (a leap year), and there are 31 days in July 2018. 3. This class may need to determine if a date (created by constructors or input, for instance) is valid or not. Testing your class: We will provide a sample program (called test.cpp) that uses objects of type Date and illustrates the usage of the member functions. We also provide the output from the execution of the

test.cpp program. Your class declaration and definition files must work with our program, as-is (do not change our program to make your code work!). You should write your own test routines to further test the functionality of your class. Please keep in mind, test.cpp is just a sample. Your class must meet the specified requirements listed above -- not just satisfy this sample program. Your class will be tested with a larger and significantly more thorough set of calls than this sample program represents. General Requirements You need to implement the Date class all by yourself! You may use the iostream library for output. DO NOT use any other C++ standard libraries, such as chrono, local_t, time and so on, or any third-party libraries, such as Boost, for API calls; No global variables, other than constants! All member data of your class must be private; The const qualifier should be used on any member functions and parameters where it is appropriate; You only need to do error-checking that is specified in the descriptions above. If something is not specified (e.g. user entering a letter where a number is expected), you may assume that part of the input will be appropriate; user input and/or screen output should only be done where described (i.e. do not add in extraneous input/output); When you write source code, it should be readable and well-documented. Submitting: Program submissions should be done through Canvas. Do not send program submissions through e-mail -- e-mail attachments will not be accepted as valid submissions. General Advice - e-mail a copy of your finished homework files to your own FSU account. This e-mail will have a time stamp that shows when they were sent (i.e. before the due date would be the best idea), and they will also serve as a backup. It's not a bad idea to keep a copy on your CS account (as well as on a personal computer) -- backing up your work is a GOOD thing! For HW #2, submit a zipped package (named proj2.tar.gz) including the following files date.h date.cpp makefile (the final executable is named proj2) readme (optional) Make sure your filenames are these exact names, and do not submit your test.cpp file (or any other main program you might create for testing purposes).