PART I
Put all the code in a .doc file and include a UML diagram for the Airplane class. You can use Microsoft Visio or another drawing tool. The code must conform to the Google C++ style sheet for order and indentation etc.
http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Class_Format
1. /*Write a class for an airplane class with constructors, interface (mutators and accessors) and a test driver (main)which should test everything.It should be able to change altitude (up,down) and speed. The constructor will set the altitude to 0 and speed to zero and longitude and latitude to Boston, Massachusetts. The overloaded constructor will set longitude and latitude to some numbers. If the altutude ever falls below 0 the change altutude function should should announce the plane had crashed and the program exit. */
2. /* Rewrite DayOfYear (see attached document) to use constructor to set day and month as well as a default constructor ( set to 0,0). The day and month member variables are now private and the set and display functions and constructors are public. Add a private check_date member function that gets called in the public set function and overloaded consturctor. */
//DISPLAY 10.3 Class with a Member Function//Program to demonstrate a very simple example of a class.
//A better version of the class DayOfYear will be given in Display 10.4.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include <iostream>using namespace std;
class DayOfYear
{public: void output( );
int month;
int day;};
int main( )
{ DayOfYear today, birthday;
cout << "Enter today's date:\n";
cout << "Enter month as a number: ";
cin >> today.month;
cout << "Enter the day of the month: ";
cin >> today.day;
cout << "Enter your birthday:\n";
cout << "Enter month as a number: ";
cin >> birthday.month;
cout << "Enter the day of the month: ";
cin >> birthday.day;
cout << "Today's date is ";
today.output( );
cout << "Your birthday is ";
birthday.output( );
if (today.month == birthday.month && today.day == birthday.day)
cout << "Happy Birthday!\n";
else
cout << "Happy Unbirthday!\n";
return 0;}
//Uses iostream:
void DayOfYear::output( )
{ cout << "month = " << month << ", day = " << day << endl;}
|
PART II
Use code from DayOfYear() from above to implement the friend functions below:
Add these functions as "friends"
bool equal(DayOfYear& date1, DayOfYear& date2);
bool lessThan(DayOfYear& date1, DayOfYear& date2) // date1 less than date 2 etc.
bool greaterThan(DayOfYear& date1, DayOfYear& date2)
bool greaterThan_or_Equal(DayOfYear& date1, DayOfYear& date2)
bool lessThan_or_Equal(DayOfYear& date1, DayOfYear& date2)
Write the main() drive to completely test these.
PART III
Write a better DayOfYear class.
Add a year variable.
Rewrite check_date so that it really works, even for leap year.
In other words. October can have 31 days but November only 30.
You can flag leap year by testing the year input as follows: A year divisible with no remainder by 400 is a leap year. A year divisable by 4 with no remainder and NOT divisible by 100 ( again no remainder) is also a leap year. As you can see, 2012 ( divide by 4 and no 100 and no remainder) is a leap year. 2013 is not. The next leap year ( February has 29 days rather than the usual 28) is 2016. If the year entered is a leap year it can have 29 days. Otherwise only 28. Check a calendar for other lengths.
The default DayOfYear constructor sets the date to 1/1/1970.
There is an overloaded constructor that takes input for year, month and day.
Besides writing the above, write an overloaded << operator that outputs: 11/2/2012 ( for example).
Write an overloaded == operator as well.
Write the public accessors and mutators for year, month and day.
Write a driver to test the overloaded operators (etc.) by creating several DayOfYear objects using both constructors and the mutators ( for the object created by default destructor), outputting their values with cout as well as with the accessors, and testing == for objects with same date and objects with different dates with some meaningful output for the test.