Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use C++ to write the following code. Existing Code for Lab 6 #include #include using namespace std; //Time class class Time { //private variables private:

Use C++ to write the following code.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Existing Code for Lab 6

#include #include

using namespace std;

//Time class class Time { //private variables private: int hour; int minute; int second;

//public methods public: //default constructor Time() { hour=0; minute=0; second=0; } //constructor with arguments Time(int h,int m,int s) { //validate the condition if(h23) h=0; if(m59) m=0; if(s59) s=0; setTime(h,m,s);

} //set the time void setTime(int h,int m,int s) { if(h23) h=0; if(m59) m=0; if(s59) s=0; //set time this->hour=h; this->minute=m; this->second=s; } //return the hour int getHour() { return hour; } //return the minute int getMinute() { return minute; } //return the second int getSecond() { return second; }

//print the time formate void print() { cout

Time alarms[5]; //5 array objects //set time alarms[0].setTime(9,25,0); alarms[1].setTime(10,50,0); alarms[2].setTime(12,15,0); alarms[3].setTime(1,40,0); alarms[4].setTime(2,55,0);

//print the time using loop for(int i=0;i

Existing Code for Lab 7

The header file Date.h is as follows :

#include using namespace std;

class Date{ private: int year; int month; int day; public: void print() const; int getYear(); int getMonth(); int getDay(); void setDate(const int y, const int m, const int d); Date(); Date(const Date&); bool equals(const Date&); };

------------------------------------------------------------------------------

The file Date.cpp is as follows :

#include #include "Date.h" using namespace std;

Date :: Date() //constructor using default values : year(2001), month(1), day(1) {}

Date :: Date(const Date& d)//copy constructor { year = d.year; month = d.month; day = d.day; } //getters int Date :: getYear() { return year; }

int Date :: getMonth() { return month; }

int Date :: getDay() { return day; } //setting date after checking validity void Date :: setDate(const int y, const int m, const int d) { if(y >= 1900 && y = 1 && m = 1 && d BCS 230: Foundations of Computer Programming II CRN 90110, 90111 JL Fall 2018 Homework 4 - Wednesday, October 24 Due Saturday, November 10, 11:59PM on Blackboard Assignment Goals: To learn to use class inheritance and class composition to create new classes. A. (20 points) In Lab 6, you defined and implemented a class called Time. You will make some Assignment modifications to the lab 6 program so that it meets the following specifications: The class Time consists of three private member variables of type int: hour, minute, and second. The class Time also includes the following public member functions 1. print to print the hour, minute, and second in the format of HH-MM-ss. (Hint: consider using output manipulators set w and setfil1). 2. setTime to accept three int arguments and use them to set the hour, minute and second member variables. A valid value for hour is between 0 and 23, inclusively. A valid value for minute and second is between 0 and 59. For any invalid values, use 0 instead. 3. get Hour to return the value of hour 4. getMinute to return the value of minute 5. getSecond to return the value of minute. 6. An equals function that compares two Time objects. Return true if they are equal in hour, minate, and second, otherwise return false. The equals function has a formal parameter which is a Time object. 7. A constructor that accepts three int arguments and use them to initialize hour, minute and second. The three parameters have default value 0. Data validation should be considered. (Hints: Call the set Time member function with 3 arguments.) A copy constructor that creates a Time object by initializing it with an existing Time object. 8. B. (20 points) In Lab 7, you defined and implemented a class called Date. You will make some modification to the lab 7 program so that it meets the following specifications: The class Date consists of three private member variables year of type int, month of type int, and day of type int

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

Data Access Patterns Database Interactions In Object Oriented Applications

Authors: Clifton Nock

1st Edition

0321555627, 978-0321555625

More Books

Students also viewed these Databases questions

Question

h. What intercultural interaction occurred in the show?

Answered: 1 week ago