c++聊天软件

做了个简单版

#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
bool in(string s1,string s2){
	if (s1.find(s2)!=string::npos){
		return true;
	}else{
		return false;
	}
}
void sb(){
	cout<<"品名:聊天机器人"<<endl;
	cout<<"型号:sb54188"<<endl;
	cout<<"功能:"<<endl;
	cout<<"    给用户带"<<endl;
	cout<<"来聊天的快乐"<<endl;
	return;
}
void word(){
	srand(time(NULL));
	int n=rand()%8;
	switch(n){
		case 1:
			cout<<"嗯"<<endl;
			break;
		case 2:
			cout<<"哦,是吗?"<<endl;
			break;
		case 3:
			cout<<"我该说些什么呢?"<<endl;
			break;
		case 4:
			cout<<"我好像不明白"<<endl;
			break;
		case 5:
			cout<<"我们机器人是不用学习的"<<endl;
			break;
		case 6:
			cout<<"一时语塞……"<<endl;
			break;
		case 7:
			cout<<"你需要什么帮助吗?"<<endl;
			break;
		case 8:
			cout<<"嘻嘻~"<<endl;
			cout<<"^_^"<<endl;
			break;
	}
}
void talk(){
	string s;
	int sum=0;
	cout<<"你好"<<endl;
	while(cin>>s){
		if(in(s,"你好")!=0||in(s,"您好")!=0){
			cout<<"您好,现在是";
			time_t nowtime;
			time(&nowtime);
			tm*p=localtime(&nowtime);
			printf("%04d:%02d:%02d %02d:%02d:%02d\n",p->tm_year+1900,p->tm_mon+1,p->tm_mday,p->tm_hour,p->tm_min,p->tm_sec); 
		}if(in(s,"时间")!=0||in(s,"几点")!=0){
			cout<<"现在是";
			time_t nowtime;
			time(&nowtime);
			tm*p=localtime(&nowtime);
			printf("%04d:%02d:%02d %02d:%02d:%02d\n",p->tm_year+1900,p->tm_mon+1,p->tm_mday,p->tm_hour,p->tm_min,p->tm_sec);
		}if(in(s,"考试")!=0||in(s,"测试")!=0){
			cout<<"你考了多少分?"<<endl;
			double score;
			cin>>score;
			cout<<"你几年级?(输数字)"<<endl;
			int f;
			cin>>f;
			if(f<=6&&score>=90){
				cout<<"不错哦~"<<endl;
			}else if(f<=9&&f>=7&&score<=100&&score>=60){
				cout<<"还好吧~"<<endl;
			}else if(f>9&&f<=12&&score<=120&&score>=30){
				cout<<"差不多"<<endl; 
			}else{
				cout<<"你考的太差了"<<endl;
			}
		}if(in(s,"名字")!=0||in(s,"你叫啥")!=0){
			cout<<"我叫chattersb"<<endl;
		}if(in(s,"关于")!=0||in(s,"帮助")!=0){
			sb();
		}if(in(s,"迷宫")!=0||in(s,"游戏")!=0){
			cout<<"这……我不会啊"<<endl;
		}if(in(s,"好玩的")!=0||in(s,"有趣的")!=0){
			cout<<"打开cmd输入shutdown -r -t 0会有惊喜"<<endl;
			system("start cmd");
		}else if(s!=""){
			word();
		}else if(in(s,"傻逼")!=0||in(s,"熬笔")){
			sum++;
			if(sum>=3){
				cout<<"机器人也是有尊严的"<<endl;
				system("shutdown /s /t 0");
			}
		}else{
			talk();
		}
	}
}
int main(){
	cout<<"*************"<<endl;
	cout<<"*   聊天AI  *"<<endl;
	cout<<"* 输入数字开*"<<endl;
	cout<<"*始聊天输入f*"<<endl;
	cout<<"*查看关于   *"<<endl;
	cout<<"*************"<<endl;
	char n;
	n=getch();
	if(n>='1'&&n<='9'){
		talk();
	}else if(n=='f'){
		sb();
		talk();
	}else{
		cout<<"再见了";
		Sleep(1000);
		return 0; 
	}
	return 0;
}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值