
程序设计
文章平均质量分 68
zoneyoung
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
排序算法--冒泡算法
#include #include using namespace std; int main(int argc, char *argv[]) { int i; int test_arr[] = {2,3,6,4,1,5}; int test_count = sizeof(test_arr)/sizeof(test_arr[0]);//求数原创 2012-12-03 01:15:26 · 267 阅读 · 0 评论 -
编写程序处理一个复数与double数相加的运算,输出相应的double实数以及复数。
#include using namespace std; class Complex { public: Complex(){real=0;image=0;} Complex(double r){real=r;image=0;} Complex(double r,double i){real=r;image=i;} operator double(){ret原创 2014-12-04 01:42:37 · 3038 阅读 · 2 评论 -
C++继承的一些结论
#include using namespace std; class student { public: void get_value() { cin >> num >> name >> sex; } void display() { cout << "num:" << num << endl; co原创 2014-12-04 17:14:27 · 345 阅读 · 0 评论 -
构造函数和析构函数的调用顺序
#include using namespace std; class A { public: A(){cout << "constructing A " << endl;} ~A(){cout << "deconstructing A " << endl;} }; class B:public A { public: B() {cout <原创 2014-12-04 17:40:44 · 318 阅读 · 0 评论 -
setfill、setw和setprecision用法
转发自某博客:http://blog.sina.com.cn/s/blog_6757fa030100o54z.html C语言用法: 使用 setfill、setw 和 setprecision 操作器,这些操作器带有参数,并在头文件 iomanip.h 中定义。因此,此头文件必须包括在程序中。 #include #include #include void main() {原创 2014-12-05 01:09:54 · 3229 阅读 · 0 评论 -
建立两个磁盘文件f1.dat和f2.dat,编程序实现以下工作
1)从键盘输入20个整数,分别存放在两个磁盘文件中,每个文件中放10个整数 2)从f1.dat读入10个数,然后存放在f2.dat文件原有数据后面 3)从f2.dat中读入20个整数,对它们进行从小到大的顺序存放在f2.dat中(不保留原来的数据)#include #include #include using namespace std; //fun1函数从键盘输入20个整数,分原创 2014-12-05 20:11:05 · 13568 阅读 · 0 评论 -
对输入输出二进制文件流的操作
#include #include #include using namespace std; struct staff { int num; char name[20]; int age; double pay; }; int main() { staff staf[7]={2101,"Li",34,1203,2104,"Wang",23,67原创 2014-12-06 02:39:09 · 887 阅读 · 0 评论 -
对输入输出串流的操作
#include #include using namespace std; struct student { int num; char name[20]; double score; }; int main() { student stud[30]={1001,"Li",78,1002,"Wang",89.5,1004,"Fun",90},stud1[原创 2014-12-06 03:00:39 · 574 阅读 · 0 评论 -
区别异常处理调用析构函数与正常调用析构函数
#include using namespace std; class Student { public: Student(int n,string nam) { cout << "constructor-" << n << endl; num = n; name = nam; } ~Student(){cout原创 2014-12-06 16:40:52 · 265 阅读 · 0 评论 -
命名空间的使用
在header1.h中 #include using namespace std; namespace student1 { class Student { public: Student(int n,string nam,int a,string addr) { num = n; nam原创 2014-12-06 17:05:55 · 276 阅读 · 0 评论 -
inline函数以及类中的函数(代码)是不占用内存空间的,类成员函数的声明和定义使用
#include using namespace std; class Student{ int num; //sizeof(int)是4 public : char name[20]; //sizeof(char [20])是20 char sex; //对齐,所以内存占用空间大小变为4,和int内存大小对其 void display原创 2014-11-27 16:11:16 · 1028 阅读 · 0 评论 -
new和delete的使用以及struct结构体是使用
#include #include using namespace std; struct Student { string name; int num; char sex; }; int main() { Student *p; p = new Student; //用new运算符开辟一个存放Student类型的数据指针变量p p ->原创 2014-11-27 02:04:18 · 4485 阅读 · 1 评论 -
类模版的使用例子
#include using namespace std; template //声明类模版,虚拟类型名numtype class Compare { public: Compare(numtype a,numtype b) { x=a; y=b; } numtype max() { r原创 2014-11-27 23:51:53 · 407 阅读 · 0 评论 -
排序算法--插入排序
#include #include using namespace std; int main(int argc, char *argv[]) { int i; int test_arr[] = {2,4,1,5,3,6}; int arr_count = sizeof(test_arr)/(sizeof(test_arr[0])); //cout <<原创 2012-12-03 15:30:43 · 318 阅读 · 0 评论 -
1000!数字后有多少个0
编程思想: 由于2*5=10 并且1000!能被2整除肯定比能被5整除的多,因此只要算出1000!中能被5整除的数即可。 按照正常思维应该是1000/5=200 1000/25=40 1000/125=8 1000/625=1 因此1000!中总共有200+40+8+1=249个0 编程实现: 假设输入的数是n,求n!求出的数字后多少个0。原创 2012-12-07 01:48:59 · 471 阅读 · 0 评论 -
基于指针的指针的一些想法
问题来源: 《大话数据结构》书中有关 #270楼 @jennyBaBy 引用 @伍迷 老师 您好 我有个问题一直想不通 ,就是您前面的那个链表代码的初始化代码是:Status InitList(LinkList *L) { *L=(LinkList)malloc(sizeof(Node)); /* 产生头结点,并使L指向此头结点 */ if(!(*L)) /原创 2014-11-12 22:21:04 · 287 阅读 · 0 评论 -
能够实现两数在函数中成功交换的两种方法
/* 实现两个数在函数成功交换的两种方法 */ #include #include using namespace std; int swap(int &p,int &q){ int temp; temp=p; cout << "------------------swap方法体内" << endl; cout <<"swap方法使用的是地址对应的值交换" << endl;原创 2014-11-20 01:12:50 · 592 阅读 · 0 评论 -
对两个整数进行交换操作
#include using namespace std; int main() { void swap(int *,int *); void swap1(int,int); void swap2(int *,int *); void swap3(int &,int &); int a=45,b=78; int * pointer_1,* po原创 2014-11-26 11:59:03 · 283 阅读 · 0 评论 -
“引用”reference的使用:交换两个数
#include using namespace std; int main() { int a = 10; int &q = a; //这里声明了一个引用,q是a的别名,q和a都是同一个内存单元 int *p = &a; //这里的&a是地址,&是地址运算符,要区别于引用声明符。 int b=13; void swap(int &,int &原创 2014-11-27 01:41:07 · 439 阅读 · 0 评论 -
构造函数析构函数的调用顺序
#include #include using namespace std; class Student { public: Student(int n,string nam,char s) { num = n; name = nam; sex = s; cout << "Constructor called"原创 2014-11-27 20:47:16 · 284 阅读 · 0 评论 -
若干字符串按字符串顺序(由小到大)输出(涉及字符串数组指针以及指向指针的指针运用的错误方式)
#include #include using namespace std; int main() { void sort(char **, int); void print(char **, int); char *name[] = {"BASIC","FORTRAN","C++","Pascal","COBOL"}; //这里的name明显是指向字符型数组的指针原创 2014-11-27 00:29:04 · 643 阅读 · 0 评论 -
const指针的用法
#include using namespace std; int main() { void fun(int *); int a = 10; int b = 23; int * const p=&a; // p = &b; //无法通过编译 const int * const q = &a; a=33; //合法 //*q=21原创 2014-11-27 01:03:49 · 234 阅读 · 0 评论 -
面试题:如何删除单链表的重复结点
转自:http://www.nowamagic.net/librarys/veda/detail/1846 写一算法将单链表中值重复的结点删除,使所得的结果表中各结点值均不相同。 解决的思路如下: 建立指针p,用于遍历链表;建立指针q,q遍历p后面的结点,并与p数值比较;建立指针r,r保存需要删掉的结点,再把需要删掉的结点的前后结点相接。由此去掉重复值。 具体代码实现为:转载 2015-06-25 17:57:03 · 2742 阅读 · 0 评论