没有合适的资源?快使用搜索试试~ 我知道了~
C++典型案例分析
需积分: 11 11 下载量 7 浏览量
2014-10-17
20:44:49
上传
评论 2
收藏 54KB DOC 举报
温馨提示
![preview](https://dl-preview.csdnimg.cn/8050945/0001-f066f8b2ab12b9f55a1edea81094d88a_thumbnail-wide.jpeg)
![preview-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/scale.ab9e0183.png)
试读
14页
C++典型案例分析,各位可以看一看,可能对你所帮助!
资源推荐
资源详情
资源评论
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![docx](https://img-home.csdnimg.cn/images/20210720083331.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![application/pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![txt](https://img-home.csdnimg.cn/images/20210720083642.png)
![](https://csdnimg.cn/release/download_crawler_static/8050945/bg1.jpg)
C++简单程序典型案例
【案例 2-1】设计一个编写仅包含 C++程序基本构成元素的程序
/* //注释行开始
This is the first C++ program.
Designed by zrf
*/ //注释行结束
#include <iostream> //包含头文件
using namespace std; //打开命名空间 std
// This is the main function//单行注释语句
int main(void) //主函数,程序入口
{//块作用域开始
int age; //声明一个变量
age= 20; //赋值语句
cout<<"The age is:"; //输出一个字符串
cout<<age<<endl; //输出变量中的值
return 0; //主函数返回 0
}//块作用域结束DDDD
【案例 2-2】计算圆的周长和面积——C++语言中常量、变量
#include <iostream>
using namespace std;
int main()
{const float PI=3.1415926; //float 型常量
![](https://csdnimg.cn/release/download_crawler_static/8050945/bg2.jpg)
float r=2.0; //用 float 型常量初始化变量
cout<<"r="<<r<<endl;//输出圆的半径
float length; //float 型变量声明
length=2*PI*r; //计算圆的周长
cout<<"Length="<<length<<endl;//输出圆的周长
float area=PI*r*r; //计算圆的面积
cout<<"Area="<<area<<endl;//输出圆的面积
return 0;
}
【案例 2-3】整数的简单运算——除法、求余运算法和增量减量运算符
#include <iostream>
using namespace std;
int main()
{int x, y;
x = 10; y = 3;
cout << x << " / " << y << " is " << x / y //整数的除法操作
<<" with x % y is " << x % y << endl; //整数的取余操作
x ++; --y ;//使用增量减量运算符
cout << x << " / " << y << " is " << x / y << "\n" //整数的除法操作
<< x << " % " << y << " is " << x % y<<endl; //整数的取余操作
return 0;
}
【案例 2-4】多重计数器——前置和后置自增运算符
#include<iostream>
![](https://csdnimg.cn/release/download_crawler_static/8050945/bg3.jpg)
using namespace std;
int main()
{int iCount=1;iCount=(iCount++)+(iCount++)+(iCount++);//后置++
cout<<"The first iCount="<<iCount<<endl;
iCount=1;iCount=(++iCount)+(++iCount)+(++iCount);//前置++
cout<<"The second iCount="<<iCount<<endl;
iCount=1;iCount=-iCount++;//后置++
cout<<"The third iCount="<<iCount<<endl;
iCount=1;iCount=-++iCount;//前置++
cout<<"The fourth iCount="<<iCount<<endl;
return 0;
}
【案例 2-5】对整数“10”和“20”进行位运算——位运算的应用
#include <iostream>
using namespace std;
int main()
{ cout << "20&10=" << (20&10) << endl;//按位与运算
cout << "20^10=" << (20^10) << endl;//按位异或运算
cout << "20|10=" << (20|10) << endl;//按位或运算
cout << "~20=" <<(~20) << endl; //按位取反运算
cout << "20<<3=" << (20<<3) << endl;//左移位运算
cout << "-20<<3=" << (-20<<3) << endl;//左移位运算
cout << "20>>3=" << (20>>3) << endl;//右移位运算
cout << "-20>>3=" << (-20>>3) << endl;//右移位运算
return 0;
}
剩余13页未读,继续阅读
资源评论
![avatar-default](https://csdnimg.cn/release/downloadcmsfe/public/img/lazyLogo2.1882d7f4.png)
![avatar](https://profile-avatar.csdnimg.cn/default.jpg!1)
lihuapinglee1
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助
![voice](https://csdnimg.cn/release/downloadcmsfe/public/img/voice.245cc511.png)
![center-task](https://csdnimg.cn/release/downloadcmsfe/public/img/center-task.c2eda91a.png)
安全验证
文档复制为VIP权益,开通VIP直接复制
![dialog-icon](https://csdnimg.cn/release/downloadcmsfe/public/img/green-success.6a4acb44.png)