设为首页 加入收藏

TOP

C++编程开发基础知识学习(一)
2017-07-20 10:22:48 】 浏览:831
Tags:编程 开发 基础 知识学习

C++编程开发基础知识学习

#include 
  
   
#include 
   
     #include 
    
      using namespace std; /*const double Pi = 3.14; class Figure { public: Figure(){}; virtual double area() const = 0; }; class Circle :public Figure{ public: Circle(double myr){ R = myr; } virtual double area() const { return Pi * R * R; } protected: double R; }; class Rectangle :public Figure{ public: Rectangle(double myr, double myw){ R = myr; W = myw; } virtual double area() const { return R * W; } private: double R; double W; }; void func(Figure &a){ cout << a.area() << endl; } int main() { Circle a(3.0); Rectangle b(2.0, 4.0); cout << "the area of circle is "; func(a); cout << "the area of retangle is "; func(b); return 0; }*/ /* class Base{ public: Base(){}; virtual ~Base() { cout << "Base destructor is called." << endl; } }; class Subclass:public Base{ public: Subclass(){}; virtual ~Subclass(); }; Subclass::~Subclass() { cout << "Subclass destructor is called." << endl; } int main() { Base *p = new Subclass; delete p; return 0; }*/ /* class Complex{ public: Complex( double r = 0.0, double i = 0.0); Complex operator + (Complex c); Complex operator - (Complex c); void display(); private: double real,image; }; Complex::Complex( double r, double i){ real = r; image = i; } Complex Complex::operator + (Complex c) { Complex temp; temp.real = real + c.real; temp.image = image + c.image; return temp; } Complex Complex::operator - (Complex c){ Complex temp; temp.real = real - c.real; temp.image = image - c.image; return temp; } void Complex::display() { if(image < 0) { cout << real << image << "i" << endl; }else { cout << real << "+" << image << "i" << endl; } } int main() { Complex c1(12.4,13.3),c2(14.4,26.5); Complex c; cout << "c1 = "; c1.display(); cout << "c2 = "; c2.display(); c = c1 + c2; cout << "c1 + c2 = "; c.display(); c = c1 - c2; cout << "c1 - c2 = "; c.display(); return 0; }*/ /* int main() { int a[20],i,j; a[0] = a[1] = 1; for(i = 2;i < 20;i++) { a[i] = a[i-1] + a[i - 2]; } for(j = 0;j < 20;j++) { cout << a[j] << "\t" ; if((j+1) % 5 == 0) cout << endl; } return 0; }*/ /* int b[5]; //全局变量 int main() { int a[5]; //局部变量 static int c[5]; //静态变量 int i; for(i = 0;i < 5;i++) cout << a[i] << " "; cout << endl; for(i = 0;i < 5;i++) cout << b[i] << " "; cout << endl; for(i = 0;i < 5;i++) cout << c[i] << " "; cout << endl; return 0; }*/ // 将一个正整数分解到数组中,然后正向和反向输出 /*int main() { int a[11]; int n,i = 0; cout << "请输入一个正整数:" << endl; cin >> n; while(n) { a[i] = n % 10; n /= 10; i++; } cout << "正向输入的结果是:" << endl; for(int j = i-1;j >= 0;j--) { cout << a[j] << " "; } cout << endl; cout << "反向输入的结果是:" << endl; for(int j = 0;j < i;j++) { cout << a[j] << " "; } cout << endl; return 0; }*/ /* class Myclass{ public: Myclass(); Myclass(int,int); Myclass(Myclass &); void print(); const Myclass &operator = (Myclass &); private: int m,n; }; Myclass::Myclass():m(5),n(1) { cout << "Default constructor." << endl; } Myclass::Myclass(int i,int j) { m = i; n = j; cout << "Parameter Constructor." << endl; } Myclass::Myclass(
首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇static 注意事项 下一篇C++自学之路:3.1-简单变量

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目