《C++捷径教程》读书笔记--Chapter 3--基本数据类型

//--《C++捷径教程》读书笔记--Chapter 3--基本数据类型
//--Chapter 3--基本数据类型   
//--11/7/2005 Mon.
//--Computer Lab
//--Liwei

//--程序#1  局部变量的使用
#include <iostream>
using namespace std;
void func();
int main()
{
   int x=10;
   func();
   cout<<"/n";
   cout<<x<<endl;
   return 0;
}

void func()
{
   int x=-199;
   cout<<x;
}

//--程序#2  全局变量的使用
#include <iostream>
using namespace std;
void func1();
void func2();
int count;//
int main()
{
   int i;
   for(i=0;i<10;i++)
   {
      count=i*2;
   func1();
   }

   return 0;
}
void func1()
{
   cout<<"count : "<<count;//全局变量
    func2(); 
   cout<<"/n";
 
}
void func2()
{
   int count;
   for(count=0;count<3;count++)
    cout<<'.'<<"*  ";
}


//--程序#3  有符号数和无符号数的区别
#include <iostream>
using namespace std;
int main()
{
   short int i;
   short unsigned int j;
   j=60000;
   i=j;
   cout<<i<<' '<<j<<endl;
   return 0;
}


//--程序#4  反向输出字母表
#include <iostream>
using namespace std;
int main()
{
   char letter;
   for(letter='Z'; letter>='A'; letter--)
    cout<<" "<<letter;
   cout<<endl;
   cout<<"/n///b/a/?/t/r";
   return 0;
}

//--程序#5  变量初始化的示例程序
#include <iostream>
using namespace std;
void total(int x);
int main()
{
   cout<<"Computing summation of 5./n";
   total(5);

   cout<<"/nComputing summation of 6./n";
   total(6);
   return 0;
}

void total(int x)
{
   int sum=0,i,count;
   for(i=1;i<=x;i++)
   {  
   sum+=i;
   for(count=0;count<10;count++)
    cout<<'.';
   cout<<"the current sum is: "<<sum<<endl;
   }
}

//--程序#6  %的使用
#include <iostream>
using namespace std;
int main()
{
   int x,y;
   x=10;
   y=3;
   cout<<x/y<<endl;
   cout<<x%y<<endl;

   x=1,y=2;
   cout<<x/y<<"  "<<x%y<<endl;
   return 0;
}


//--程序#7  异或运算的使用
#include <iostream>
using namespace std;
bool xor(bool a,bool b);

int main()
{
   bool p,q;
   cout<<"Enter P (0 or 1): ";
   cin>>p;
   cout<<"Enter q (0 or 1): ";
   cin>>q;

   cout<<"p and q: "<<(p&&q)<<endl;
   cout<<"p or q: "<<(p||q)<<endl;
   cout<<"p xor q: "<<xor(p,q)<<endl;
   return 0;
}

bool xor(bool a,bool b)
{
   return (a||b)&&!(a&&b);
}


//--程序#8  强制转换的使用
#include <iostream>
using namespace std;
int main()
{
   int i;
   for(i=0;i<100;i++)
    cout<<i<<"/ 2 is :"<<(float)i/2<<endl;
   return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值