What are the uses of C++ Programming? why C++ Programming is better than C programming.
Answers
Answer:
C++ is object-oriented, bottom-up, and includes many high-level features. C is low level, procedural, and top-down. C is still in use because it is slightly faster and smaller than C++. For most people, C++ is the better choice.
Answer: consider the below c++ program used for designing a simple calculator
#include<iostream>
#include<string>
using namespace std;
int main()
{
int a,b,sum,diff,pro,div,mod;
char ch;
cout<<"Enter the first number"<<endl;
cin>>a;
cout<<"Enter the Second number"<<endl;
cin>>b;
cout<<"Enter the operation you need (+,-,*,/,%)"<<endl;
cin>>ch;
if(ch=='+')
{
sum=a+b;
cout<<"The sum of the entered two numbers is"<<sum<<endl;
}
else
if(ch=='-')
{
diff=a-b;
cout<<"The differnce of the entered two numbers is"<<diff<<endl;
}
else
if(ch=='*')
{
pro=a*b;
cout<<"The product of the entered two numbers is"<<pro<<endl;
}
else
if(ch=='/')
{
div=a/b;
cout<<"The quotient of the entered two numbers is"<<div<<endl;
}
else
if(ch=='%')
{
sum=a%b;
cout<<"The reminder of the entered two numbers is"<<mod<<endl;
}
else
cout<<"Invalid operator choosen"<<endl;
return 0;
}
Explanation:
We use the concept of Object oriented programming in C++ whereas, Procedural approach is done in c.
Also the codes are less complex in C++ than in C.
C++ is comparatively a newer programming language than C.