C++ Provide a default constructor for program

Provide a default constructor for program

Page 1 of 1

2 Replies - 5517 Views - Last Post: 09 September 2009 - 05:22 AM Rate Topic: -----

#1 need_helpp   User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 72
  • Joined: 08-September 09

C++ Provide a default constructor for program

Posted 08 September 2009 - 08:43 PM

//Provide a default constructor for program

#include <iostream>
#include <iomanip> 
using namespace std;

class date 
{
public:
void AssignDate (int, int, int);
void DisplayNumeric ( void);
void DisplayVerbal (void); 
private:
int month, day, year;
};
void date::AssignDate (int m, int d, int y)
{
month = m;
day = d;
year = y;
}
void date::DisplayNumeric (void)
{
cout<<"Numerical form is ";
if ( (year%100)<10)
{
cout<<month<< '/'<<day<< "/0"<< (year % 100)<<endl;
}
else
{
cout<<month<< '/'<<day<< '/'<< (year % 100)<<endl;
}
}
void date::DisplayVerbal (void)
{
cout<<"Verbal form is ";
switch (month)
{
case 1: cout<< "January";
break;
case 2: cout<< "February";
break;
case 3: cout<< "March";
break; 

case 4: cout<< "April";
break;
case 5: cout<< "May";
break;
case 6: cout<< "June";
break;
case 7: cout<< "July";
break;
case 8: cout<< "August";
break;
case 9: cout<< "Septmember";
break;
case 10: cout<< "October";
break;
case 11: cout<< "November";
break;
case 12: cout<< "December";
break;
}
cout<<' '<< day<< ", "<< year<<endl;
}
int main (void)
{
date NewYear, Easter, MemorialDay, IndependenceDay,
LaborDay, Thanksgiving, Christmas;
int input_month,
input_day,
input_year;
cout<< "Enter NewYear values of month, year and day." 
<<endl;
cin>> input_month >> input_day >> input_year;
NewYear.AssignDate (input_month, input_day, input_year);
NewYear.DisplayNumeric( );
NewYear.DisplayVerbal( );
cout<< "Enter Easter values of month, year and day."
<<endl;
cin>> input_month >> input_day >> input_year; 
Easter.AssignDate (input_month, input_day, input_year);
Easter.DisplayNumeric( );
Easter.DisplayVerbal( );
cout<< "Enter MemorialDay values of month, year and day." <<endl;
cin>> input_month >> input_day >> input_year; 
MemorialDay.AssignDate (input_month, input_day, input_year);
MemorialDay.DisplayNumeric( );
MemorialDay.DisplayVerbal( ); 
return 0; 
}


*** MOD EDIT: Added code tags. Please :code: ***

This post has been edited by JackOfAllTrades: 09 September 2009 - 05:12 AM


Is This A Good Question/Topic? 0
  • +

Replies To: C++ Provide a default constructor for program

#2 KYA   User is offline

  • Wubba lubba dub dub!
  • member icon

Reputation: 3202
  • View blog
  • Posts: 19,234
  • Joined: 14-September 07

Re: C++ Provide a default constructor for program

Posted 08 September 2009 - 08:45 PM

If none are provided the compiler will generally provide a default constructor. This looks like a homework assignment, therefore all i will say on the subject is that a default constructor (that the programmer provides) is simply one that takes no arguments and initializes all values to some default.
Was This Post Helpful? 0
  • +
  • -

#3 learnplaycreate   User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 119
  • Joined: 27-August 09

Re: C++ Provide a default constructor for program

Posted 09 September 2009 - 05:22 AM

this will help, it explains oop basics clearly and includes a whole section on constructors:
http://www.dreaminco...owtopic9873.htm
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1