- 博客(51)
- 收藏
- 关注
原创 8章9节this指针
#include iostream>class Rectangle...{public: Rectangle(); ~Rectangle(); void SetLength(int length) ...{this->itsLength=length;} int GetLength()const ...{return this->itsLength
2008-05-16 23:18:00
351
原创 章8节在自由存储区中创建成员
#includeiostream>class SimpleCat...{public: SimpleCat(); ~SimpleCat(); int GetAge() const ...{return *itsAge;} void SetAge(int age) ...{*itsAge=age;} int GetWeight() const ...{re
2008-05-16 23:17:00
438
原创 8章7节访问数据成员
#includeiostream>class SimpleCat...{public: SimpleCat() ...{itsAge = 2;} ~SimpleCat()...{} int GetAge() const ...{return itsAge;} void SetAge(int age) ...{itsAge = age; } privat
2008-05-16 23:14:00
358
原创 8章6节删除自由存储区的对象
#includeiostream>using namespace std;class SimpleCat...{public: SimpleCat(); ~SimpleCat();private: int itsAge;};SimpleCat::SimpleCat()...{ cout "Constructor called." endl; itsA
2008-05-16 23:13:00
380
原创 8章3节分配删除指针new和delete
#includeiostream>int main()...{ using namespace std; int localVariable = 5; int*pLocal = &localVariable; int *pHeap = new int; *pHeap = 7; cout "localVariable: " localVariab
2008-05-16 23:10:00
447
原创 8章1节确定指针中存储的内容
#include iostream>int main()...{ using namespace std; unsigned short int myAge=20 , yourAge=30; unsigned short int *pAge=&myAge; cout "myAge is: "myAge; cout " yourAge is: "you
2008-05-16 23:09:00
392
原创 学习十天的复习程序
#include iostream>using namespace std;enum CHOICE...{ DrawRect = 1, GetArea, GetPerim, ChangeDimensions, Quit};class Rectangle...{pub
2008-05-13 02:26:00
346
原创 7章7节for死循环简单menu程序
#include int menu();void DoTaskOne();void DoTaskMany(int);using namespace std;int main(){ bool exit = false; for ( ; ; ) { int choice = menu(); switch(choice) { case(1): DoTaskOne();
2008-05-11 23:53:00
1103
原创 7章7节使用swich控制语句
#include int main(){ using namespace std; unsigned short int number; cout cin >> number; switch (number) // 下面假设了5个条件 { case 0: cout break; case 5: cout break; case 4: cout
2008-05-11 23:29:00
666
原创 7章6节for循环计算Fibonacci数
#include unsigned int fib(unsigned int position);int main(){ using namespace std; unsigned int answer,position; cout cin >> position; cout answer = fib(position); cout cout return 0;}
2008-05-11 04:36:00
389
原创 7章5节一些荒谬的空for循环
#include int main(){ using namespace std; int counter = 0; int max; cout cin >> max; for( ; ; ) //空for 没有初始化 没有条件 没有action 但是还是要有( ; ; ) { if (counter { cout counter++; } else b
2008-05-11 04:35:00
409
原创 7章5节for语句的循环
#include int main(){ int counter; for(counter=0;counter /* for 循环 (initialization; test; action) 由三个部分组成 初始化 测试 执行的动作(如递增)相当与 int counter =0; .......initialization w
2008-05-11 04:34:00
290
原创 7章5节for语句2个参数的循环
#include int main(){ for(int i =0 ,j = 100 ; i { std::cout } // for 和while 一样可以作为一个条件的中断 跳出当前的循环 去执行下一个action std::cout return 0;}
2008-05-11 04:32:00
977
原创 7章5节for循环嵌套
#includeint main(){ using namespace std; int rows,columns; char theChar; cout cin >> rows; cout cin >> columns; cout cin >> theChar; for(int i=0; i { for(int j=0; j cout cout } re
2008-05-11 04:31:00
304
原创 7章4节用break来跳出while
#include int main(){ int counter=0; while(true) { counter++; if(counter>10) break;//break 和 continue 的区别 前者是跳出 后者是跳转到程序的开头 } std::cout return 0;}
2008-05-11 04:30:00
533
原创 7章4节使用dowhile
#include int main(){ int counter; std::cout std::cin >> counter; do { std::cout counter--; } while(counter>0);//while和do while的区别在于是先执行程序还是先判断是否要执行 // do while中不管
2008-05-11 04:28:00
388
原创 7章4节实现dowhile
#include int main(){ int counter; std::cout std::cin >> counter; while(counter>0) { std::cout counter--; } std::cout return 0;}
2008-05-11 04:27:00
329
原创 7章4节break和continue
#include int main (){ using namespace std; typedef unsigned long ULONG; ULONG small,large,skip,target; const unsigned short MAXSMALL=65535; cout cin >> small; cout cin >> large; cout cin >>
2008-05-11 04:25:00
309
原创 7章2节while循环
#include int main (){ using namespace std;int counter = 100;while (counter { counter++; cout }cout return 0;}
2008-05-11 04:24:00
319
原创 7章2节while的复杂循环大小
#include int main(){ using namespace std; unsigned short small; unsigned long large; const unsigned short MAXSMALL=65535; cout cin >> small; cout cin >> large; cout while (small { if (smal
2008-05-11 01:29:00
465
原创 7章1节goto循环
#include int main(){ using namespace std; int counter =100; int n; loop: n = counter++; cout if (n goto loop; cout return 0;}
2008-05-11 01:27:00
287
原创 6章16节练习3表示工资
#include class Employee{ public: int GetAge () const; void SetAge (int age); int GetYearsOfService () const; void SetYearsOfService (int years); int GetSalary () const; void SetSalary (int salar
2008-05-11 01:26:00
379
原创 6章12节做一个.h头文件
#include class Cat{public: Cat(int initialage); ~Cat(); int GetAge(); void SetAge(int age); void Meow();private: int itsAge;}; #include "123.h" Cat::Cat(int initialage) //constructor
2008-05-11 01:24:00
359
原创 6章7街构造函数和解析函数
#include class Cat{public: Cat(int initialage);//构造 ~Cat();//解析 int GetAge(); void SetAge(int age); void Meow();private: int itsAge;};Cat::Cat(int initialage) //constructor of Cat.{ itsAge
2008-05-11 01:17:00
614
原创 6章6节存取器与类的实现
#include class Cat{public: Cat(int initialage); ~Cat(); int GetAge(); void SetAge(int age); void Meow();private: int itsAge;};Cat::Cat(int initialage) //constructor of Cat.{ itsAge = initia
2008-05-11 01:15:00
306
原创 6章4节类的声明和对象与方法
#include class cat //declare the cat class{public: // 声明以下的参数为publicint itsage;int itsweight;};int main(){ cat frisky; frisky.itsage =5; //. 引用类 std::cout return 0;}
2008-05-11 01:14:00
269
原创 5章10节递归
#include int fib (int n);using namespace std;int main(){ int n, answer; cout cin >> n; cout answer=fib(n); cout cout return 0;}int fib (int n){ cout if(n { cout return (
2008-05-11 01:12:00
233
原创 5章10节递归
#include int fib (int n);using namespace std;int main(){ int n, answer; cout cin >> n; cout answer=fib(n); cout cout return 0;}int fib (int n){ cout if(n { cout return (
2008-05-11 01:11:00
291
原创 5章6节局部与全局使用同一个变量不同定义的调用
#include void myfunc();using namespace std;int x=5,y=7;int main(){ myfunc(); cout cout return 0;}void myfunc(){ int y=10; cout cout }
2008-05-11 01:08:00
266
原创 5章5节去顶函数的作用域温度转换
#include float convert(float);int main(){ using namespace std; float tempfer; float tempcel; cout cin >> tempfer; tempcel=convert(tempfer); cout cout char response;cin >> response; return
2008-05-11 01:06:00
597
原创 5章5节局部参数的作用域
#include void myfunc();int main(){ using namespace std; int x=5; // 在main函数里 X=5 cout myfunc(); //开始调用函数 myfunc() cout return 0;}void myfunc(){ using namespace std; int x=10;//赋值=10 cout
2008-05-11 01:05:00
270
原创 5章1节函数的声明定义用法
#include int area( int length,int width);// 声明一个函数 包括 返回值的类型 函数名 函数包括的参数int main(){ using namespace std; int lengthofyard; int widthofyard; int areaofyard; cout cin >>widthofyard; cout cin
2008-05-11 01:02:00
309
原创 4章10节输入一个大于一百小于十的数字
#include int main(){ using namespace std; int x; cout cin >> x; if (x >=10) { if(x>100) cout else cout } else cout return 0;}
2008-05-11 01:00:00
787
原创 4章9节三目运算符
#include int main(){ using namespace std; int x,y,z; cout cin >> x; cin >> y; z = (x>y) ? x: y; cout // ?: 为条件运算符 是唯一一个需要三个操作数的运算符 /* 用if表示等同于下 if(x>y) z=x cout else z=y cout */
2008-05-11 00:56:00
421
原创 4章9节if比较大小
#include int main(){ using namespace std; int bignumber,smallnumber; cout cin >> bignumber; cin >> smallnumber; if (bignumber>smallnumber) { cout } if(bignumber { bignumber=smalln
2008-05-11 00:53:00
467
原创 4章6节运算优先级括号嵌套返回值
#include int main(){/* 优先级 1. 解析运算符 :: 2. 成员选择 下标 函数调用 后缀递增递减 . -> () ++ -- 3. sizeof 前缀递增递减 求补 逻辑非 单目加和减 取址和解除引用 new new[] delete delete[] 强制类型转换 sizeof() ++ -- …… ! + - & ()
2008-05-11 00:49:00
440
原创 4章5节递增递减前后缀的区别
#include int main(){ using namespace std; int myage =23, yourage=30; cout cout myage++; //后缀是先赋值再递减1 ++yourage;//前缀是先递增再赋值1给前面的myage cout cout cout myage++; ++yourage; cout cout c
2008-05-11 00:47:00
434
原创 4章3节使用运算符
#include int main(){ using std::cout; using std::endl; int difference,bignumber=100,smallnumber=50; difference=bignumber-smallnumber; cout difference=smallnumber-bignumber; cout
2008-05-11 00:46:00
264
原创 4章1节语句和表达式
#include int main(){ using std::cout; using std::endl; int a=0,b=1,x=1,y=22; cout cout {a=2; b=3; y=x=a+b; } // 这是一个语句块 就是一个简单的语句也可以拆分为几个语句 用{}来括起来表示 cout cout char reponse; std::cin>>re
2008-05-10 16:52:00
277
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人
RSS订阅