Tuesday, 8 October 2024

Journal Program 3

 /*

Def : WAP to build a class Person,which contain person name,age

  and city as data members and getData() and printData()

  as memeber functions to read and print person data.

Tut Date:

Lab Date:

*/

#include<iostream.h>

#include<conio.h>

#include<stdio.h>

class Person

{

int age;

char name[20],city[20];

public :

void getData()

{

cout<<"\n Enter person name : ";

flushall();

gets(name);

cout<<"\n Enter person age : ";

cin>>age;

cout<<"\n Enter city name : ";

flushall();

gets(city);

}

void printData();

};

void Person::printData()

{

cout<<"\n\t\t PERSON DETAILS ";

cout<<"\n======================================";

cout<<"\n Person Name : "<<name;

cout<<"\n Person Age : "<<age;

cout<<"\n City Name : "<<city;

cout<<"\n======================================";


}


int main()

{

clrscr();

Person p;

p.getData();

p.printData();

getch();

return 0;

}


No comments:

Post a Comment