#include<iostream>
#include<cmath>
void simo(int n);
//using namespace std;
int main(void)
{
//std 是库
//namespace是命令空间
using namespace std;//可以去除,用这种方式std::cout
//cout表示输出对象
cout << "C++ RULES";
cout << endl;//重起一行
cout << "helloll";
//第二种形式换行
cout << "You wont regret it!" << endl;
int carrots;
carrots = 25;
int a;
int b;
int c;
//把5传递个3个变量,最后3个变量的值都是5
a = b = c = 5;
cout << endl;
cout << "I have ";
cout << carrots;
cout << endl;
carrots = carrots - 1;
cout << "Crunch,Crunch,Now I Have " << carrots << "carrots." << endl;
int carrostr;
cout << "how many carrtos do you have" << endl;
//代表输入,进行捕获
cin >> carrostr;
cout << "Here are two more.";
carrostr = carrostr + 2;
cout << "Now you have" << carrostr << "carrostr." << endl;
double area;
cout << "Enter the floor area, in square feet , of your home: ";
cin >> area;
//计算出平方
double side;
side = sqrt(area);
cout << "That's the equivalent of asquare " << side << "feet to the side" << endl;
simo(3);
cout << "pick an integer: ";
int count;
cin >> count;
simo(count);
bool is_ready = true;
int ans = true; //true 将被转换为1
int promise = false;//将被转换为0
//同样,任何数字类型或指针隐私转换为bool值
bool start = -100; //true
bool stop = 0; //false
//const 限定符,和java中final有点相似,也可以用define,但const相对较好,可以使用C++作用域规则将定义限制在函数或文件中,也可以用于更复杂的类型
const int Months = 12;
//在c++中,和java不同,多了long double类型 ,通常,float至少为32位,double为64位,long double 为80 , 96,或128位
cout.setf(ios_base::fixed, ios_base::floatfield);
float tub = 10.0 / 3.0;
const float million = 1.0E6;
cout << "tub = " << tub << endl; //3.333333
//如若乘100万被
cout << "a million tubs = " << million * tub << endl; //3333333.250000;
//如若扩大1000万背,则超出范围值,后面会有0值出现,不同于java,java超出范围会报错。
cout << "Ten million tubs = " << 10 * million * tub << endl;//33333332.000000
//可以使用double来接收
//double mint = 10.0 / 3.0;
//cout << "mint = " << mint << endl;
//cout << "a million mints = " << million * mint << endl;
//浮点数在做运算时,精度会降低
float a = 2.34E22;
float b = a + 1.0;
//浮点数运算比整数慢,精度会有所降低
cout << "a = " << a << endl;
cout << "b - a = " << b - a << endl;
return 0;
}
void simo(int n)
{
using namespace std;
cout << "Simon toes" << n << " toms/" << endl;
}
学习C++的第一天
最新推荐文章于 2024-10-12 22:47:18 发布
这篇文章介绍了C++的基础知识,包括使用iostream库进行输入输出,利用namespace管理命令空间,以及如何声明和使用变量。文中展示了如何进行算术运算,如变量赋值和浮点数计算,并提到了精度问题。此外,还讨论了const常量的使用和函数调用。
摘要由CSDN通过智能技术生成