C++ Laguage



Admission Enquiry Form

  

First Program in C++




First Object Oriented Program in C++:

In C++ we can write object oriented programs as well as structured programs.

In this tutorial we are writing only object orieted programs.In object oriented programming we have to follow the following steps:

  1. Create class
  2. Create data fields or variables
  3. Define Member functions or functions
  4. Create objects of the class
  5. Use member functions of the class using objects

in object oriented programming.We need to create class first to find the solution of any problem.




first OOPs Program

//first oop program to display Hello Compuhelp
#include<iostream>
class First
{
public:
void message()
{
std::cout<<"Hello Compuhelp";
}
};//end of class
int main()
{
First first;//first is the object of class First
first.message();//calling member function
}//end of main




Code to write a class Student to input and display the data.

#include<iostream>
using namespace std;
class Student
{
char name[20];
int rollno;
float fee;
public:
void input()
{
cout<<"Enter name ";
cin>>name;
cout<<"Enter rollno ";
cin>>rollno;
cout<<"Enter fee ";
cin>>fee;
}
void display()
{
cout<<"\nName is "<<name;
cout<<"\nRollno is "<<rollno;
cout<<"\nEnter fee "<<fee;
}
};//end of class

int main()
{
Student st;
st.input();
st.display();
}//end of main


Output:

Enter name compuhelp
Enter rollno 23
Enter fee 10000

Name is compuhelp
Rollno is 23
Enter fee 10000