zoukankan      html  css  js  c++  java
  • 20191117-STD::讲解及求平均数例题

    1. #include "stdafx.h" 

    2. #include "cstdio" 

    3. #include "iostream" 

    4. #include "algorithm"

    5.  using namespace std; 

    6.  int main()

    7.  { 

    8.      char grade='A';

    9.      switch(grade)

    10.     {

    11.         case 'A': cout<<"85~100 ";break;

    12.         case 'B': cout<<"70~84 ";break;

    13.         case 'C': cout<<"60~69 ";break;

    14.         case 'D': cout<<"<60 ";break;

    15.         default: cout<<"error ";break;

    16.      }

    17. }

    注释掉using namespace std;,代码如下: 

    1. #include "stdafx.h" 

    2. #include "cstdio" 

    3. #include "iostream" 

    4. #include "algorithm"

    5.  //using namespace std; 

    6.  int main()

    7.  { 

    8.      char grade='A';

    9.      switch(grade)

    10.     {

    11.         case 'A': std::cout<<"85~100 ";break;

    12.         case 'B':  std:: cout<<"70~84 ";break;

    13.         case 'C':  std:: cout<<"60~69 ";break;

    14.         case 'D':  std:: cout<<"<60 ";break;

    15.         default:   std:: cout<<"error ";break;

    16.      }

    17. }

    解题思路:

        如果不加using namespace std;,则cout等命令前需加上std::,如上例,注释掉了using namespace std;,下面的代码做了相应修改.

        下一题,题目:

        随机输入三个带小数的数,求平均值:

    1. #include "stdafx.h" 

    2. #include "cstdio" 

    3. #include "iostream" 

    4. #include "algorithm"

    5.  using namespace std; 

    6.  int main()

    7.  { float a,b,c; 
          cin>>a>>b>>c;

    8.     cout<<(a+b+c)/3;

    9. }

    解题思路:因为是带小数的题,所以用到了FLOAT,求平均数即:(a+b+c)/3

  • 相关阅读:
    MySQL的备份和恢复-mysqldump
    MySQL日志功能详解
    MySQL查询缓存
    MySQL的用户管理
    doc常用命令
    记录mysql语句
    centos常用命令
    centos 7.6
    centos6 常用命令
    centos6.8 安装软件
  • 原文地址:https://www.cnblogs.com/whcsrj/p/12928252.html
Copyright © 2011-2022 走看看