struct procedure
{
Date dateOfProcedure;
int procedureID;
int procedureProviderID;
};
Data.h
#include
#include
class Date
{
friend ostream& operator<<( ostream &, const Date & );
// allows easy output to a ostream
public:
Date( int m = 1, int d = 1, int y = 1900 ); // constructor, note the default values
void setDate( int, int, int ); // set the date const
Date &operator+=( int ); // add days, modify object
bool leapYear( int) const; // is this a leap year?
bool endOfMonth( int ) const; // is this end of month?
int getMonth ( ) const;
int getDay ( ) const;
int getYear ( ) const;
string getMonthString( ) const;
private:
int month;
int day;
int year;
static const int days[]; // array of days per month static const string monthName[]; // array of
month names
void helpIncrement();
// utility function
}; #endif Data.cpp // Member function definitions for Date
class in separate
date.cpp
#include
#include \"date.h\"
#include // Initialize static members at file scope; // one class-wide copy.
const int Date::days[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; const string
Date::monthName[] = { \"January\", \"February\", \"March\", \"April\", \"May\", \"June\",
\"July\", \"August\", \"September\", \"October\", \"November\", \"December\" };
// Date constructor
Date::Date(int m, int d, int y)
{
setDate(m, d, y); } // Set the date
void Date::setDate(int mm, int dd, int yy)
{
month = (mm >= 1 && mm <= 12) ? mm : 1; year = (yy >=1900&& yy <= 2100) ? yy
: 1900; // test for a leap year
if (month == 2 && leapYear(year)) day = (dd >= 1 && dd <= 29) ? dd : 1;
else
day =(dd >= 1 && dd <= days[month]) ? dd : 1;
} // Add a specific number of days to a date
const Date &Date::operator+=(int additionalDays)
{
for (int i = 0; i < additionalDays; i++) helpIncrement();
return *this; // enables cascading
} // If the year is leap year, return true; //
otherwise, return false
bool Date::leapYear(int testYear)
const
{
if (testYear % 400 == 0 || (testYear %100 != 0 && testYear % 4 == 0)) return true; // a
leap year
else
return false; // not a leap year
} // Determine if the day is the end of the month
bool Date::endOfMonth(int testDay)
const
{
if (month == 2 && leapYear(year))
return (testDay == 29); // last day of Feb. in leap year
else
return (testDay == days[month]);
} // Function to help increment the date
void Date::helpIncrement()
{
if (!endOfMonth(day))
{
// date is not at the end of the month
day++;
}
else if (month < 12)
{
// date is at the end of the month, but month < 12 day = 1; ++month;
}
else
{
// end of month and year: last day of the year
day = 1;
month = 1;
++year;
} }
// Overloaded output operator
ostream &operator<<(ostream& output, const Date &d)
{
output << d.monthName[d.month] << \' \' << d.day << \", \"<< d.year;
return output; // enables cascading
}
int Date::getMonth() const //
{
Public:
int month[20];
If(month[]!=”/0”)
Cout<<”Enter Month :-<>month;
Elseif (month[]<12)
{
Cout<>month[];
else
return month;
}
int Date::getDay() const //
{
Pu.
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
struct procedure { Date dateOfProcedure; int procedureID.pdf
1. struct procedure
{
Date dateOfProcedure;
int procedureID;
int procedureProviderID;
};
Data.h
#include
#include
class Date
{
friend ostream& operator<<( ostream &, const Date & );
// allows easy output to a ostream
public:
Date( int m = 1, int d = 1, int y = 1900 ); // constructor, note the default values
void setDate( int, int, int ); // set the date const
Date &operator+=( int ); // add days, modify object
bool leapYear( int) const; // is this a leap year?
bool endOfMonth( int ) const; // is this end of month?
int getMonth ( ) const;
int getDay ( ) const;
int getYear ( ) const;
string getMonthString( ) const;
private:
int month;
int day;
int year;
static const int days[]; // array of days per month static const string monthName[]; // array of
month names
void helpIncrement();
// utility function
}; #endif Data.cpp // Member function definitions for Date
class in separate
2. date.cpp
#include
#include "date.h"
#include // Initialize static members at file scope; // one class-wide copy.
const int Date::days[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; const string
Date::monthName[] = { "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" };
// Date constructor
Date::Date(int m, int d, int y)
{
setDate(m, d, y); } // Set the date
void Date::setDate(int mm, int dd, int yy)
{
month = (mm >= 1 && mm <= 12) ? mm : 1; year = (yy >=1900&& yy <= 2100) ? yy
: 1900; // test for a leap year
if (month == 2 && leapYear(year)) day = (dd >= 1 && dd <= 29) ? dd : 1;
else
day =(dd >= 1 && dd <= days[month]) ? dd : 1;
} // Add a specific number of days to a date
const Date &Date::operator+=(int additionalDays)
{
for (int i = 0; i < additionalDays; i++) helpIncrement();
return *this; // enables cascading
} // If the year is leap year, return true; //
otherwise, return false
bool Date::leapYear(int testYear)
const
{
if (testYear % 400 == 0 || (testYear %100 != 0 && testYear % 4 == 0)) return true; // a
leap year
else
return false; // not a leap year
} // Determine if the day is the end of the month
bool Date::endOfMonth(int testDay)
const
{
3. if (month == 2 && leapYear(year))
return (testDay == 29); // last day of Feb. in leap year
else
return (testDay == days[month]);
} // Function to help increment the date
void Date::helpIncrement()
{
if (!endOfMonth(day))
{
// date is not at the end of the month
day++;
}
else if (month < 12)
{
// date is at the end of the month, but month < 12 day = 1; ++month;
}
else
{
// end of month and year: last day of the year
day = 1;
month = 1;
++year;
} }
// Overloaded output operator
ostream &operator<<(ostream& output, const Date &d)
{
output << d.monthName[d.month] << ' ' << d.day << ", "<< d.year;
return output; // enables cascading
}
int Date::getMonth() const //
{
Public:
int month[20];
4. If(month[]!=”/0”)
Cout<<”Enter Month :-<>month;
Elseif (month[]<12)
{
Cout<>month[];
else
return month;
}
int Date::getDay() const //
{
Public :
int day[20];
if(day[]!=”/0”)
{
cout<<”Enter day :”<>day[];
}
Else if(day>31)
{
Cout<>day[];
}
else
return day;
}
int Date::getYear() const //
{
Public :
int year[1000];
If(year[]!=”/0”)
{
Cout<<”Enter year:”<>year[];
Else
{
return year;
}
5. string Date::getMonthString() const//
{
Public:
String monthname[20];
if(monthname[]!=”/0”)
{
Cout<>monthname[];
}
Else
return monthName[month];
}
patient.h
#pragma once
#include
#include
#include "date.h" /*#ifndef PATIENT1_H #define PATIENT1_H */
class Patient
{
struct procedure
{
Date dateOfProcedure; int procedureID;
int procedureProviderID;
};
public:
Patient(const char * id=0, const char * first="null", const char * last="null", Date
birth=1900, int doctor=0);
//Put in default values just as in Date class //Use the set functions so input values are
checked
~Patient();
Patient & setID(); //check if length of name string is < 32. // if not, shorten to 32 letters.
Patient & setFirstName(const char * first); //check if length of name string is < // 15, if not,
shorten to 14 letters.
Patient & setLastName(const char *last); //check if length of name string is < // 15, if not,
6. shorten to 14 letters.
Patient& setBirthDate(Date);
Patient & setPrimaryDoctorID(int);
const char * getID();
const char * getFirstName();
const char * getLastName();
Date getBirthDate();
int getPrimaryDoctorID(); // Patient& operator=(Patient other); bool enterProcedure(Date
procedureDate, int procedureID,int procedureProviderID);//tries to add a new entry to record
array, returns //true if added, false if cannot be added
void printAllProcedures();
void display();
private:
char ID[33];
char firstName[15];
char lastName[15];
Date birthdate;
int primaryDoctorID;
procedure record[100];
int currentCountOfProcedures; // keeps track of how many procedures have //been recorded. if it
reaches 500, no new procedures can //be entered.
};
patient.cpp
#include "Patient.h"
#include
#include
Patient::Patient(const char* , const char * first, const char * last, Date birth, int doctor)
{
setID(); setFirstName(first); setLastName(last); setBirthDate(birth);
setPrimaryDoctorID(doctor);
}
Patient::~Patient()
{ }
Patient &Patient::setID()
{
7. char hold[33];
memcpy(hold, getLastName(), 15);
strcat_s(hold, getFirstName());
int birthYear = birthdate.getYear();
char holdYearC[5]; sprintf_s(holdYearC, "%d", birthYear); strcat_s(hold,
holdYearC); memcpy(this->ID, hold, 33);
return(*this);
}
Patient& Patient::setFirstName(const char *first) //check if length of name string is <
{
if (strlen(first) > 15)
strncpy(firstName, first, 14);
else
strcpy(firstName, first); return *this;
} // 15, if not, shorten to 14 letters.
Patient& Patient::setLastName(const char *last) //check if length of name string is <
{
if (strlen(last) > 15)
strncpy(lastName, last, 14);
else
strcpy(lastName, last); return *this;
} // 15, if not, shorten to 14 letters.
Patient &Patient::setBirthDate(Date birth)
{
birthdate = birth; return *this;
}
Patient& Patient::setPrimaryDoctorID(int doctor)
{
primaryDoctorID = doctor; return *this;
}
const char *Patient::getID()
{ return ID; }
const char *Patient::getFirstName()
{ return firstName; }
const char *Patient::getLastName()
{ return lastName; }
8. Date Patient::getBirthDate()
{ return birthdate; }
int Patient::getPrimaryDoctorID()
{ return primaryDoctorID; }
bool Patient::enterProcedure(Date procedureDate, int procedureID,int
procedureProviderID)//tries to add a new entry to record array, returns //true if added, false if
cannot be added
{
if (currentCountOfProcedures > 100)
{
cout << "Cannot add any more procedure" << endl;
return false;
} else
{
record[currentCountOfProcedures].dateOfProcedure = procedureDate;
record[currentCountOfProcedures].procedureID = procedureID;
record[currentCountOfProcedures].procedureProviderID =
procedureProviderID;
currentCountOfProcedures++;
return true;
} }
void Patient::printAllProcedures()
{
cout << "Procedures of patient" << endl;
for (int i = 0; i < currentCountOfProcedures; i++)
{
cout << "Date of Procedure: " << record[i].dateOfProcedure << endl;
cout << "Procedure ID: " << record[i].procedureID << endl;
cout<< "Procedure Provider ID: " << record[i].procedureProviderID
<< endl;
}
Void Patient::display()
{
Public :
Int Current_date[30];
Cout<>FirstName[];
9. Cout<>LasrName[];
Cout <>BirthDate[];
Cout <
Solution
struct procedure
{
Date dateOfProcedure;
int procedureID;
int procedureProviderID;
};
Data.h
#include
#include
class Date
{
friend ostream& operator<<( ostream &, const Date & );
// allows easy output to a ostream
public:
Date( int m = 1, int d = 1, int y = 1900 ); // constructor, note the default values
void setDate( int, int, int ); // set the date const
Date &operator+=( int ); // add days, modify object
bool leapYear( int) const; // is this a leap year?
bool endOfMonth( int ) const; // is this end of month?
int getMonth ( ) const;
int getDay ( ) const;
int getYear ( ) const;
string getMonthString( ) const;
private:
int month;
int day;
int year;
static const int days[]; // array of days per month static const string monthName[]; // array of
month names
void helpIncrement();
10. // utility function
}; #endif Data.cpp // Member function definitions for Date
class in separate
date.cpp
#include
#include "date.h"
#include // Initialize static members at file scope; // one class-wide copy.
const int Date::days[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; const string
Date::monthName[] = { "January", "February", "March", "April", "May", "June",
"July", "August", "September", "October", "November", "December" };
// Date constructor
Date::Date(int m, int d, int y)
{
setDate(m, d, y); } // Set the date
void Date::setDate(int mm, int dd, int yy)
{
month = (mm >= 1 && mm <= 12) ? mm : 1; year = (yy >=1900&& yy <= 2100) ? yy
: 1900; // test for a leap year
if (month == 2 && leapYear(year)) day = (dd >= 1 && dd <= 29) ? dd : 1;
else
day =(dd >= 1 && dd <= days[month]) ? dd : 1;
} // Add a specific number of days to a date
const Date &Date::operator+=(int additionalDays)
{
for (int i = 0; i < additionalDays; i++) helpIncrement();
return *this; // enables cascading
} // If the year is leap year, return true; //
otherwise, return false
bool Date::leapYear(int testYear)
const
{
if (testYear % 400 == 0 || (testYear %100 != 0 && testYear % 4 == 0)) return true; // a
leap year
else
return false; // not a leap year
11. } // Determine if the day is the end of the month
bool Date::endOfMonth(int testDay)
const
{
if (month == 2 && leapYear(year))
return (testDay == 29); // last day of Feb. in leap year
else
return (testDay == days[month]);
} // Function to help increment the date
void Date::helpIncrement()
{
if (!endOfMonth(day))
{
// date is not at the end of the month
day++;
}
else if (month < 12)
{
// date is at the end of the month, but month < 12 day = 1; ++month;
}
else
{
// end of month and year: last day of the year
day = 1;
month = 1;
++year;
} }
// Overloaded output operator
ostream &operator<<(ostream& output, const Date &d)
{
output << d.monthName[d.month] << ' ' << d.day << ", "<< d.year;
return output; // enables cascading
}
int Date::getMonth() const //
{
12. Public:
int month[20];
If(month[]!=”/0”)
Cout<<”Enter Month :-<>month;
Elseif (month[]<12)
{
Cout<>month[];
else
return month;
}
int Date::getDay() const //
{
Public :
int day[20];
if(day[]!=”/0”)
{
cout<<”Enter day :”<>day[];
}
Else if(day>31)
{
Cout<>day[];
}
else
return day;
}
int Date::getYear() const //
{
Public :
int year[1000];
If(year[]!=”/0”)
{
Cout<<”Enter year:”<>year[];
13. Else
{
return year;
}
string Date::getMonthString() const//
{
Public:
String monthname[20];
if(monthname[]!=”/0”)
{
Cout<>monthname[];
}
Else
return monthName[month];
}
patient.h
#pragma once
#include
#include
#include "date.h" /*#ifndef PATIENT1_H #define PATIENT1_H */
class Patient
{
struct procedure
{
Date dateOfProcedure; int procedureID;
int procedureProviderID;
};
public:
Patient(const char * id=0, const char * first="null", const char * last="null", Date
birth=1900, int doctor=0);
//Put in default values just as in Date class //Use the set functions so input values are
checked
~Patient();
14. Patient & setID(); //check if length of name string is < 32. // if not, shorten to 32 letters.
Patient & setFirstName(const char * first); //check if length of name string is < // 15, if not,
shorten to 14 letters.
Patient & setLastName(const char *last); //check if length of name string is < // 15, if not,
shorten to 14 letters.
Patient& setBirthDate(Date);
Patient & setPrimaryDoctorID(int);
const char * getID();
const char * getFirstName();
const char * getLastName();
Date getBirthDate();
int getPrimaryDoctorID(); // Patient& operator=(Patient other); bool enterProcedure(Date
procedureDate, int procedureID,int procedureProviderID);//tries to add a new entry to record
array, returns //true if added, false if cannot be added
void printAllProcedures();
void display();
private:
char ID[33];
char firstName[15];
char lastName[15];
Date birthdate;
int primaryDoctorID;
procedure record[100];
int currentCountOfProcedures; // keeps track of how many procedures have //been recorded. if it
reaches 500, no new procedures can //be entered.
};
patient.cpp
#include "Patient.h"
#include
#include
Patient::Patient(const char* , const char * first, const char * last, Date birth, int doctor)
{
setID(); setFirstName(first); setLastName(last); setBirthDate(birth);
setPrimaryDoctorID(doctor);
}
15. Patient::~Patient()
{ }
Patient &Patient::setID()
{
char hold[33];
memcpy(hold, getLastName(), 15);
strcat_s(hold, getFirstName());
int birthYear = birthdate.getYear();
char holdYearC[5]; sprintf_s(holdYearC, "%d", birthYear); strcat_s(hold,
holdYearC); memcpy(this->ID, hold, 33);
return(*this);
}
Patient& Patient::setFirstName(const char *first) //check if length of name string is <
{
if (strlen(first) > 15)
strncpy(firstName, first, 14);
else
strcpy(firstName, first); return *this;
} // 15, if not, shorten to 14 letters.
Patient& Patient::setLastName(const char *last) //check if length of name string is <
{
if (strlen(last) > 15)
strncpy(lastName, last, 14);
else
strcpy(lastName, last); return *this;
} // 15, if not, shorten to 14 letters.
Patient &Patient::setBirthDate(Date birth)
{
birthdate = birth; return *this;
}
Patient& Patient::setPrimaryDoctorID(int doctor)
{
primaryDoctorID = doctor; return *this;
}
const char *Patient::getID()
{ return ID; }
16. const char *Patient::getFirstName()
{ return firstName; }
const char *Patient::getLastName()
{ return lastName; }
Date Patient::getBirthDate()
{ return birthdate; }
int Patient::getPrimaryDoctorID()
{ return primaryDoctorID; }
bool Patient::enterProcedure(Date procedureDate, int procedureID,int
procedureProviderID)//tries to add a new entry to record array, returns //true if added, false if
cannot be added
{
if (currentCountOfProcedures > 100)
{
cout << "Cannot add any more procedure" << endl;
return false;
} else
{
record[currentCountOfProcedures].dateOfProcedure = procedureDate;
record[currentCountOfProcedures].procedureID = procedureID;
record[currentCountOfProcedures].procedureProviderID =
procedureProviderID;
currentCountOfProcedures++;
return true;
} }
void Patient::printAllProcedures()
{
cout << "Procedures of patient" << endl;
for (int i = 0; i < currentCountOfProcedures; i++)
{
cout << "Date of Procedure: " << record[i].dateOfProcedure << endl;
cout << "Procedure ID: " << record[i].procedureID << endl;
cout<< "Procedure Provider ID: " << record[i].procedureProviderID
<< endl;
}
Void Patient::display()