using overloaded constructors

This is a discussion on using overloaded constructors within the C++ Programming forums, part of the General Programming Boards category; i dont know how this stuff is supposed to work... my error comes up in the member function definitions for ...

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    8

    Angry using overloaded constructors

    i dont know how this stuff is supposed to work... my error comes up in the member function definitions for date class page. This is the error --> c:\c++\exercise7_07\chapter7.cpp(14) : error C2660: 'setdate' : function does not take 2 parameters.

    the point of the program is to output a date in multiple formats(ddd yyyy, mm/dd/yy, June 14, 1992). Use overloaded constructors to create Date objects initialized with dates of the formats in part (a) and create a date constructor hat reads the system date using the standerd library function time.h and sets the date members.(havent started the last part yet) please help ASAP!!!

    this is what i have so far -->

    //header file

    //Declaration of the Date class
    //Member functions defined in chapter7.cpp

    //preprocessor directives that prevent multiple inclusions of
    //header files

    #ifndef EXERCISE7_07_h
    #define EXERCISE7_07_h

    class date {
    public:
    date(int, int, int); //constructors
    date(int, int);
    date(char, int, int);
    date();

    //set functions

    void setdate(int, int, int); //sets month, day, year
    void setmonth(int); //sets month
    void setday(int); //sets day
    void setyear(int); //sets year

    //get functions

    int getmonth(); //return month
    int getday(); //return day
    int getyear(); //return year

    void printwords(); //output in form of June 14, 1992
    void printnumbers(); //output in form of MM/DD/YY
    void printjulian(); //output in form of DDD YYYY



    private:
    int month; // 01-12
    int day; // 1-31
    int year; // year
    };


    #endif


    //.cpp file #1

    //member function definitions for Time class

    #include<iostream>
    #include"exercise7_07.h"

    using std::cout;

    date::date( int month, int day, int year)
    { setdate (month, day, year); }
    date::date( int day, int year)
    { setdate (day, year); }
    date::date( char month, int day, int year)
    { setdate (month, day, year); }

    //set the values of month, day, year

    void date::setdate( int dd, int mm, int yyyy)
    {
    setday(dd);
    setmonth(mm);
    setyear(yyyy);
    }

    //set day value
    void date::setday(int dd)
    { day= (dd>=1 && dd<=31) ? dd : 0;}

    //set month value
    void date::setmonth(int mm)
    { month= (mm<=01 && mm<=12) ? mm : 0;}

    //set year value
    void date::setyear(int yy)
    { year= yy;}

    //get day value
    int date::getday() {return day;}

    //get month value
    int date::getmonth() {return month;}

    //get year value
    int date::getyear() {return year;}

    //prints date in MM/DD/YY format
    void date::printnumbers()
    {
    cout << month << "/" << day << "/" << year;
    }

    //prints date in worded format
    void date::printwords()
    {
    char *newmonth[13]{" ", "January","February","March","April","May","June", "July","August","September","October","November"," December"}

    if (month==1)
    cout << newmonth[1] <<" " <<day <<"," <<year;
    if (month==2)
    cout << newmonth[2] <<" " <<day <<"," <<year;
    if (month==3)
    cout << newmonth[3] <<" " <<day <<"," <<year;
    if (month==4)
    cout << newmonth[4] <<" " <<day <<"," <<year;
    if (month==5)
    cout << newmonth[5] <<" " <<day <<"," <<year;
    if (month==6)
    cout << newmonth[6] <<" " <<day <<"," <<year;
    if (month==7)
    cout << newmonth[7] <<" " <<day <<"," <<year;
    if (month==8)
    cout << newmonth[8] <<" " <<day <<"," <<year;
    if (month==9)
    cout << newmonth[9] <<" " <<day <<"," <<year;
    if (month==10)
    cout << newmonth[10] <<" " <<day <<"," <<year;
    if (month==11)
    cout << newmonth[11] <<" " <<day <<"," <<year;
    if (month==12)
    cout << newmonth[12] <<" " <<day <<"," <<year;
    }
    }

    //prints date in Julian format
    void date::printjulian()
    {
    int JulDay;

    if (month==1)
    JulDay =day;
    if (month==2)
    JulDay = day + 31;
    if (month==3)
    JulDay = day + 31 + 28;
    if (month==4)
    JulDay = day + 31 + 28 + 31;
    if (month==5)
    JulDay = day + 31 + 28 + 31 + 30;
    if (month==6)
    JulDay = day + 31 + 28 + 31 + 30 + 31;
    if (month==7)
    JulDay = day + 31 + 28 + 31 + 30 + 31 + 30;
    if (month==8)
    JulDay = day + 31 + 28 + 31 + 30 + 31 + 30 + 31;
    if (month==9)
    JulDay = day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31;
    if (month==10)
    JulDay = day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;
    if (month==11)
    JulDay = day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;
    if (month==12)
    JulDay = day + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30;

    cout << JulDay << " " << year << "\n";
    }


    //.cpp file #2

    #include <iostream>
    #include "exercise7_07.h"

    int main(void)
    {
    date d;

    d.setday(31);
    d.setmonth(3);
    d.setyear(1994);

    d.getday();
    d.getmonth();
    d.getyear();

    d.printjulian();
    d.printnumbers();
    d.printwords();

    return 0;
    }


    the error is happening is the first .cpp file, int the lines
    date::date( int day, int year)
    { setdate (day, year); }
    I know that setdate needs 3 parameters, but i dont see where the third one is supposed to some from!!
    Last edited by Alicia; 02-11-2002 at 01:13 PM.

  2. #2
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    //set functions

    void setdate(int, int, int); //sets month, day, year
    void setmonth(int); //sets month
    void setday(int); //sets day
    void setyear(int); //sets year


    { setdate (day, year); }//does this exist???

  3. #3
    _B-L-U-E_ Betazep's Avatar
    Join Date
    Aug 2001
    Posts
    1,412
    use [ code ] tags for your code... it makes it a lot easier to read

    Code:
    This is stuff in a code tag ( [ code ] and [ /code ] without the spaces)
    Blue

  4. #4
    Unregistered
    Guest

    Smile some suggestions

    hi,

    Also , If you want to read the system time and print them in three ways, why do you need the overloading of constructors. You simply use only one constructor and call different methods for different formats.{I don't see you are using them any way.}

    Still if you want them,

    You may want to change the constructor with two parameters to something like this

    date(int day,char month, int year){
    //then pass params correctly
    setdate(month,day,year);
    }

    Assumes proper values are entered while reading for correct type casting.

    Note:
    In setmonth(int), you may want to change the condition to
    mm>=01 . The current condition is incorrect.

    Hope this helps.
    Future Member

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 04:45 PM
  3. overloaded >> operator issue...
    By soulredemption in forum C++ Programming
    Replies: 2
    Last Post: 10-17-2005, 10:53 PM
  4. overloaded on overloads
    By emceedee in forum C++ Programming
    Replies: 1
    Last Post: 03-31-2003, 01:14 AM
  5. Copy constructors and private constructors
    By Eibro in forum C++ Programming
    Replies: 5
    Last Post: 11-24-2002, 09:16 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21