In this blog, Here is an example of a Simple Math Operation in C++ and with their designated function. We will also learn the basic syntax in C++. Before we begin, What is C++? C++ was developed as an enhancement of C language that includes object-oriented paradigm. It is an imperative and a compiled language.
Structure of a C++:
Simple Math Equation in C++
Sample Code:
Output:
Code Explained:
Line 1: #include <iostream> is a header file library that includes the standard input output library functions.
Line 2: using namespace std means that we can use names for objects and variables from the standard library.
Line 3: Blank Line. C++ ignores blank line but it will make our code readable.
Line 4: int main() represent the function of the code. Anything inside the curly braces {} will be executed.
Line 6: Int = Datatype, x and y = Variables for 1st and 2nd Number.
Line 7: sum, diff, prod, quo = Variables for Sum, Difference, Product and Quotient.
Line 9: cout or (pronounce as see-out) is a syntax used to print the output/ input text. Always together with “<<“;
Line 10: cin is a syntax used to read the input from the code. Always together with “>>“;
Line 14-17: Represent the basic math operation, such as Addition, Subtraction, Multiplication and Division.
Line 19-22: Represent the output of each answer. Syntax “endl” used to insert a new line characters.
Reference:
https://www.w3schools.com/cpp/cpp_syntax.asp