《C++捷径教程》读书笔记--Chapter 3--基本数据类型
2005-11-07 21:18
756 查看
//--《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;
}
//--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;
}
相关文章推荐
- 《C++捷径教程》读书笔记--Chapter 9--更多的数据类型与运算符(第一部分)
- 《C++捷径教程》读书笔记--Chapter 9--更多的数据类型与运算符(第二部分)
- Chapter 3、Java语法基础(二)----Java基本数据类型、变量与常量 (20th,Feb)
- oracle读书笔记-----PL/SQL编程(一)之基本数据类型、程序结构
- 读书笔记:Java基本数据类型的强制转换
- 读书笔记 JavaScript高级程序设计 第三章 基本概念-数据类型
- oracle读书笔记-----PL/SQL编程(一)之基本数据类型、程序结构
- oracle读书笔记-----PL/SQL编程(一)之基本数据类型、程序结构
- Safe C++ 读书笔记:对基本数据类型进行封装,以编写更安全的C++代码
- 代码大全第二版读书笔记 第三部分-变量 十二、基本数据类型 十三、不常见的数据类型
- 黑马程序员——StringBuffer、基本数据类型
- 基于 Android NDK 的学习之旅-----数据传输(基本数据类型和数组传输)
- Python基本数据类型初识
- 浅谈数据类型转换之基本类型
- 直接a=b,对象克隆会有问题,但是为什么基本数据类型,String Integer等就没问题?
- redis基本数据类型-redis系列教程
- 基本数据类型--取值范围
- 基本数据类型与引用类型的存储位置引发的疑问
- Java中八种基本数据类型的默认值
- C/C++基本数据类型所占字节数