c++判断与推理

#include<iostream>

using namespace std;

int main()

{

string mm,md;

cout<<"一口咬掉牛尾巴(打一字),请猜:"<<endl;

cin>>md;

if (md=="告") 

  cout<<"正确";

else

  cout<<"错了";  

}

思考练习:1.如何多出几道题?

                 2.如何判断数值相等?

                 3.判断输入口令是否正确

学习要点:1.关系表达式、关系运算

拓展练习:乘法口算训练器 

挑战练习:画个圈圈护师傅(判断圆坐标位置)(初中)

思路: 

#include<cmath>   

#include<iostream>

using namespace std;

int main()

{

int r=10;

int x,y;

cout<<"妖怪位置x y:";

cin>>x>>y;

if ___________

  cout<<"啦啦,师傅很安全!";

else

  cout<<"挡挡,打妖怪!";

 }

导入:请用并且、或者、除非造句。

好天运动,坏天读书,总有有益的事要做。

1. 逻辑判断(多条件)

#include<iostream>

using namespace std;

int main()

{

    string tq,jq;

    cout<<"天气怎么样(晴、雨)?"  ;

    cin>>tq;

    cout<<"在假期吗?(在、不在)" ; 

cin>>jq;

    

    if (tq=="晴" && jq=="在" )

      cout<<"去运动!"<<endl;

      

     if (tq=="雨" && jq=="在" )        

      cout<<"读一整本书!"<<endl;

      

    if (jq!="在")           

      cout<<"不是假期呢,我也有好多事做呢!"<<endl;

}

2.逻辑推理(嵌套)

#include<iostream>

using namespace std;

int main()

{

    string tq,jq;

    cout<<"天气怎么样(晴、雨)?"  ;

    cin>>tq;

    cout<<"在假期吗?(在、不在)" ; 

cin>>jq;

    

    if (jq=="在"  )

        if (tq=="雨"  )        

          cout<<"读一整本书!"<<endl;

        else

          cout<<"不下雨就运动!" ;

    else        

      cout<<"不是假期呢,我也有好多事做呢!"<<endl;

}

思考练习:

1.不要一厢情愿,还要综合考虑。多条件判断。哪些事需要多条件判断?

2.逻辑运算组合实验。


学习要点:

1.逻辑表达式、逻辑运算

2.if 嵌套

    

拓展练习:BIM判断(教材)

挑战练习: 

1.字符串包含判断,改成关键词模糊判断

#include <iostream>

#include <string>

using namespace std;

int main()

{

string s="happy new year";

string r="new";

if (s.find(r) < s.length())

{

cout<<s<<"中包含"<<r<<endl;

}

else

{

cout<<s<<"中不包含"<<r<<endl;

}

return 0;

}

 2.设计专题聊天机器人

 使用模糊关键词回答问题。

 
 
 

原文地址:https://www.cnblogs.com/whcsrj/p/12924195.html