您的位置:首页 > 编程语言 > C语言/C++

c++基础学习(03PM)

2015-05-31 17:54 323 查看
1.g++ xx.cc

2.枚举类型的值从0开始依次递增,没有指定的情况下。要是指定了,按照指定的值递增。

3.switch()语句中case是入口 break是出口程序只能从出口出来

4.打印出99乘法表 有兴趣可以尝试一下一层循环试验一下

5.本讲相关代码1:

#include <iostream>

#include <ctime>

using namespace std;

enum Color{BLACK,WHITE,BLUE=100,GREEN};

int main()

{

Color cloth=WHITE;

Color hat=GREEN;

cout << "cloth=" << cloth << endl;

cout << "hat=" << hat << endl;

int n;

cout<< "1--good morning" << endl;

cout<< "2--good afternoon" << endl;

cout<< "3--good evening" << endl;

cout<< "choose(1~3)" << endl;

cin >> n;

switch(n)

{

case 1:

cout<< "1--good morning" << endl;break;

case 2:

cout<< "2--good afternoon" << endl;break;

case 3:

cout<< "3--good evening" << endl;break;

default:

cout<< "hello!" << endl;break;

}

int m=5;

while(m>0)

{

long t=time(NULL);

t += 1;

while(time(NULL)<t);//等待5秒钟才进行下一步

cout << "nihao" << endl;

m--;

}

for(int i=0;i<5;i++)//i只在for循环中可以使用,在其他地方就不能用了 在c++中

{

cout << i << endl;

}

cout << i << endl;//i在for循环之外也可以使用,在其他地方就不能用了 在vc++中

for(;;)

{

int p;

cout << "input an integer:";

cin >> p;

if(p==0)

break;

else

cout << p*p <<endl;

}

return 0;

}

6.本讲相关代码2:

#include <iostream>

#include <ctime>

using namespace std;

void wait_one_second()

{

int m=1;

while(m>0)

{

long t=time(NULL);

t += 1;

while(time(NULL)<t);//等待1秒钟才进行下一步

cout << "nihao" << endl;

m--;

}

}

void wait(int n)

{

while(n>0)

{

wait_one_second();

cout<<".\a" << endl;

n--;

}

}

int main()

{

wait(8);

return 0;

}

7.本讲相关代码3:

#include <iostream>

#include <ctime>

using namespace std;

int menu_choice()

{

int n;

do{

cout << "1--存款" << endl;

cout << "2--取款" << endl;

cout << "3--转账" << endl;

cout << "4--查询" << endl;

cout << "0--退出" << endl;

cout << "请选择(0~4):" << endl;

cin >> n;

}while(n<0||n>4);

return n;

}

int main()

{

cout << menu_choice() << endl;

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: