0

Here is the program I'm trying to run. These errors appear:

37:28 no matching function for call to...

52:67 error default argument given for parameter 1/2/3

I'm not sure how to fix them.

Also, on my header dataType.h I am getting these notes:

29:7 candidate expects 0 arguments, 1 provided

32:5 previous specification in ...

Are these notes something to worry about? If so, how can I fix them?

dataTypeImp.cpp

#ifndef dateType_H 
#define dateType_H
#include <iostream>
#include "dateType.h"
using namespace std;
    void dateType::setDate(int month, int day, int year) {
        dMonth = month;
        dDay = day;
        dYear = year;
    };
    //Function to set the date.
    //The member variables dMonth, dDay, and dYear are set 
    //according to the parameters
    //Postcondition: dMonth = month; dDay = day;
    //               dYear = year 

    int dateType::getDay() const {
        return dDay;
    }
    //Function to return the day.
    //Postcondition: The value of dDay is returned.

    int dateType::getMonth() const {
        return dMonth;
    }
    //Function to return the month.  
    //Postcondition: The value of dMonth is returned.

    int dateType::getYear() const {
        return dYear;
    }
    //Function to return the year.     
    //Postcondition: The value of dYear is returned.

    void dateType::printDate() const {
        cout << "Date: " << dMonth << "-" << dDay << "-" << dYear;
        if (isLeapYear(true)) {//**<<THIS IS ERROR 37:28**
            cout << "This is a leap year";
        }
        else {
            cout << "This is not a leap year";
        }
    }
    //Function to output the date in the form mm-dd-yyyy.

    bool isLeapYear(int dYear) {
        bool isLeapYear = (dYear%4);
        return isLeapYear;
    }
    //Function to determine whether the year is a leap year.

    dateType::dateType(int month = 1, int day = 1, int year = 1900) {
        setDate(month, day, year);//**^^THIS IS ERROR 52:67^^**
    }
    //Constructor to set the date
    //The member variables dMonth, dDay, and dYear are set 
    //according to the parameters
    //Postcondition: dMonth = month; dDay = day; 
    //               dYear = year
    //If no values are specified, the default values are 
    //used to initialize the member variables.
#endif

dataType.h

#ifndef date_H 
#define date_H
 
class dateType
{
public:
    void setDate(int month, int day, int year);
      //Function to set the date.
      //The member variables dMonth, dDay, and dYear are set 
      //according to the parameters
      //Postcondition: dMonth = month; dDay = day;
      //               dYear = year 

    int getDay() const;
      //Function to return the day.
      //Postcondition: The value of dDay is returned.

    int getMonth() const;
      //Function to return the month.  
      //Postcondition: The value of dMonth is returned.

    int getYear() const;
      //Function to return the year.     
      //Postcondition: The value of dYear is returned.

    void printDate() const;
      //Function to output the date in the form mm-dd-yyyy.

    bool isLeapYear(); //**<<THIS IS NOTE 29:7**
      //Function to determine whether the year is a leap year.

    dateType(int month = 1, int day = 1, int year = 1900);//**<<THIS IS NOTE 32:5**
      //Constructor to set the date
      //The member variables dMonth, dDay, and dYear are set 
      //according to the parameters
      //Postcondition: dMonth = month; dDay = day; 
      //               dYear = year
      //If no values are specified, the default values are 
      //used to initialize the member variables.

private:
    int dMonth;      //variable to store the month
    int dDay;        //variable to store the day
    int dYear;       //variable to store the year
};

#endif

main.cpp

#include <iostream>
#include "dateType.h"
using namespace std;

int main() {
    int month;      
    int day;       
    int year;

    //Verifying inputs then using get function
    dateType dDate;
    cout << "Please input a date in the format month-day-year"
    << "starting with month" << endl;
    cin >> month;
    while(month<1 || month>12 || cin.fail()) {
      cin.clear();
      cout << "Please enter a number between 1 and 12 for the month." << endl;
      cin >> month;
    }
    dDate.getMonth();

    //Verifying input then using get function

    cout << "Please enter a year" << endl;
    cin >> year;
    while(year<1 || cin.fail()) {
    cin.clear();
    cout << "Please enter a positive number for the year." << endl;
    cin >> year;
    }
    dDate.getYear();

    /*Using a switch to determine which months have how many days
    and to check if there is a leap year to include feb 29
    */

    switch(month) {
      case 1:
      case 3:
      case 5:
      case 7: 
      case 8: 
      case 10:
      case 12:
        cout << "Please enter a day of the month" << endl;
        cin >> day;
        while(day<1 || day>31 || cin.fail()) {
          cin.clear();
          cout << "Please enter a day of the month between 1 and 31" << endl;
          cin >> day;
        }
        break;
      case 4: 
      case 6:
      case 9: 
      case 11:
        cout << "Please enter a day of the month" << endl;
        cin >> day;
        while (day<1 || day>30 || cin.fail()) {
          cin.clear();
          cout << "Please enter a day of the month between 1 and 30" << endl;
          cin >> day;
        }
        break; 
      case 2:
        cout << "Please enter a day of the month" << endl;
        cin >> day;
        if(dDate.isLeapYear()){
          while(day<1 || day>29 || cin.fail()) {
            cin.clear();
            cout << "Please enter a day of the month between 1 and 29" << endl;
            cin >> day;
            }
        }else{
          while(day<1 || day>28 || cin.fail()) {
            cin.clear();
            cout << "Please enter a day of the month between 1 and 28" << endl;
            cin >> day;
          } 
        dDate.getDay();
        }
        break;
    }
    //end of switch
    dDate.setDate(month, day, year);
    dDate.printDate();
    return 0;
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Tyler
  • 1
  • 2
  • `isLeapYear(true)` did you mean to pass dYear here? isLeapYear takes an int. default parameters should only appear in the header file dont replicate them in the cpp. you declaration for leap year in the header doesnt match the definition in the cpp. – Borgleader Jun 12 '22 at 03:45
  • @Borgleader Id like to put a true or false value into the if (isLeapYear(true)). Id like to set the boolean to true or false based on if its a leap year, then print out in text if the year is a leap year – Tyler Jun 12 '22 at 04:02
  • isLeapYear returns true/false already why are you trying to pass a bool in? whats wrong with just `if (isLeapYear())`? – Borgleader Jun 12 '22 at 04:10
  • 1
    @Tyler `isLeapYear()` *takes in* a year integer as input, and *returns* a bool. You should not be passing in a `bool` to it. Seems you lack a fundamental understanding of how functions work. I suggest you consult your textbook. If you don't have one, you should get one: [The Definitive C++ Book Guide and List](https://stackoverflow.com/questions/388242/) – Remy Lebeau Jun 12 '22 at 04:11
  • 2
    Don't use include guards in .cpp files. – n. m. could be an AI Jun 12 '22 at 04:37
  • @RemyLebeau I only have that value in there because everything else I've tried is not working and it was out on a limb. I still get dateTypeImp.cpp error 37:28 when I have it as so ``` bool isLeapYear(int dYear) { if(dYear%4 ==0 ){ return true; }else{ return false; } } – Tyler Jun 12 '22 at 23:27
  • @Tyler see the answer I just posted. – Remy Lebeau Jun 13 '22 at 00:11

1 Answers1

1

Your dateType class declares a non-static member method isLeapYear() which does not take any input parameters (and BTW, should be declared as const).

But your dataTypeImp.cpp file does not define that method. Instead, it declares+defines a standalone isLeapYear() function which does take an input parameter.

Your code inside of the dateType::printDate() method is trying to call this standalone function with an input value, but that function has not been declared yet at that point in the code, so the compiler tries to call the dateType::isLeapYear() method instead, which fails since the parameter doesn't match what the method is expecting (ie, nothing).

So, to fix this, change the standalone function into a proper definition for the dateType::isLeapYear() method, and then fix printDate() to remove the input parameter.

void dateType::printDate() const {
    ...
    if (isLeapYear()) {
       ...
    }
    else {
       ...
    }
}

bool dateType::isLeapYear() const {
    return (dYear%4 == 0);
}

Also, note that your algorithm to determine a leap year is incomplete. Not all years that are divisible by 4 are leap years. You need to take centuries into account, too:

https://en.wikipedia.org/wiki/Leap_year

For example, in the Gregorian calendar, each leap year has 366 days instead of 365, by extending February to 29 days rather than the common 28. These extra days occur in each year which is an integer multiple of 4 (except for years evenly divisible by 100, but not by 400).

bool dateType::isLeapYear() const {
    return ((dYear % 4 == 0) && ((dYear % 100 != 0) || (dYear % 400 == 0)));
}
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770