zoukankan      html  css  js  c++  java
  • 第四章 C++数据类型 简单

    //1 C++数据类型
    #include <iostream>
    int add(int x, int y)
    {
        return x+y;
    }
    int main()
    {
        int i=1, y=2;
    	std::cout<<add(i,y);
        return 0;
    }
    
    // 2什么是变量
    #include <iostream>
    using namespace std;
    int main()
    {
        int a = 35;
    	cout<<"a的值是:"<<a<<endl;
    	cout<<"请输入数值:"<<endl;
    	cin>>a;
    	cout<<"现在a的值是:"<<a<<endl;
    
    	return 0;
    }
    
    // 4 布尔值
    /*
    #include <iostream>
    using namespace std;
    int main()
    {
        bool check = true;
    	if(check == true)
    	{
    	     cout<<"hello world\n";
    	}
    	return 0;
    }
    
    
    //5 字符型
    /*
    #include <iostream>
    using namespace std;
    int main()
    {
        cout<<"特殊字符";
    	char ch='\r';
    	//由于反斜杠'\'改变了其后字母的含义,因此它又叫做转义字符
    	cout<<ch<<"特殊用途";
    	return 0;
    }*/
    
    /*
    // 6 双字节型
    // 我们知道char型变量可存储一个字节的字符,它用来保存英文字符与标点符号是可以的,但是存储汉字,韩文与日文却不可以,因为汉字,韩文与日文都占据两个节字,为了解决这个问题,C++又提供了解wchar_t类型,也就是双字节类型,又叫宽字符类型
    #include <iostream>
    #include <locale>
    using namespace std;
    int main()
    {
    	 //由于"中"是个汉字,所以我们需要调用一个函数来将本机的语言设置为中文简体
         setlocale(LC_ALL,"chs");
    
    	 wchar_t wt[] = L"中";
    	 //大字子母L告诉编译器为"中"字分配两个字节的空间
    
    	 //使用wcout替代cout来输出宽字符
    	 wcout<<wt;
    	 return 0;
    }
    */
    
    /*
    // 7 整型概述
    #include <iostream>
    using namespace std;
    int main()
    {
    	cout<<"int:"<<sizeof(int)<<endl;
    	cout<<"short:"<<sizeof(short)<<endl;
    	cout<<"long"<<sizeof(long)<<endl;
    	unsigned short a;
    	cout<<"unsigned short:"<<sizeof(unsigned short)<<endl;
    	cout<<"unsigned int:"<<sizeof(unsigned int)<<endl;
    	cout<<"unsigned long:"<<sizeof(unsigned long)<<endl;
    
        return 0;
    
    }
    */
    
    /*
    // 9 整型变量的定义
    #include <iostream>
    using namespace std;
    int main()
    {
    	short a, b;
    	a = 32767;
    	b = a+1;
    	cout<<"a:"<<a<<"\n"<<"b:"<<b<<endl;
        //从该程序中我们看出整型数据溢出后不会报错,而是像汽车里程表那样,到达最大值后,又从最小值开始计数,因此我们需要时刻注意所定义变量的最大取值范围,一定不要超过这个范围进行赋值
    
    	return 0;
    }
    */
    
    /*
    
    // 10 浮点型变量
    #include <iostream>
    #include <iomanip>
    using namespace std;
    int main()
    {
    	float a = 12.3456789012345;//float的小数精度可能只在5, 到6位情况
        cout<<setprecision(15)<<a<<endl;
        //如果对精度要求很高,可以用double
    	double b = 12.3456789012345;
    	cout<<b<<endl;
    	return 0;
    }
    
    */
    
    /*
    // 11 常量
    #include <iostream>
    using namespace std;
    int main()
    {
    	const double PI = 3.1415926;
    	//PI = 0; 常量一旦定义后,就不能在进行修改了
    	const char ch='s';
    	cout<<"ch:"<<ch<<", PI:"<<PI<<endl;
        return 0;
    }
    */
    
    //12 枚举型常量
    #include <iostream>
    using namespace std;
    int main()
    {
    	enum day{Sunday, Monday, Tueday,Wednerday, Thursday};
    	day today;
    	today = Sunday;
    	if(today == Sunday)
    	{
    	    cout<<"周末休息";
    	}else{
    	    cout<<"现是工作";
    	}
        return 0;
    }
    

      

  • 相关阅读:
    ACM ICPC 2008–2009 NEERC MSC A, B, C, G, L
    POJ 1088 滑雪 DP
    UVA 11584 最短回文串划分 DP
    POJ 2531 Network Saboteur DFS+剪枝
    UVa 10739 String to Palindrome 字符串dp
    UVa 11151 Longest Palindrome 字符串dp
    UVa 10154 Weights and Measures dp 降维
    UVa 10271 Chopsticks dp
    UVa 10617 Again Palindrome 字符串dp
    UVa 10651 Pebble Solitaire 状态压缩 dp
  • 原文地址:https://www.cnblogs.com/xiangxiaodong/p/2552896.html
Copyright © 2011-2022 走看看