Pages

Create a class of student, get student name and age and print on screen using setter and getter function.

Tuesday 25 June 2013

#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
}
 

Search Box

Most Reading

Contact Form

Name

Email *

Message *