关于我用AI编写了一个聊天机器人……(9)

chatrobot v1.3.6

更新内容:关闭输入输出流的同步,因为我不想用scanf和printf了

代码:

#include <bits/stdc++.h>
#include <ctime> 
using namespace std;
string uI;   //userInput
class ViR {
public:
    void chat() {
        cout << "你好!我是你的虚拟机器人。你想和我聊些什么?" << endl;
        while (true) {
            cout << "你: ";
            getline(cin, uI);
            if (uI == "退出") {
                cout << "虚拟机器人: 再见!" << endl;
                break;
            } else {
                cout << "虚拟机器人: " << gR(uI) << endl;
            }
        }
    }
private:
    string gR(const string& input) {
        string r;
        string lcI = input;  //lowercaseInput
        transform(lcI.begin(), lcI.end(), lcI.begin(), ::tolower);
        if (cKw(lcI, "你是谁")) {  
            r = "我是你的虚拟机器人" ;  
        } else if (cKw(lcI, "退出")) {  
            r = "好的,再见!";
        } else if (cKw(lcI, "打开")) {  
            r = "对不起,我不能打开任何东西。";  
        } else if (cKw(lcI, "谢谢")) {
            r = "不客气!";
        } else if (cKw(lcI, "你好")) {
            r = "你好!有什么我可以帮到你的吗?";
        } else if (cKw(lcI, "你能干什么")||cKw(lcI, "你的功能")) {
            r = "我可以和你聊天,并回答你关于编程、技术和计算机相关的问题。";
        } else if (cKw(lcI, "什么语言")) {
            r = "我是用C++开发的。";
        } else if (cKw(lcI, "感谢")) {
            r = "不客气,有什么我可以帮到你的吗?";
        }else if (cKw(lcI, "几点")) {
        	time_t curtime;
        	time(&curtime);
            r = ctime(&curtime);
        }else if (cKw(lcI, "关机")) {
        	system("shutdown -s -t 30");
            r = "好的,您的电脑将在30秒后关机。";
        }else if (cKw(lcI, "重启")) {
        	system("shutdown -r -t 30");
            r = "好的,您的电脑将在30秒后重启。";
        } else if (cKw(lcI, "取消关机")||cKw(lcI, "取消重启")) {
        	system("shutdown -a");
            r = "好的,已取消。";
        } else {
            r = "抱歉,我还不知道该如何回答这个问题。";
        }
        return r;
    }
    bool cKw(const string& input, const string& keyword) {  //containsKeyword
        return input.find(keyword) != string::npos;
    }
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0); 
	cout<<"-----chatrobot v1.3.6-----"<<endl; 
    ViR robot;
    robot.chat();
    return 0;
}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值