Answer to Question #324650 in C++ for Amy

Question #324650

Create a program that will perform the default constructor.


1
Expert's answer
2022-04-06T05:07:39-0400
#include <iostream>
#include <string>
 
using namespace std;
 
class Date {

public:
//default constructor
   Date(){
      day = 1;
      month = 1;
      year = 2000;
   }
 
void setdate(int d , int m, int y){
      day = d;
      month = m;
      year = y;
}

string Month(int n){
    string m[12]={"January","February.","March","April","May","June","July","August",
                    "September","October","November","December"};
    return m[n-1];
}
void show(){
    cout<<day<<" "<<Month(month)<<" "<<year<<endl;
}

private:
   int day;
   int month;
   int year;
};
 
int main()
{
    Date myData;
    myData.show();
    
    myData.setdate(21,1,1961);
    myData.show();
    
    cout << endl;
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS