C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
Expert Solution & Answer
Book Icon
Chapter 13, Problem 8SA

Explanation of Solution

The class dateType has a friend function declared in its definition. The friend function is then defined with two parameters of dateType and a bool return type. The logic of the function is explained with the in-lined comments in the program given below.

//class definition

class dateType

{

    //declare the friend function in the class definition

    friend bool before(dateType d1, dateType d2);

    public:

        void setDate(int month, int day, int year);

        int getDay() const;

        int getMonth() const;

        int getYear() const;

        void printDate() const;

        bool isLeapYear(int) const;

        dateType(int month = 1, int day = 1, int year = 1900);

    private:

        int dMonth; //variable to store the month

        int dDay; //variable to store the day

        int dYear; //variable to store the year

};

//define the friend function

bool before(dateType d1, dateType d2){

    //if the year of first object is strictly less

    //than the year of second object return true

    //else if the year of the first object is

    //strictly more than the year of the second

    //object return false else if there is a tie

    //then compare the months

    if (d1...

Blurred answer
Students have asked these similar questions
Write a class Travel having two private data members (distanceCovered , Time) The class has three constructors which are • having no parameter – for setting values to zero or null. • having two parameters for assigning values to both data members. • Overload the above constructor and use this keyword to set the values of data members. • Provide getters/setters for data members. • A function which calculates and display speed of traveling. • Write a function show() displays values.   Write test Application that demonstrates the Run class by calling all the three constructors and method, creating a Create Travel objects, and then display the traveling with speed. Calculate highest speed. Programming language : java
a. Write the specification (i.e., what would be in a header file) for a class called studentType. Code the data member section (as private) and the function prototypes (as public). You do not need to write any include, using or other directives. Include the following: Data: Student First Name Student Last Name Student gpa Student ID Functions: Default constructor Set the first name Get the first name Set the last name Get the last name Set the gpa Get the gpa Set the ID Get the ID b. Create an object of studentType using the default constructor. 3.
Create an Employee class that includes three private data members— firstName (type string), lastName (type string), and monthlySalary (type int ).It also includes several public member functions.1. A constructor initializes the three data members. 2. A setFirstName function accepts a string parameter and does not return any data. It sets the firstName.3. A getFirstName function does not accept any parameter and returns a string. It returns the firstName.4. A setLastName function accepts a string parameter and does not return any data. It sets the lastName.5. A getLastName function does not accept any parameter and returns a string. It returns the lastName.6. A setMonthlySalary function accepts an integer parameter and does not return any data. It sets the monthlySalary. If the monthly salary is less than or equal zero, set it to 1000 and it displays the employee’s first name, last name and the inputted salary with a statement “**==The salary is set to $1000.”7. A getMonthlySalary…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning