Hi guys
where is the problem with that simple class program:

#include<iostream>
#include<conio.h>
using namespace std;
class DayOfYear
{
      public:
             DayOfYear(int month,int day);
             void output();
             void input();
      private:
              int month_year;
              int day_year;
};
DayOfYear::DayOfYear(int month,int day)
{
    month_year=month;
    day_year=day;
}
void DayOfYear::output()
{
     cout<<month_year<<"/"<<day_year;
}
void DayOfYear::input()
{
     cout<<"What's your month of birthday : ";
     cin>>month_year;
     cout<<"What's your day of birthday : ";
     cin>>day_year;
}


int main()
{
    cout<<"The program will use class and a regular function and represent some kind of connection between them"<<endl;
    DayOfYear bach_birthday(3,21),my_birthday;
    cout<<"The birth of Bach is : ";
    bach_birthday.output();
    cout<<"\nNow I will ask you about your birthday"<<endl;
    cout<<"What is your month and day of birthday : ";
    my_birthday.input();
    my_birthday.output();     

    getch();
    return 0;
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

You tell us..? we're not mind readers.

What problem are you having? does it compile? if not, what error message(s) do you get?

Can't you copy it and try to compile yourself. wouldn't be much easier and simpler and more readable. Anyway ,this program doesn't compile. There is an error message:
41 no matching function for call to `DayOfYear::DayOfYear()'
Do you know what is it mean
Thanks

I could - but there's no guarantee that what happens when I try compiling & running it, is going to be the same as what happens when you try compiling & running it (Especially not when you've missed out CODE tags, and your code has got forum icons in it... )

The error you're getting is because the compiler can't find a default constructor in the DayOfYear class.

When you write your own constructor, the default constructor is no longer available automatically, so you either have to make one, or change your code in main, so that its using the constructor you've already written..

DayOfYear bach_birthday(3,21),my_birthday;

Edited 3 Years Ago by pyTony: fixed formatting

Hej
And one more question. I understand what you are saying, but I don't know how to aplay it. How may I create new default constructor and where can I place it, that everything will work in that particular program.
Thanks a lot

Just create a constructor in your DayOfYear class, which takes no parameters... just like you've done here

#include<iostream>
#include<conio.h>
using namespace std;
class DayOfYear
{
public:
[B]    DayOfYear(int month,int day);[/B]
    void output();
    void input();
private:
    int month_year;
    int day_year;
};
[B]DayOfYear::DayOfYear(int month,int day)
{
    month_year=month;
    day_year=day;
}[/B]
void DayOfYear::output()
{
    cout<<month_year<<"/"<<day_year;
}
void DayOfYear::input()
{
    cout<<"What's your month of birthday : ";
    cin>>month_year;
    cout<<"What's your day of birthday : ";
    cin>>day_year;
}
This question has already been answered. Start a new discussion instead.