You are on page 1of 9

C++ Class Programs

Dated: 08-08-2017
Program to enter students details and display it

#include <iostream>
using namespace std;
class stud
{
public:
char name[30],clas[10];
int rol, age;
void enter()
{
cout<<"Enter Student Name: ";
cin>>name;
cout<<"Enter Student Age: "; cin>>age;
cout<<"Enter Student Roll number: ";
cin>>rol;
cout<<"Enter Student Class: "; cin>>clas;
}
void display()
{
cout<<"\n Age\tName\tR.No.\tClass";

cout<<"\n"<<age<<"\t"<<name<<"\t“
<<rol<<"\t"<<clas;
}
};
int main()
{
class stud s;
s.enter();
s.display();
cin.get(); //use this to wait for a keypress
}
Ouput
// Adding two number using class (C++)
#include<iostream.h>
#include<conio.h>
class add
{
  private:
      int a, b, c;
  public:
      void read()
    {
cout<<"enter Two Number "<<endl;
cin>>a>>b;
    }
 void display()
  {
cout<<" A  = "<<a<<endl;
cout<<" B  = "<<b<<endl;
cout<<"Sum = "<<c<<endl;
   }
      void sum()
   {
       c= a+b;
   }
};
void main()
{
add x; // x is a object off add
  clrscr();
  x.read();
  x.sum();
  x.display();
  getch();
}

You might also like