Programming Task

Programming Task: 


Ø C++ Program to Store Information of a Student in a Class
Ø C++ Program to Add Two Distances (in inch-feet) System Using Class
Ø C++ Program to Add Complex Numbers by Passing Object of a class to a     Function
Ø C++ Program to Calculate Difference Between Two Time Period
Ø  Store and Display Information of a car using Class and Member functions



 Programming task 2:
  
Part 1
Create a class Date with following data members:
·        Day, Month, Year
·        Overload two constructors to set the initial date.
·        Create multiple objects in main according to the need of programme.
  1. Overloaded == operator to check if the date is same. This will be a member function as demonstrated in the notes. Remember that you will want to compare the month, day, and year.
  2. Add an overloaded ++ operator (as a member function, to increment date, and month and year according to requirements of the calendar)
  3. Just for fun, create an overloaded << operator as a non-member to print the date.
ostream& operator<<(ostream&, const Date&);
  1. Explain why operator<< must be overloaded as a non-member.

Part 2:
Overload the + operator so that the following lines of code run in main:
        Date date3, date4;
        date3=date1+82;
        date4=6+date2;
More Details:
  • Define two functions. The prototypes will look like this:
·         Date operator+ (const Date&, int);
Date operator+ (int, const Date&);
Are they member or non-member functions? (Notice how many arguments they have)
  • Both functions will create a temporary date and return it.
  • Think about reusing as much code as possible.
    1. For one implementation of operator+, can you call the operator++ function?
    2. For the second implementation of operator+, can you call the first operator+ function?
    3. Together these two functions should be no more that 10 lines of code in the bodies. If you make it longer, you are working too hard.




No comments:

Post a Comment