01 2020 档案

摘要:源程序: #include<iostream> #include<iomanip> #include<string> using namespace std; string Months[13] = { "","Jan","Feb","Mar","Apr","May","Jun","Jul","Au 阅读全文
posted @ 2020-01-27 15:26 bobo哥 阅读(160) 评论(0) 推荐(0) 编辑
摘要:源程序: #include<iostream> using namespace std; int main() { char str[30]; while (!cin.eof()) //当输入流没有结束时继续循环 { cin.ignore(10, ':'); //在cin流中跳过':'之前的全部字符 阅读全文
posted @ 2020-01-27 15:16 bobo哥 阅读(126) 评论(0) 推荐(0) 编辑
摘要:源程序: #include<iostream> using namespace std; int main() { char buf[10]; int i = 0; while (cin.getline(buf, 10)) //若输入流的一行超过9个字符,则会出错 cout << ++i << ": 阅读全文
posted @ 2020-01-27 15:10 bobo哥 阅读(123) 评论(0) 推荐(0) 编辑
摘要:源程序: // // main.cpp // p292 // // Created by duanqibo on 2020/1/27. // Copyright © 2020年 duanqibo. All rights reserved. // #include<iostream> using na 阅读全文
posted @ 2020-01-27 14:59 bobo哥 阅读(121) 评论(0) 推荐(0) 编辑
摘要:源程序: //程序7-10 #include <iostream> using namespace std; int main() { char c = 'a', str[80] = "0123456789abcdefghijklmn"; int x = 65; cout << "cout.put( 阅读全文
posted @ 2020-01-27 14:45 bobo哥 阅读(129) 评论(0) 推荐(0) 编辑
摘要:源程序: //程序7-9 #include <iostream> using namespace std; int main() { double values[] = { 1.23,20.3456,300.4567,4000.56789,50000.1234567 }; cout.fill('*' 阅读全文
posted @ 2020-01-27 14:42 bobo哥 阅读(144) 评论(0) 推荐(0) 编辑
摘要:源程序: //程序7-8 #include <iostream> #include <iomanip> using namespace std; int main() { double x = 12.34; cout << "1)" << setiosflags(ios::scientific | 阅读全文
posted @ 2020-01-27 14:38 bobo哥 阅读(151) 评论(0) 推荐(0) 编辑
摘要:源程序: // // main.cpp // p286 // // Created by duanqibo on 2020/1/27. // Copyright © 2020年 duanqibo. All rights reserved. // //程序7-7 #include <iostream> 阅读全文
posted @ 2020-01-27 14:34 bobo哥 阅读(207) 评论(0) 推荐(0) 编辑
摘要:源程序: // // main.cpp // p285 // // Created by duanqibo on 2020/1/27. // Copyright © 2020年 duanqibo. All rights reserved. // //程序7-6 #include<iostream> 阅读全文
posted @ 2020-01-27 14:25 bobo哥 阅读(131) 评论(0) 推荐(0) 编辑
摘要:源程序: #include<iostream> #include<iomanip> using namespace std; int main() { int n = 65535,m = 20; cout<<"1)"<<n<<"n"<<"="<<hex<<n<<"="<<oct<<n<<endl; 阅读全文
posted @ 2020-01-27 14:21 bobo哥 阅读(110) 评论(0) 推荐(0) 编辑
摘要:源程序: #include <iostream> #include <string> using namespace std; int main() { char ch; int sum = 0,count = 0,x; cout<<"请输入整数(按Ctrl+Z退出)"<<endl; do { wh 阅读全文
posted @ 2020-01-27 14:15 bobo哥 阅读(109) 评论(0) 推荐(0) 编辑
摘要:源程序: #include <iostream> using namespace std; int main() { int x, count, sum = 0; freopen("c:\\input.txt", "r", stdin); for (count = 0; count<10; coun 阅读全文
posted @ 2020-01-27 12:44 bobo哥 阅读(101) 评论(0) 推荐(0) 编辑
摘要:源程序: #include <iostream> using namespace std; int main() { int x, count, sum = 0; freopen("c:\\input.txt", "r", stdin); //将标准输入重定向到文件input.txt for (co 阅读全文
posted @ 2020-01-27 12:37 bobo哥 阅读(156) 评论(0) 推荐(0) 编辑
摘要:源程序: #include <iostream> using namespace std; int main() { int x, y; cin >> x >> y; freopen("c:\\test.txt", "w", stdout); if (y == 0) cerr<<"error."<< 阅读全文
posted @ 2020-01-27 12:09 bobo哥 阅读(109) 评论(0) 推荐(0) 编辑
摘要:基类与派生类之间的互相转换,使用指针的情况 源程序: #include<iostream> using namespace std; class CBase { protected: int n; public: CBase(int i):n(i){} void Print() { cout<<"C 阅读全文
posted @ 2020-01-12 19:16 bobo哥 阅读(241) 评论(0) 推荐(0) 编辑
摘要:派生类中的复制构造函数 源程序: #include<iostream> using namespace std; class A { public: A() //默认构造函数 { i=100; cout<<"类A默认构造函数"<<endl; } A(const A&s) //复制构造函数 { i=s 阅读全文
posted @ 2020-01-12 19:03 bobo哥 阅读(170) 评论(0) 推荐(0) 编辑
摘要:互包含的类 源程序: #include<iostream> #include<string> using namespace std; class B; class A { public: int aInt; B *bPoint=NULL; void SetValue(int v) { aInt=v 阅读全文
posted @ 2020-01-12 18:58 bobo哥 阅读(130) 评论(0) 推荐(0) 编辑
摘要:虚基类 源程序: #include <iostream> using namespace std; class A{ public: int a; void showa(){ cout<<"a="<<a<<endl; } }; class B:virtual public A{ public: in 阅读全文
posted @ 2020-01-12 18:23 bobo哥 阅读(127) 评论(0) 推荐(0) 编辑
摘要:抽象类示例 源程序: #include <iostream> using namespace std; class A{ private: int a; public: virtual void print()=0; void func1(){ cout<<"func1"<<endl; } }; c 阅读全文
posted @ 2020-01-12 18:19 bobo哥 阅读(165) 评论(0) 推荐(0) 编辑
摘要:不使用虚析构函数的情况 源程序: #include <iostream> using namespace std; class ABase{ public: ABase(){ cout<<"ABase构造函数"<<endl; } ~ABase(){ cout<<"ABase::析构函数"<<endl 阅读全文
posted @ 2020-01-12 18:10 bobo哥 阅读(195) 评论(0) 推荐(0) 编辑
摘要:多态与非多态的比较 源程序: #include <iostream> using namespace std; class A{ public: void func1(){ cout<<"A::func1"<<endl; } virtual void func2(){ cout<<"A::func2 阅读全文
posted @ 2020-01-12 18:06 bobo哥 阅读(187) 评论(0) 推荐(0) 编辑
摘要:在构造函数和析构函数中调用虚函数 源程序: #include <iostream> using namespace std; class A{ public: virtual void hello(){ cout<<"A::hello"<<endl; } virtual void bye(){ co 阅读全文
posted @ 2020-01-12 18:01 bobo哥 阅读(122) 评论(0) 推荐(0) 编辑
摘要:在成员函数中调用虚函数 源程序: #include <iostream> using namespace std; class CBase{ public: void func1(){ cout<<"CBase::func1()"<<endl; func2(); func3(); } virtual 阅读全文
posted @ 2020-01-12 17:53 bobo哥 阅读(397) 评论(0) 推荐(0) 编辑
摘要:使用多态处理图形示例 源程序: #include <iostream> #include <cmath> using namespace std; class CShape { protected: double acreage; public: CShape() { //cout<<"基类构造函数 阅读全文
posted @ 2020-01-12 17:36 bobo哥 阅读(169) 评论(0) 推荐(0) 编辑
摘要:多态机制下对象存储空间的大小 源程序: #include <iostream> using namespace std; class A { public: int i; virtual void func(); virtual void func2(); }; class B :public A 阅读全文
posted @ 2020-01-12 09:24 bobo哥 阅读(116) 评论(0) 推荐(0) 编辑
摘要:基类引用实现多态 源程序: #include <iostream> using namespace std; class A { public: virtual void Print() { cout << "A::Print" << endl; } }; class B :public A { p 阅读全文
posted @ 2020-01-12 09:15 bobo哥 阅读(193) 评论(0) 推荐(0) 编辑
摘要:用基类指针访问基类对象及派生类对象 源程序: #include <iostream> #include <string> using namespace std; class A { public: void put_name(string s) { name = s; } virtual void 阅读全文
posted @ 2020-01-12 09:10 bobo哥 阅读(137) 评论(0) 推荐(0) 编辑
摘要:源程序: // // main.cpp // virtualfunction // // Created by duanqibo on 2020/1/9. // Copyright © 2020年 duanqibo. All rights reserved. // #include <iostrea 阅读全文
posted @ 2020-01-09 23:00 bobo哥 阅读(155) 评论(0) 推荐(0) 编辑