How to Add two number in C++



How to Add two number in C++

 In this blog your gonna learn about how to add two number in C++. Also we gonna use Arithmetic Operator.

How to Add two number in C++


Table of Contents
  1. In this program,
  2. Data science & data analyst
  3. Data Cleaning and Preprocessing in Data ScienceAdvanced Data Analysis Techniques: Unlocking Insights from DataData Visualization Techniques in Data ScienceDescriptive Statistics in Data SciData Science Tools and TechniquesScope of Data ScienceWhy learn Data Science? | Why Data Science?Impact of Data ScienceThe Importance of Data in Science | Introduction to Data ScienceWhat is Data Analysis | Data Analyst for Beginners
    1. C++
  4. Introduction of C++ || Definition of C++Brief history of C++ || history of C++Features of C++ || why we use C++ || concept of C++Concept of OOP || What is OOP || Object oriented programming languageDifference Between OOP And POP || Different Between C and C++Characteristics of C++Interesting fact about C++ || Top 10 interesting fact about C++C++ Program StructureWriting first program in C++ || how to write hello world in C++Basic Data Type And Variable In C++Identifier in C++Keywords in C++Token in C++Comment in C++Constant in C++Modifier in C++Taking User Input in C++ | User input in C++Input Output Operator In C++C++ Operators | Operator in programming languageHow to Add two number in C++Polymorphism in C++Compile Time Polymorphism in C++Function overloading in C++Operator Overloading in C++What are Control Structures in C++ || Understanding Control Structures in C++ | How to use if, else, switchWhat are Functions and Recursion in C++ | How to Defining and Calling FunctionsClass in C++Object in C++
    1. Algorithms
  5. Why algorithm | The Importance of Algorithms in Modern Technology
    1. Technology
  6. Which is better | BSc in Computer Science or BTech?


#include<iostream.h>
#include<conio.h>
class add
{
public:
int a;
int b;
int c;
public:
void addition(void);
};
void  add::addition(void)
{
cout<<endl<<"please enter the value of a and b:";
cin>>a>>b;
cout<<endl<<”a=”<<a;
cout<<endl<<”b=”<<b;
c=a+b;
cout<<endl<<"the sum of those numbers:-"<<c;
}
void main()
{
clrscr();
add A;
A.addition();
getch();
}

The output of the program is given below. 


In this program,


I am using class to add two number, we can also add two number without using class.my class_name is “add”.

class add {}

We using three variable a, b, c and its publically defined in class datamember. where a, b is a number that you enter to add and c include result of this two number.

Public:
int a;
int b;
int c;


In the class member function we create a function that include all instruction to add two number. my function name is “addition” and it is a void function and its arguments also void.

public:
void addition(void);

We call the function outside of the class by using scope resolution operator ::

 void  add::addition(void) {}

cout, The cout object in C++ is an object of class iostream. It is used to display the output to the standard output device i.e. monitor.


cin, The cin object in C++ is an object of class iostream. It is used to accept the input from the standard input device i.e. keyboard.


In this function you can see the use of cout and cin:-


void  add::addition(void)
{
cout<<endl<<"plese enter the value of a and b:";
cin>>a>>b;
cout<<endl<<a;
cout<<endl<<b;
c=a+b;
cout<<endl<<"the sum of those numbers:"<<c;
}

 And we using main function to call the class by using object of that class:-


void main()
{
clrscr();
add A;               //object created
A.addition();      //call the function by using object 
getch();
}
 


Output of the program:-

please enter the value of a and b: 12 13
a=12
b=13
the sum of those numbers:-25



Data science & data analyst

C++

Algorithms

Technology


Post a Comment

Ask any query by comments

Previous Post Next Post