随笔分类 -  C++程序设计例题

摘要:MD5加密详解 引言: 我在百度百科上查找到了关于MD5的介绍,我从中摘要一些重要信息: Message Digest Algorithm MD5(中文名为信息摘要算法第五版)为计算机安全领域广泛使用的一种散列函数,用以提供消息的完整性保护。 MD4算法同样需要填补信息以确保信息的比特位长度减... 阅读全文
posted @ 2014-02-20 21:27 talobt3 阅读(14724) 评论(0) 推荐(1)
摘要:C++递归求解N个元素的所有子集引言: 我在复习C++遇到了设计递归函数的问题。这个例子,很好的显示了设计递归的方式,思想。 这与斐波那数列不同,这个例子更有应用意义。问题:试编写一个递归函数,用来输入n个元素的所有子集。 例如:三个元素{a,b,c} 输出: {a,b,c} {ab} ... 阅读全文
posted @ 2014-02-15 21:07 talobt3
摘要:1 /*统计除了>之外的行里面CHED四个字母总数*/ 2 #include 3 #include 4 #include 5 using namespace std; 6 7 class FindLetter 8 { 9 private:10 ifstream m_r;11 ofstream m_w;12 string m_falphabet,m_temp;13 char m_jump;//要跳跃的字符14 unsigned int *m_number,m_length;//计数 和 文件中的一行的个数... 阅读全文
posted @ 2013-11-25 19:59 talobt3 阅读(714) 评论(0) 推荐(0)
摘要:#includeusing namespace std;class Shape{public:void getArea(){cout<<"this is Shape class"<<endl;}};class Rectangle:public Shape{private:double x,y;public: void putbox(const int newx,const int newy){x=newx;y=newy; cout<<"x,y="<<x<<","<< 阅读全文
posted @ 2013-11-20 19:45 talobt3 阅读(167) 评论(0) 推荐(0)
摘要:1 #include<iostream> 2 using namespace std; 3 4 class Base0 5 { 6 public: 7 int var0; 8 void fun0() 9 { 10 cout<<"Member of Base0"<<endl; 11 } 12 }; 1 阅读全文
posted @ 2013-11-06 09:19 talobt3 阅读(307) 评论(0) 推荐(0)
摘要:1 //多继承同名隐藏 2 #include <iostream> 3 4 using namespace std; 5 6 class Base1 7 { 8 public: 9 int var; 10 void fun() 11 { 12 cout<<"Member of Base1"<<end 阅读全文
posted @ 2013-11-06 09:15 talobt3 阅读(520) 评论(0) 推荐(0)
摘要:1 #include <iostream> 2 #include <iomanip> 3 #include <string> 4 5 using namespace std; 6 7 struct Student 8 { 9 int num; 10 string name; 11 char sex; 阅读全文
posted @ 2013-11-04 20:18 talobt3 阅读(341) 评论(0) 推荐(0)
摘要:1 #include 2 3 using namespace std; 4 class Point 5 { 6 public: 7 Point(int x=0,int y=0):x(x),y(y){} 8 int getX() const {return x;} 9 int getY() const {return y;}10 private:11 int x,y;12 };13 int main()14 {15 Point a(4,5);16 Point * p1=&a;17 18 int (Point::*funcPtr)() c... 阅读全文
posted @ 2013-11-02 15:18 talobt3 阅读(179) 评论(0) 推荐(0)
摘要://6-13#includeusing namespace std;class Point{public: Point(int x=0,int y=0):x(x),y(y){} int getX() const {return x;} int getY() const {return y;}private: int x,y;};int main(){ Point a(4,5); Point * p1=&a; int (Point::*funcPtr)() const=&Point::getX; cout*funcPtr)()getX() 2 //... 阅读全文
posted @ 2013-11-02 15:18 talobt3 阅读(325) 评论(0) 推荐(0)
摘要:1 #include 2 3 using namespace std; 4 5 void printStuff(float data) 6 { 7 cout<<"this is the print stuff function."<<endl; 8 } 9 10 void printMessage(float data)11 {12 cout<<"the data to be listed is"<<data<<endl;13 }14 15 void printFloat(float data) 阅读全文
posted @ 2013-11-02 15:17 talobt3 阅读(186) 评论(0) 推荐(0)
摘要:1 #include 2 3 using namespace std; 4 5 void splitFloat(float x,int * intPart,float * fracPart) 6 { 7 *intPart=static_cast(x); 8 *fracPart=x-*intPart; 9 }10 11 12 int main()13 {14 cout>x;20 splitFloat(x,&n,&f);21 cout<<"Inter Part="<<n<<"Fraction Part=&quo 阅读全文
posted @ 2013-11-02 15:13 talobt3 阅读(171) 评论(0) 推荐(0)
摘要:1 #include 2 3 using namespace std; 4 5 6 int main() 7 { 8 int i; 9 int *ptr=&i;10 i=10;11 cout<<"i="<<i<<endl;12 cout<<"*ptr="<<*ptr<<endl;13 14 return 0;15 } 阅读全文
posted @ 2013-11-02 15:12 talobt3 阅读(147) 评论(0) 推荐(0)
摘要:1 #include 2 3 int main() 4 { 5 int line1[]={1,0,0}; 6 int line2[]={1,0,0}; 7 int line3[]={1,0,0}; 8 9 int * pLine[3]={line1,line2,line3};10 11 std::cout<<"Matrix test:"<<std::endl;12 13 14 for(int i=0;i<3;++i)15 for(int j=0;j<3;j++)16 std::cout<<pLine[... 阅读全文
posted @ 2013-11-02 15:10 talobt3 阅读(177) 评论(0) 推荐(0)
摘要://在weight.h中#ifndef _WEIGHT_H_#define _WEIGHT_H_class Car;class Boat{ private: double weight; public: Boat(double w=0.0):weight(w){} double getWeight(){return weight;} friend double getTotalWeight(Car & m,Boat & n);};class Car{ private: double weight; p... 阅读全文
posted @ 2013-11-02 15:10 talobt3 阅读(207) 评论(0) 推荐(0)
摘要:1 #include 2 3 using namespace std; 4 5 class A 6 { 7 public: 8 A(int i); 9 void print();10 private:11 const int a;12 static const int b=10;13 };14 15 16 A::A(int i):a(i){}17 18 void A::print()19 {20 cout<<a<<":"<<b<<endl;21 }22 //常成员函数只能通过初始化来获得初值23 24 int main()25 阅读全文
posted @ 2013-11-02 15:09 talobt3 阅读(182) 评论(0) 推荐(0)
摘要:1 #include 2 3 using namespace std; 4 5 class A 6 { 7 private: 8 int x,y; 9 public:10 A(int i,int j):x(i),y(j){}11 void Adisplay() const12 {13 cout<<"x="<<x<<" "<<"y="<<y<<endl;14 }15 };16 17 int main()18 {19 const A a(5,4);20 a.Adisp 阅读全文
posted @ 2013-11-02 15:08 talobt3 阅读(166) 评论(0) 推荐(0)
摘要:1 #include 2 3 using namespace std; 4 5 class Point 6 { 7 public: 8 Point(int x=0,int y=0):x(x),y(y){} 9 int getX() const {return x;}10 int getY() const {return y;}11 private:12 int x,y;13 };14 int main()15 {16 Point a(4,5);17 Point *p1;p1=&a;18 cout<<(*p1).getX()<<end... 阅读全文
posted @ 2013-11-02 15:08 talobt3 阅读(157) 评论(0) 推荐(0)
摘要://在weight.h中#ifndef _WEIGHT_H_#define _WEIGHT_H_class Point{public: Point(int x=0,int y=0):x(x),y(y){} int getX(){return x;} int getY(){return y;} friend float dist(Point &p1,Point &p2) { double x=p1.x-p2.x; double y=p1.y-p2.y; return static_cast(sqrt(x*x+y*y)); }private: ... 阅读全文
posted @ 2013-11-02 15:07 talobt3 阅读(338) 评论(0) 推荐(0)
摘要:1 #include 2 using namespace std; 3 class Point 4 { 5 public: 6 Point(int xx=0,int yy=0) 7 { 8 x=xx; 9 y=yy;10 cout<<"Constructor is called"<<endl;11 }12 Point(Point &p);13 int getX()14 {15 return x;16 }17 int getY()18 {19 ... 阅读全文
posted @ 2013-11-02 15:04 talobt3 阅读(278) 评论(0) 推荐(0)
摘要:#include using namespace std;class A{public: void display(){cout<<x<<endl;} int getX() {return x;} friend class B;private: int x;};class B{public: void set(int i); void display() { a.display(); };private: A a;};void B::set(int i){ a.x=i;}int main(){ cout << "H... 阅读全文
posted @ 2013-11-02 15:04 talobt3 阅读(189) 评论(0) 推荐(0)