What is C++?
C++ is an object-oriented programming language. It was developed by Bjarne
Stroustrup at Bell Labs in 1983 as an extension of the C programming language.
C++ is a high-level, general-purpose programming language. C++ is an object-
oriented programming language which means that the main focus is on objects and
manipulations around these objects. This makes it much easier to manipulate code,
unlike procedural or structured programming which requires a series of
computational steps to be carried out. C++ is a compiled language that requires a
program's source code to be compiled into machine language before it can run. C+
+ is still one of the most widely used programming languages for developing
software.
Why we need C++?
C++ is faster than most other programming languages and it provides excellent
concurrency support. This makes it useful in those areas where performance is
quite critical and the latency required is very low. Such requirements occur all the
time in high-load servers such as web servers, application servers, database
servers, etc. C++ plays a key role in such servers. C++ is closer to hardware than
most other programming languages like Python, etc. C++ is fun and easy to learn
Features of C++
1. Simple
2. Object Oriented
3. Machine Independent and Platform-Dependent
4. Popular
5. Case-Sensitive
6. Mid-level programming language
7. Structured Programming Language
8. Rich Library
9. Memory Management
10. Powerful and Fast
11. Pointer
Algorithm to make a scientific calculator
Input: One number or two numbers.
Output: Multipication, Square root, Logarithm, Pow ,Trigonometry
function.
Step 1: Start
Step 2: Declare variable
Choice, num1, num2 ,result,base,exponent,operation.
Step 3: Read the value for variable choice, num1, num2, result, base,
exponent, operation.
Step 4: Switch(choice)
Step 5:
Case 1:Multipication: result=num1*num2
Case 2: Square root: result =sqrt(num1)
Case 3: Logarithm: result=log(num1)
Case 4: Pow: result= pow (base, exponent)
Case 5: Trigonometry function:result= tan(num1 * M_PI / 180.0)
Step 6: Default: Error
Step 7: Output
Step 8: Stop
Program
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int choice;
double num1,num2,result;
double base,exponent;
char operation;
cout<<"Calculator :";
cout<<"1. Multipication :";
cout<<"2. Square root :";
cout<<"3. Logarithm :";
cout<<"4. Pow :";
cout<<"5. Tanget :";
cout<<"Enter your choice (1-5) :";
cin>>choice;
switch(choice){
case 1:
cout<<"Enter the first number :";
cin>>num1;
cout<<"Enter the second number :";
cin>>num2;
result=num1*num2;
cout<<"Result :"<<result<<endl;
break;
case 2:
cout<<"Enter the number :";
cin>>num1;
if(num1>=0){
result=sqrt(num1);
cout<<"Result :"<<result<<endl;
}else{
cout<<"Square root of a negative number
is defined :";
}
break;
case 3:
cout<<"Enter the number :";
cin>>num1;
if(num1>0){
result=log(num1);
cout<<"Result :"<<result<<endl;
}else{
cout<<"Logarithm of zero and any
negative num is not defind :";
}
break;
case 4:
cout<<"Enter the base :";
cin>>base;
cout<<"Enter the exponent :";
cin>>exponent;
cout<<"Result :"<<pow(base,exponent)<<endl;
break;
default:
cout<<"Error :";
break;
case 5:
cout<<"Enter the angle in degrees :";
cin>>num1;
result=tan(num1 * M_PI / 180.0);
cout<<"Result :"<<result<<endl;
break;
cout<<"Error :";
break;
}
return 0;
}