Create a class that holds name and address information. Store
all the information in
character strings that are private members of the class. Include a
public function that
stores the name and address. Also include a public function that
displays the name and
address. (Call these functions store() and display().)
Program:
#include<iostream>
#include<string>
using namespace std;
class Information
{
private:
char name[50], address[100];
public:
void store()
{
//getline to accept full name and address if you want
cout<<"Enter the name: ";
cin.getline(name,50);
cout<<"Enter the address: ";
cin.getline(address,100);
}
void display()
{
cout<<"\n\nName: "<<name<<endl;
cout<<"Address: "<<address<<endl;
}
};
int main()
{
Information info;
//calling store() method to accept the name and address
info.store();
//calling display() method to display the stored name and
address
info.display();
}
Output:
Get Answers For Free
Most questions answered within 1 hours.