RSS Forums RSS
Please support our C++ advertiser: Programming Forums
Views: 2041 | Replies: 1
Reply
Join Date: Jun 2005
Location: California
Posts: 92
Reputation: djbsabkcb is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
djbsabkcb's Avatar
djbsabkcb djbsabkcb is offline Offline
Junior Poster in Training

Help C++ program using classes

  #1  
Jul 16th, 2005
Below is a program that determines if one address comes before another address using classes. One constructor takes an apartment parameter and the other doesn't. My errors are invalid conversion from int to const and among others. Any ideas?


#include <iostream>
#include <stdlib>

using namespace std;

class Address
{

        public:
        Address(int h, string st, int appt, string c, string s, string pc);
        Address(int h, string st, string c, string s, string pc);
        bool comes_before(Address a) const;
        void print() const;

        private:
        int house_number;
        string street;
        int apartment_number;
        string city;
        string state;
        string postal_code;
};

Address::Address(int h, string st, int appt, string c, string s, string pc)
{
        // initialization of the variables
        house_number = h;
        street = st;
        apartment_number = appt;
        city = c;
        state = s;
        postal_code = pc;
}

Address::Address(int h, string st, string c, string s, string pc)
{


        // initialization of the variables
        house_number = h;
        street = st;
        city = c;
        state = s;
        postal_code = pc;
}
void Address::print()const
{

        cout << house_number << " " << street;
        if (apartment_number > 0 )
                cout << ", #" << apartment_number << endl;
                cout << city << ", " << state << ", " << postal_code << endl;
}

bool Address::comes_before( Address other)const
{

        return postal_code < other.postal_code;

}


int main()
{
        //creating an object of 'Address' for a house
        Address aHouse(100, "N.University Dr.", "Edmond", "OK", 73034);

        //creating another object of 'Address' for an apartment
        Address anApartment(201, "N.E. 89th St.", 305, "Oklahoma City", "OK", 73134);

        cout << " Comparing Address\n\n";
        a.House.print();

        cout << "\nwith address\n\n";

        anApartment.print();

        if(a.House.comes_before(anApartment))

                cout << "\nThe HOUSE address comes before the APARTMENT address\n";
        else
                cout << "\nThe HOUSE address does o come before the APARTMENT address\n";


        // comparing again

        if (anApartment.comes_before(aHouse))

                cout << " \nThe APARTMENT address comes before the HOUSE address\n";
        else
                cout << " \nThe APARTMENT address does not come before the HOUSE address\n";

        return 0;
<< moderator edit: added code tags: [code][/code] >>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2005
Location: California
Posts: 92
Reputation: djbsabkcb is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
djbsabkcb's Avatar
djbsabkcb djbsabkcb is offline Offline
Junior Poster in Training

Re: C++ program using classes

  #2  
Jul 16th, 2005
figured it out was using a string in the class for zip code instead of int.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 9:48 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC