Answer to Question #284249 in C++ for Mehtab

Question #284249

Implement a class Address. An address has



 a house number,



 a street,



 a city,



 a state and



 a postal code.



Supply two constructors:



 the default no-argument constructor that initializes different members



 one with complete address.



 Supply a print function that prints the address with the street on one line and the city,



state, and postal code on the next line.



 Supply a method verifyAddress that tests whether an address is valid (and does not



contain default values)



 Supply a method compareTo that tests whether one address comes before another when



the addresses are compared by postal code



Write a small program to test your class.

1
Expert's answer
2022-01-02T08:16:15-0500
#include<conio.h>
#include <iostream>
# include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include <cmath>
#include<dos.h>

using namespace std;


/*
	Implement a class Address. An address has a house number, a street, a city, a state and a postal code.
	Supply two constructors: the default no-argument constructor that initializes different members
	one with complete address. Supply a print function that prints the address with the street on one line and the city,
	state, and postal code on the next line. Supply a method verify Address that tests whether an address is valid (and does not contain default values)
	Supply a method compareTo that tests whether one address comes before another when the addresses are compared by postal code
	Write a small program to test your class.
*/


#define NO_OF_ADDRESS	5


class Address
{
	public:
	string H_No;
	string Street;
	string City;
	string State;
	int ZipCode;
	void GetAddress(void)			
	{
		ZipCode=-1;
		cout<<"\n\tEnter H. No.  : "; cin>>H_No;
		cout<<"\n\tEnter Street  : "; cin>>Street;
		cout<<"\n\tEnter City    : "; cin>>City;
		cout<<"\n\tEnter State   : "; cin>>State;
		cout<<"\n\tEnter Zip Code: "; cin>>ZipCode;
	}
	void PrintAddress(void)
	{
		cout<<"\n\n\t"<<H_No<<", "<<Street;
		cout<<"\n\t"<<City<<", "<<State<<" - "<<ZipCode;
	}
	int VerifyAddress(void)
	{
		int Flag=1;
		if(H_No.empty()) 	Flag=0;
		if(Street.empty()) 	Flag=0;
		if(City.empty()) 	Flag=0;
		if(State.empty()) 	Flag=0;
		if(ZipCode<=0)		Flag=0;
		return(Flag);
	}
};


void CompareTo(Address A1, Address A2)
{
	if(A1.ZipCode>=A2.ZipCode)
	{
		A2.PrintAddress();
		A1.PrintAddress();		
	}
	else
	{
		A1.PrintAddress();
		A2.PrintAddress();		
	}
}


int main()
{
	int Flag;
	class Address A,B;
	cout<<"\n\tAddress-1";
	A.GetAddress();
	A.PrintAddress();
	Flag=A.VerifyAddress();
	if(Flag==1) cout<<"\n\t\tAddress is Valid.";
	else		cout<<"\n\t\tAddress is In-Valid.";
	
	cout<<"\n\tAddress-2";
	B.GetAddress();
	B.PrintAddress();
	Flag=B.VerifyAddress();
	if(Flag==1) cout<<"\n\t\tAddress is Valid.";
	else		cout<<"\n\t\tAddress is In-Valid.";
	
	CompareTo(A,B);
	return(0);
	
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog