#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    1
    Rep Power
    0

    Question Need help to solve problems in object-oriented programming


    Need help to solve questions in object-oriented programming
    the questions are as follows:



    Part1 . Implement the class Time defined as follows:
    /* Time.h */
    #ifndef TIME_H_
    #define TIME_H_
    class Time {
    public:
    Time(); // constructor
    void setTime( int, int, int ); // set hour, minute, second
    void printTime() const; // print time format h:m:s
    private:
    int hour; // 0 - 23 (24-hour clock format)
    int minute; // 0 - 59
    int second; // 0 - 59
    };
    #endif /* TIME_H_ */

    The implementation of the class Time is as follows:
    /* Time.cpp */
    #include <iostream>
    #include "Time.h"
    using namespace std;
    // Time constructor
    Time::Time()
    {
    hour = 0;
    minute = 0;
    second = 0;
    }
    // set new Time value
    void Time::setTime( int h, int m, int s )
    {
    hour = ( h >= 0 && h < 24 ) ? h : 0;
    minute = ( m >= 0 && m < 60 ) ? m : 0;
    second = ( s >= 0 && s < 60 ) ? s : 0;
    }
    // print Time
    void Time::printTime() const
    {
    cout << hour << ":" << minute << ":" << second << "\n";
    }
    a. Add a new member function to the class Time that allows setting the time using AM and PM. The function should take four arguments: hour, minute, second, and AMPM. It should convert the input into a 24‐hour time system and set the data members hour, minute, second of the class Time, accordingly.
    b. Add a new member function to the class Time that prints the time using AM PM. For example if the time is 23:10:30 then the function should return 11:10:30PM.
    c. Test the new functions as follows:
    a. ‐ Dynamically create two objects of class Time.
    b. Invoke the new member functions on both objects so as to validate their correctness.


    d. Add a new function to the class Date that sets the date. The function should take three arguments that represents the day, month, and year and sets the data members of the class Date. Ensure that the dates are valid. For example, you should not have a day which is beyond 31. Assume that we do not deal with leap years (a year with an extra day).
    e. Add a new function to the class Date that returns the month in letters (e.g., January, February, etc.).
    f. Add a new function that returns the number of days between two given dates. d. Test the new functions of the class Date by:
    a. Dynamically create two objects of class Date.
    b. Invoke the new member functions on both objects so as to validate their correctness.
    c.
    Part2. Create a class called Passenger that represents passengers of an airline company. A passenger is defined by the following information:
    ‐ Passenger ID (int)
    ‐ Name (string)
    ‐ Address (string)
    ‐ Tel (string)
    ‐ Date of birth (of type Date from Q2)
    Provide the following functions:
    ‐ A constructor that initializes the data members and provides default arguments.
    ‐ Accessor methods that return the value of the data members.
    ‐ Functions that change the address, tel., and date of birth of a passenger.
    ‐ A function that prints information about a passenger.
    Test your class by dynamically creating two Passenger objects and calling on them the above functions.

    Part3. Create a class Flight that represents information about a particular flight. A flight is defined by a flight number (string), departure and arrival dates (type Date from Q2), departure and arrival times (type Time from part1), the arrival city (string), and the list of passengers on this flight (an array whose elements are of type Passenger from Part2). For the creation of the array, you may assume that all flights have the same capacity.
    The class Flight should have the following member functions:
    ‐ A constructor that sets the flight number, departure date and time, arrival date and time.
    ‐ A function that returns the duration of the flight in hours.
    ‐ A function that adds a passenger to the list of passengers. Recall that a passenger is of type Passenger.
    ‐ A function that removes a passenger from the list of passengers. The function takes passenger ID as input.
    ‐ A function that returns true if a given person is on the passengerís list, false otherwise.
    ‐ A function that prints the list of passengers.
    ‐ A function that returns the number of seats available.

    Test your class by creating two objects of the class Flight. For each class, you should create at least 5 passengers. All objects must be created dynamically.
    In this question, we encourage you to use the program analysis steps explained in the class, and which consist of identifying and formulating the problem, thinking of which variables you should use, analyzing the problem and the various possible solutions, and solving it. Similarly to parts 1‐3, you only need to submit the final program code. You do not have to document the problem analysis steps.
  2. #2
  3. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jan 2003
    Location
    USA
    Posts
    7,173
    Rep Power
    2222
    OK, so what have you done so far?

    And do you have any questions? I didn't see any questions there, nothing but a verbatim copy of your assignment problems. Almost as if you want us to do your work for you, which would be aiding you to commit plagiarism, an academic crime that would get you expelled. Certainly you wouldn't want that, so that leaves us right where we started, wondering what your question is.
  4. #3
  5. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,894
    Rep Power
    481
    By God if you can solve this Pan Am will hire you in a flash! (Is Pan Am still operating?) Seriously, if you write some code, and it doesn't work, and you can't figure out why, and you compiled with all warnings turned on, and you post it here you'll about certainly get good help.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo