0% found this document useful (0 votes)
32 views9 pages

C++ Class Programs-7-8-2017

This document contains two C++ programs that use classes. The first program defines a student class with data members for student details like name, age, roll number, and class. It includes functions to enter student data and display it. The main function creates an object of the class and calls the member functions. The second program defines a class to add two numbers with data members for the two numbers and their sum. It includes functions to read the numbers, calculate the sum, and display the output. The main function creates an object and calls the member functions.

Uploaded by

Madiajagan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views9 pages

C++ Class Programs-7-8-2017

This document contains two C++ programs that use classes. The first program defines a student class with data members for student details like name, age, roll number, and class. It includes functions to enter student data and display it. The main function creates an object of the class and calls the member functions. The second program defines a class to add two numbers with data members for the two numbers and their sum. It includes functions to read the numbers, calculate the sum, and display the output. The main function creates an object and calls the member functions.

Uploaded by

Madiajagan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 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