C++ Programming
Step 1. Design a new ADT that implements a class named Date, add 3 private member variables month, day, year along with their appropriate public constructor / getter / setter member functions inside Date.h and Date.cpp.
Step 2. Design another ADT that implements a class named Watch, add 3 private member variables hour, minute, second, along with their appropriate public constructor / getter / setter member functions inside Watch.h and Watch.cpp.
Step 3. Next, implement the additional SmartWatch class that is derived from your Watch class. The SmartWatch class should have a private member variable named "notification" that stores the description for an event. Add appropriate constructor, mutator, and accessor functions. Additionally, inside the SmartWatch class add another private attribute Date eventdate, as an object composition.
Step 4. See attached main.cpp. There is no need to add for any additional functionality in main.cpp.
main.cpp :
Date createToday();
void createClassicWatch(Date *today);
void manageCustomEvent(Date *today);
int main() {
Date today = createToday();
createClassicWatch(&today);
manageCustomEvent(&today);
}
Date createToday()
{
//create today's date object
cout << "Enter todays date: " << endl;
int day, month, year;
cin >> day >> month >> year;
Date today(day, month, year);
return today;
}
//create watch object
void createClassicWatch(Date *today) {
cout << "Enter current time: " << endl;
int hour, min, sec;
cin >> hour >> min>> sec;
Watch rolex(hour, min, sec);
cout << "----------------------------------------" << endl;
cout << "Classic watch display screen" << endl;
cout << "Today date: " << today->getDay() << "/" << today->getMonth() << "/" << today->getYear() << endl;
cout << "Current time: " << setfill('0') << setw(2) << rolex.gethr() << ":" << setfill('0') << setw(2) << rolex.getmin() << ":" << setfill('0') << setw(2) << rolex.getsec() << endl;
cin.ignore();
cin.clear();
}
//create smart watch object
void manageCustomEvent(Date *today) {
cout << "----------------------------------------" << endl;
cout << "Enter event name " << endl;
string event_name = "";
getline(cin, event_name);//user enters Final exam
cin.clear();
cout << "Enter event date" << endl;
//declare all variables needed for smart watch object
int event_day = 0, event_month = 0, event_year = 0, event_hour = 0, event_min = 0, event_sec = 0;
cin >> event_month>> event_day >> event_year; //user enters exam date 5 11 2019
cout << "Enter event time" << endl;
cin >> event_hour >> event_min >> event_sec; //user enters exam time 8 00 00 2019
Smart_watch applewatch(event_day, event_month, event_year, event_hour, event_min, event_sec, event_name);
applewatch.displayDaysBeforeEvent(today);
}
#pragma once
class Date
{
private:
int day, month, year;
public:
//constructor
Date(int day, int month, int year);
//getters
int getDay();
int getMonth();
int getYear();
//setters
void setDay(int day);
void setMonth(int month);
void setYear(int year);
};
#include"Date.h"
Date::Date(int day, int month, int year)
{
this->day = day;
this->month = month;
this->year = year;
}
//getters
int Date::getDay()
{
return day;
}
int Date::getMonth()
{
return month;
}
int Date::getYear()
{
return year;
}
//setters
void Date::setDay(int day)
{
this->day = day;
}
void Date::setMonth(int month)
{
this->month = month;
}
void Date::setYear(int year)
{
this->year = year;
}
#pragma once
class Watch
{
private:
int hour, minute, second;
public:
//constructor
Watch(int hour, int minute, int second);
//getters
int gethr();
int getmin();
int getsec();
//setters
void sethr(int hr);
void setmin(int min);
void setsec(int sec);
};
#include"Watch.h"
//constructor
Watch::Watch(int hour, int minute, int second)
{
this->hour = hour;
this->minute = minute;
this->second = second;
}
//getters
int Watch::gethr()
{
return hour;
}
int Watch::getmin()
{
return minute;
}
int Watch::getsec()
{
return second;
}
//setters
void Watch::sethr(int hr)
{
hour = hr;
}
void Watch::setmin(int min)
{
minute = min;
}
void Watch::setsec(int sec)
{
second = sec;
}
#pragma once
#include<iostream>
using namespace std;
#include"Date.h"
#include"Watch.h"
class Smart_watch:public Watch
{
private:
string notification;
Date *eventdate;
public:
Smart_watch(int day,int month, int year,int hr,int
min,int sec,string eventname);
//getters
string getNotification();
Date *getEventDate();
//setters
void setNotification(string event);
void setEventDate(Date *dt);
void displayDaysBeforeEvent(Date *today);
};
#include"SmartWatch.h"
Smart_watch::Smart_watch(int day, int month, int year, int hr, int
min, int sec, string eventname):Watch(hr,min,sec)
{
eventdate= new Date(day, month, year);
this->notification = eventname;
}
//getters
string Smart_watch::getNotification()
{
return notification;
}
Date * Smart_watch::getEventDate()
{
return eventdate;
}
//setters
void Smart_watch::setNotification(string event)
{
notification = event;
}
void Smart_watch::setEventDate(Date *dt)
{
eventdate = dt;
}
void Smart_watch::displayDaysBeforeEvent(Date *today)
{
cout << "Number of days before Event: " <<
( eventdate->getDay() -today->getDay() )<<endl;
}
#include<iomanip>
#include<string>
#include"SmartWatch.h"
Date createToday();
void createClassicWatch(Date *today);
void manageCustomEvent(Date *today);
int main() {
Date today = createToday();
createClassicWatch(&today);
manageCustomEvent(&today);
//to hold the output screen
system("pause");
}
Date createToday()
{
//create today's date object
cout << "Enter todays date: " << endl;
int day, month, year;
cin >> day >> month >> year;
Date today(day, month, year);
return today;
}
//create watch object
void createClassicWatch(Date *today) {
cout << "Enter current time: " <<
endl;
int hour, min, sec;
cin >> hour >> min >> sec;
Watch rolex(hour, min, sec);
cout << "----------------------------------------" << endl;
cout << "Classic watch display screen" << endl;
cout << "Today date: " << today->getDay() << "/" << today->getMonth() << "/" << today->getYear() << endl;
cout << "Current time: " << setfill('0') << setw(2) << rolex.gethr() << ":" << setfill('0') << setw(2) << rolex.getmin() << ":" << setfill('0') << setw(2) << rolex.getsec() << endl;
cin.ignore();
cin.clear();
}
//create smart watch object
void manageCustomEvent(Date *today) {
cout << "----------------------------------------" << endl;
cout << "Enter event name " << endl;
string event_name = "";
getline(cin, event_name);//user enters Final exam
cin.clear();
cout << "Enter event date" << endl;
//declare all variables needed for smart watch object
int event_day = 0, event_month = 0, event_year = 0, event_hour = 0, event_min = 0, event_sec = 0;
cin >> event_day>>event_month >> event_year; //user enters exam date 5 11 2019
cout << "Enter event time" << endl;
cin >> event_hour >> event_min >> event_sec; //user enters exam time 8 00 00 2019
Smart_watch applewatch(event_day, event_month, event_year, event_hour, event_min, event_sec, event_name);
applewatch.displayDaysBeforeEvent(today);
}
//output
//if you need any help regarding this solution........... please leave a comment thanks.........
C++ Programming Step 1. Design a new ADT that implements a class named Date, add 3 private member variables month, day, year along with their appropriate public constructor / getter / setter member fu...
LW: Class Constructors Objectives Write a default constructor for a class. Note that this constructor is used to build the object anytime an argument is not provided when it is defined. Write a parameterized constructor that takes arguments that are used to initialize the class’s member variables Labwork Download the code associated with this lab: ColorConstructor.zip Main.cpp Color.h Color.cpp Compile and run the code. The first line of output of the program should display nonsensical integers for the values of...
For the LinkedList class, create a getter and setter for the private member 'name', constructing your definitions based upon the following declarations respectively: std::string get_name() const; and void set_name(std::string); In the Main.cpp file, let's test your getter and setter for the LinkedLIst private member 'name'. In the main function, add the following lines of code: cout << ll.get_name() << endl; ll.make_test_list(); ll.set_name("My List"); cout << ll.get_name() << endl; Output should be: Test List My List Compile and run your code;...
The class dateType is designed to implement the date in a program, but the member function setDate and the constructor do not check whether the date is valid before storing the date in the data members. Rewrite the definitions of the function setDate and the constructor so that the values for the month, day, and the year are checked before storing the date into the data members. Add a function member, isLeapYear, to check whether a year is a leap...
C++ Design a class bankAccount that defines a bank account as an ADT and implements the basic properties of a bank account. The program will be an interactive, menu-driven program. a. Each object of the class bankAccount will hold the following information about an account: account holder’s name account number balance interest rate The data members MUST be private. Create an array of the bankAccount class that can hold up to 20 class objects. b. Include the member functions to...
public class Date { private int month; private int day; private int year; /** default constructor * sets month to 1, day to 1 and year to 2000 */ public Date( ) { setDate( 1, 1, 2000 ); } /** overloaded constructor * @param mm initial value for month * @param dd initial value for day * @param yyyy initial value for year * * passes parameters to setDate method */ public Date( int mm, int dd, int yyyy )...
#include <iostream> using namespace std; class Circle{ // private member variable named radius private: double radius; // get function for radius public: double getRadius(){ return radius; } // set function for radius void setRadius(double rad){ radius=rad; } // returning area = 3.14159 * radius * radius double getArea(){ return (3.14159 * radius * radius); } }; // Sample run int main() { // Declaring object of Circle Circle myCircle; myCircle.setRadius(5); // printing radius of circle cout<<"Radius of circle is: "<<(myCircle.getRadius())<<endl;...
USE C++. Just want to confirm is this right~? Write a class named RetailItem that holds data about an item in a retail store. The class should have the following member variables: description: A string that holds a brief description of the item. unitsOnHand: An int that holds thw number of units currently in inventory. price: A double that holds that item's retail price. Write the following functions: -appropriate mutator functions -appropriate accessor functions - a default constructor that sets:...
employee.h ---------- #include <stdio.h> #include <iostream> #include <fstream> class Employee { private: int employeeNum; std::string name; std::string address; std::string phoneNum; double hrWage, hrWorked; public: Employee(int en, std::string n, std::string a, std::string pn, double hw, double hwo); std::string getName(); void setName(std::string n); int getENum(); std::string getAdd(); void setAdd(std::string a); std::string getPhone(); void setPhone(std::string p); double getWage(); void setWage(double w); double getHours(); void setHours(double h); double calcPay(double a, double b); static Employee read(std::ifstream& in); void write(std::ofstream& out); }; employee.cpp ---------- //employee.cpp #include...
Design and implement a C++ class called Date that has the following private member variables month (int) day (nt) . year (int Add the following public member functions to the class. Default Constructor with all default parameters: The constructors should use the values of the month, day, and year arguments passed by the client program to set the month, day, and year member variables. The constructor should check if the values of the parameters are valid (that is day is...
Create a class called Flower. Add one member variables color. Add only one getter function for the color. The get function returns color. Implement a constructor that expects color value and assigns it to the member variable. Create a subclass of Flower named Rose. The Rose class has one member variable name. Add a constructor which expects color and name. Pass color to the base constructor and set name to it's member variable.Write a program that has an array of ...