C ++ is based on an expansion on the C language, which not only contains the features of the C language, and optimized in C language, making an already complicated content easier.
C ++ three characteristics:
- Abstraction and encapsulation - classes and objects
- Inheritance and derivation
- Polymorphism
Next, we first discuss some simple basics ++ C:
1. On the:
2. function default parameters:
Experiment 1:
Write a function of circular, rectangular, triangular area, requirements for function overloading to achieve. Triangle area calculated using Heron's formula.
#include<iostream>
#include<math.h>
using namespace std;
#define PI 3.14
double area(int r)
{
return PI*r*r;
}
double area(int a,int b)
{
return a*b;
}
double area(int q,int w,int e)
{
double p;
p=(q+w+e)/2;
return sqrt(p*(p-q)*(p-w)*(p-e));
}
//同一个函数名area实现三个不同的功能:
int main()
{
double c,t;
int r,a,b,q,w,e;
cout<<"请输入圆的半径:";
cin>>r;
c=area(r);
cout<<"圆的面积是:"<<c<<endl;
cout<<"请输入长方形的长和宽";
cin>>a>>b;
r=area(a,b);
cout<<"当长方形的长和宽是:"<<a<<"和"<<b<<"时,长方形的面积是;"<<r<<endl;
cout<<"请输入三角形的三边长";
cin>>q>>w>>e;
t=area(q,w,e);
cout<<"当三角形的三边长shi:"<<q<<"和"<<w<<"和"<<e<<"时,三角形的面积是:"<<t<<endl;
system("pause");
return 0;
}
Experiment 2:
preparation of a program, to find two or three largest number of positive integers. Requirements: have a function with default parameters to achieve.
#include<iostream>
#include<math.h>
using namespace std;
int max(int a,int b=2)
{
return a>b?a:b;
}
int main()
{
int a,b=3;
cout<<max(a=4,b)<<endl;
return 0;
}
3. Quote:
4.new/delete operator: