#include <iostream>
#include <string.h>
using namespace::std;
class student
{
string name;
int age;
public:
student() //constructor
{
}
~student() //distructor
{
}
void setData(string n, int a) //setter function
{
name=n;
age=a;
}
void Dispaly() //getter function
{
cout<<"Your name is "<<name<<"\nYour age is "<<age<<endl;
}
};
int main()
{
student a; // object of class student
string name;
int age;
cout<<"Enter your name: ";
getline(cin, name); //get complete line from user.
cout<<"Enter your age: ";
cin>>age;
a.setData(name, age); // calling setter function
a.Dispaly(); // calling getter function
system("pause"); // hold screen untill user enter any character from screen
}
#include <string.h>
using namespace::std;
class student
{
string name;
int age;
public:
student() //constructor
{
}
~student() //distructor
{
}
void setData(string n, int a) //setter function
{
name=n;
age=a;
}
void Dispaly() //getter function
{
cout<<"Your name is "<<name<<"\nYour age is "<<age<<endl;
}
};
int main()
{
student a; // object of class student
string name;
int age;
cout<<"Enter your name: ";
getline(cin, name); //get complete line from user.
cout<<"Enter your age: ";
cin>>age;
a.setData(name, age); // calling setter function
a.Dispaly(); // calling getter function
system("pause"); // hold screen untill user enter any character from screen
}