Assignemnt 2
Assignemnt 2
Assignemnt 2
Code:
#include <iostream>
#include <string>
class Date{
private:
int month;
int day;
int year;
public:
if(d>0 || d<=31){
day = d;
if(m>0 || m<=12){
month = m;
if(y>=1900){
year = y;
}
if(d>0 || d<=31){
day = d;
if(m>0 || m<=12){
month = m;
if(y>=1900){
year = y;
}}
Date(){month = 1;
year = 1900;
day = 1;
return day;
return month;
return year;
if(day>0 || day<=31)
this->day = day;
if(month>0 || month<=31)
this->month = month;
if(year>1900)
this->year = year;
void printDate(){
cout<<year<<"/";
if(month>9){
cout<<month<<"/";
}else{
cout<<"0"<<month<<"/";
if(day>9){
cout<<day;
}else{
cout<<"0"<<day;
}}};
int main() {
Date dateDefault;
date.printDate();
int m,y,d;
cin>>m;
cin>>d;
cin>>y;
dateDefault.setDate(m,d,y);
dateDefault.printDate();
Task#2
#include <iostream>
#include <string>
using namespace std;
class Date{
private:
int month;
int day;
int year;
public:
if(d>0 || d<=31){
day = d;
if(m>0 || m<=12){
month = m;
}
if(y>=1900){
year = y;
if(d>0 || d<=31){
day = d;
if(m>0 || m<=12){
month = m;
if(y>=1900){
year = y;
}}
Date(){month = 1;
year = 1900;
day = 1;
return day;
return month;
return year;
}
if(day>0 || day<=31)
this->day = day;
if(month>0 || month<=31)
this->month = month;
if(year>1900)
this->year = year;
void printDate(){
cout<<year<<"/";
if(month>9){
cout<<month<<"/";
}else{
cout<<"0"<<month<<"/";
if(day>9){
cout<<day;
}else{
cout<<"0"<<day;
}}};
Employee headerfile:
#include<iostream>
#include<string.h>
#include"date.h"
class Employee{
protected:
char firstname[25];
char lastname[25];
Date birthDate;
Date hireDate;
public:
strcpy(firstname,first);
strcpy(lastname,last);
birthDate=Bday;
hireDate=Hday;
void print(){
birthDate.printDate();
cout<<endl;
hireDate.printDate();
cout<<endl;
};
Main code:
#include<iostream>
#include<string.h>
#include"employee.h"
int main(){
Date birth(7,24,1949);
Date hire(3,12,1988);
Employee manager("bob","blue",birth,hire);
manager.print();
return 0;
Task#3
Code:
#include<iostream>
class Count{
private:
int x;
public:
Count() : x(0) {}
};
C.x=50;
return C.x;
int main(){
Count C;
return 0;