C++速学学习心得笔记

这篇博客记录了作者在C++学习过程中的心得,内容包括基础语法、数据结构、文件操作、类与对象、多态、模板等关键知识点,并通过实例代码进行讲解。涉及冒泡排序、结构体、指针、文件输入输出、类的封装、多态实现、容器如vector、stack、queue、list、set、map的使用。适合有一定C语言和Java基础的学习者参考。
摘要由CSDN通过智能技术生成

C++学习心得(本文是我在拥有一定c语言、java入门基础上,花费四天学习c++的一些笔记,由于健忘,故作此可以在日后对于一些容易忘记的内容可以及时查看,复习c++的内容):
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;

//7-16
/void bubbleSort(int arr, int len)
{
for(int i=0;i<len-1;i++)
for (int j = 0; j < len - i - 1; j++)
{
if (arr[j] > arr[j + 1])
{
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
struct Student
{
string name;
int age;
int score;
};
void out(Student stu)
{
cout << stu.name <<" “<< stu.age <<” "<< stu.score << endl;
}
void out1(const struct Student * p)
{
//p->score=99;
cout << p->name << " " << p->age << " " << p->score << endl;
}
int main()
{
srand((unsigned int)time(NULL));
int e = rand() % 60 + 40;

int arr[] = { 3,7,1,5,4,9,2,8,6,0 };
int len = sizeof(arr) / sizeof(arr[0]);
for (int n = 0; n < len; n++)
{
	cout << arr[n] << " ";
}
cout << endl;
bubbleSort(arr, len);
for (int k = 0; k < len; k++)
{
	cout << arr[k]<<" ";
}
cout << endl;


struct Student s1;
s1.name = "xiaoming";
s1.age = 12;
s1.score = 98;
struct Student s2 = { "xiaoqiang",14,88 };
struct Student stuArr[2] = {
	{"xiaomi",20,76},
    {"xiaohua",17,80}
};
Student * l = &s2;
cout << l->age << endl;
out(s2);
out1(&s1)



system("pause");
return 0;

}
*/

//7-17
/int func()//栈区
{
int a = 10;
return &a;
}
intfunc1()//堆区
{
int
w = new int(10);
return w;
}
void test()
{
int*arr = new int[10];
delete[]arr;
}

void mySwap(int &a, int &b) //引用传递
{
int temp = a;
a = b;
b = temp;
}

int & test1()
{
int a = 10;
return a;

}
int & test2()
{
static int a = 10;
return a;

}

//封装
const double PI = 3.14;
class Circle
{
public:
int r;
double calculate()
{
return 2 * PI*r;
}
};

class Student
{
public:
string name;
int id;
void showStudent()
{
cout << name << " " << id << endl;
}
void setName(string name)
{
this->name = name;
}
void setId(int id)
{
this->id = id;
}

};

//多态
class Animal
{
public:
virtual void speak()
{
cout << “动物在说话” << endl;
}
};
class Cat :public Animal
{
public:
virtual void speak()
{
cout << “小猫在说话” << endl;
}
};
class Dog :public Animal
{
public:
virtual void speak()
{
cout << “小狗在说话” << endl;
}
};
void doSpeak(Animal &animal)
{
animal.speak();
}
void test1()
{
Cat cat;
doSpeak(cat);
Dog dog;
doSpeak(dog);
}

//计算器类
class AbstractCalculator
{
public:
virtual int getResult()//纯虚函数 virtual void func()=0
{
return 0;
}
int numA;
int numB;
};
class mulCalculator :public AbstractCalculator
{
public:
int getResult()
{
return numA * numB;
}
};
void test3()
{
AbstractCalculator *abc = new

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值