Question

ASSIGNMENT - more on classesDue today A program needs a class to represent the date. 1. Define the year. Additionally, declare the following methods: class Date for this purpose using three integral data members for day, month, and void init( int month, int day, int year); void init(void); void print(void); Store the definition of the class Date in a header file Implement the methods for the class Date in a separate source file: 1. The method print0 outputs the date to standard output using the format Month- 2. The method init0 uses three parameters and copies the values passed to it to Day-Year corresponding members. A range check is not required at this stage, but will be added later. The method init0 without parameters writes the current date to the corresponding members. Note Use the functions declared in ctime 3. time_t time(time_t *ptrSec) struct tm *localtime(const time_t *ptrSec); The structure tm and sample calls to this function are included opposite. The type time_t is defined as long in ctime. The function time(0 returns the system time expressed as a number of seconds and writes this value to the variable referenced by ptrSec. This value can be passed to the function localtime() that converts the number of seconds to the local type tm date and returns a pointer to this structure. Test the class Date using an application program that once more is stored in a separate source file. To this end, define two objects for the class and display the current date.

MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Date.h

******************

class Date {

private:

int day, month, year;

public:

void init(int m, int d, int y);

void init(void);

void print(void);

};

Date.cpp

******************

#include <iostream>

#include <ctime>

#include "Date.h"

using namespace std;

void Date::init(int m, int d, int y) {

month = m;

day = d;

year = y;

}

void Date::init() {

time_t now = time(0);

tm *ltm = localtime(&now);

init(ltm->tm_mon + 1, ltm->tm_mday, 1970 + ltm->tm_year);

}

void Date::print() {

cout << month << "-" << day << "-" << year << endl;

}

Main.cpp

*****************

#include <iostream>

#include <ctime>

#include "Date.h"

using namespace std;

int main() {

Date d1;

d1.init();

d1.print();

Date d2;

d2.init(11, 30, 2017);

d2.print();

}

Add a comment
Know the answer?
Add Answer to:
MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST BE DONE IN C++ .MUST...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Use c++ to code: Problem 1 Implement a class Clock whose get hours and get_minutes member functions return the current...

    Use c++ to code: Problem 1 Implement a class Clock whose get hours and get_minutes member functions return the current time at your location. To get the current time, use the following code, which requires that you include the <ctime>header time_t current_time time (e); ta local time - localtime(current, tine)i int hours -local_time->tm hour int minutes-local time->tm_min; Also provide a get_time member function that returns a string with the hours and minutes by calling the get_hours and get_minutes functions. Provide...

  • You are to write a basic fitness application, in C++, that allows the user of the...

    You are to write a basic fitness application, in C++, that allows the user of the application to manually edit “diet” and “exercise” plans. For this application you will need to create three classes: DietPlan, ExercisePlan, and FitnessAppWrapper. Diet Plan Attributes: The class DietPlan is used to represent a daily diet plan. Your class must include three data members to represent your goal calories (an integer), plan name (a std::string), and date for which the plan is intended (a std::string)....

  • its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task an...

    its about in C++ You will implement a simple calendar application The implementation should include a class named Calendar, an abstract class named Event and two concrete classes named Task and Appointment which inherit from the Event class The Event Class This will be an abstract class. It will have four private integer members called year, month, day and hour which designate the time of the event It should also have an integer member called id which should be a...

  • HW_8b - Famous People - One class used by another class - This exercise requires the...

    HW_8b - Famous People - One class used by another class - This exercise requires the declaration of two classes: o Famous People O Date - 5 Files are required: o Date.h o Date.cpp o Famous People.h o Famous People.cpp o main.cpp File: Date.h Private data members: O _month o _day 0 year - Public member functions: o Default constructor • Assign O's to all three data members. o Overloaded constructor • Three integer values are passed as arguments from...

  • C++ problem 11-6 In Programming Exercise 2, the class dateType was designed and implemented to keep...

    C++ problem 11-6 In Programming Exercise 2, the class dateType was designed and implemented to keep track of a date, but it has very limited operations. Redefine the class dateType so that it can perform the following operations on a date, in addition to the operations already defined: Set the month. Set the day. Set the year. Return the month. Return the day. Return the year. Test whether the year is a leap year. Return the number of days in...

  • C++ programming question Topic: Class 'Date' Hello everybody, can some one help me... ... Write a...

    C++ programming question Topic: Class 'Date' Hello everybody, can some one help me... ... Write a class Date with the following properties: a) Data elements of the class are day, month, year. All three data elements are defined by the Type int. b) A set and a get element function are to be provided for each data element. In Within the framework of this task, it should be assumed that the values that are passed for day and year, are...

  • SaffSpring 2019 Professor Question 1: Answer ALL of the following questions based on this provide...

    I need sub-questions e, f, g, h. SaffSpring 2019 Professor Question 1: Answer ALL of the following questions based on this provided int daya int montha Date int dnt int y day-d year class Event ring locatson eventbat Event (5tring , Dated ocatlon- event Date-d pubiie String toStringt String detalla-Locatlons"LocatlonDatesevent Date.day return detalia eventDate-year publie statie weld mai arg Event 2ew EventCBayan" hew Date1.3,20191 Systen.out peintil The event n (11.201,as scheduled-ee . 내 1 eentDate.yeari ystem.st-printeinte yatem.ost-printcin(e2) a) What is...

  • Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type...

    Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type int Name of type String Balance of type float Public members void Init) method to enter the values of data members void Show) method to display the values of data members void Deposit(int Amt) method to increase Balance by Amt void Withdraw(int Amt) method to reduce Balance by Amt (only if required balance exists in account) float RBalance() member function that returns the value...

  • For this project a Date class(specifiedin the file Project_10.h) will be constructed and all function definitions will be written in the file Project_10.cpp. A makefileis provided to compile this project. The file Project_10_main.cppcontainsthe main fun

    Project_10_base_files.zipMakefile (2).txtProject_10_main 1.JPGProject_10_main 2.JPGProject_10_main 3.JPGProject_10 h.JPGProject_10 cpp.JPGAny C++ technique covered in Chapters 1 through 12is allowedexcept for global variablesYou are not allowed to use any global variables.If necessary, global constants may be used.Project 10DescriptionFor this project a Date class(specifiedin the file Project_10.h) will be constructed and all function definitions will be written in the file Project_10.cpp.  A makefileis provided to compile this project.  The file Project_10_main.cppcontainsthe main functionthat is used to run the program.On Canvas, download the files Project_10.h, Project_10_main.cpp...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT