Monday, 22 December 2014

C++ PROGRAM: Define a class Name with member last, first, suffix, and nick name implement the class person so that persons name is of the type name class instead string.


Define a class Name with member last, first, suffix, and nick name implement the class person so that persons name is of the type name class instead string.

SOLUTION:
#include<iostream.h>
#include<conio.h>
class Name
{
public:
char first_name[20],last_name[20],suffix[20],nick_name[20];
};
class Person:public Name
{
public:
void input();
void output();
};
void Person::input()
{
cout<<"Enter your First Name:";
cin>>first_name;
cout<<"\nEnter your Last Name:";
cin>>last_name;
cout<<"\nEnter the Suffix for your Last Name:";
cin>>suffix;
cout<<"\nEnter your Nick Name:";
cin>>nick_name;
}
void Person::output()
{
cout<<"\n\n\nYour First Name is:"<<first_name;
cout<<"\nYour Last Name:"<<last_name;
cout<<"\nThe Suffix for your Last Name:"<<suffix;
cout<<"\nYour Nick Name is:"<<nick_name;
}
void main()
{
Person p;
clrscr();
p.input();
p.output();
getch();
}
OUTPUT:






No comments:

Post a Comment