01 2020 档案

摘要://c++中字符串的处理获取一行函数 #include <iostream> using namespace std; int main() { string s; getline(cin,s); cout<<s<<endl; } //c++中对于操作符重载的一些现象 #include <iostr 阅读全文
posted @ 2020-01-29 16:26 zmachine 阅读(550) 评论(0) 推荐(0)
摘要:#include <iostream> #include <algorithm>//直接用相应的库进行排序,简化算法,加快相应速度 using namespace std; int main() { int a[7]={-2,3,4,1,9,0,7}; sort(a,a+7);//排序函数默认为从小 阅读全文
posted @ 2020-01-29 11:17 zmachine 阅读(2123) 评论(0) 推荐(0)
摘要://关于友元:可以自由取得friend中private成员 //相同class的各object互为友元 #include <iostream> using namespace std; class complex{ public: complex(int r=0,int i=0) :re(r),im 阅读全文
posted @ 2020-01-29 10:58 zmachine 阅读(145) 评论(0) 推荐(0)
摘要:#include <iostream> using namespace std; template<typename T> class complex{ public:complex(T r=0,T i=0) :re(r),im(i) {} T real() const{return re;}//函 阅读全文
posted @ 2020-01-29 10:37 zmachine 阅读(149) 评论(0) 推荐(0)
摘要://non-explicit-one argument ctor(具有一个实参的构造函数) #include <iostream> using namespace std; class Fraction { public: Fraction(int num,int den=1) :m_numerat 阅读全文
posted @ 2020-01-28 22:03 zmachine 阅读(519) 评论(0) 推荐(0)
摘要://转换函数:可以实现将一个类转换为令一种类型 举例: #include <iostream> using namespace std; class Fraction {//一个分数类 public: Fraction(int num,int den=1) :m_numerator(num),m_d 阅读全文
posted @ 2020-01-28 19:55 zmachine 阅读(277) 评论(0) 推荐(0)
摘要:2.定义一个简单的Computer类,有数据成员芯片(cpu)、内存(ram)、光驱(cdrom)等等,有两个公有成员函数run、stop。cpu为CPU类的一个对象,ram为RAM类的一个对象,cdrom为CDROM类的一个对象,定义并实现这个类。 #include <iostream> usin 阅读全文
posted @ 2020-01-25 09:48 zmachine 阅读(342) 评论(0) 推荐(0)
摘要:.定义一个CPU类,包含等级(rank)、频率(frequency)、电压(voltage)等属性,有两个公有成员函数run、stop。其中,rank为枚举类型CPU_Rank,定义为enum CPU_Rank{P1=1,P2,P3,P4,P5,P6,P7},frequency为单位是MHz的整型数 阅读全文
posted @ 2020-01-24 17:58 zmachine 阅读(556) 评论(0) 推荐(0)