c++基础学习(03PM)

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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值