题目:
1、如何使用C++来找出编码88表示的字符?指出至少两种方法。
思路:方法一定义一个字符型变量直接等于88,将其输出结果为编码88表示的字符;方法二使用整形变量来存储88,输出时将其强制转换成字符型。
2、 晶晶赴约会
描述:晶晶的朋友贝贝约晶晶下周一起去看展览,但晶晶每周的1、3、5有课必须上课,请帮晶晶判断她能否接受贝贝的邀请,如果能输出YES;如果不能则输出NO。
输入:输入有一行,贝贝邀请晶晶去看展览的日期,用数字1到7表示从星期一到星期日。
输出:输出有一行,如果晶晶可以接受贝贝的邀请,输出YES,否则,输出NO
思路:本题可以使用switch语句进行选择,按照题目把对应语句进行编写。
3、 根据下述条件的逻辑表达式验证输入输出:
3.1 weight大于或等于155,但小于125;
3.2 ch为q或者为Q;
3.3 x为偶数,但不是26的倍数;
3.4 d位于1000到2000中,或g为1;
3.5 ch是小写英文字母或者大写英文字母;
思路:按照题目要求逐个实现
参考代码:
1、
#include<iostream>
using namespace std;
int main(){
char a=88;
cout<<a<<endl;
int b=88;
cout<<(char)b<<endl;
return 0;
}
2、
#include<iostream>
using namespace std;
int main(){
int riqi;
char i;
cin>>riqi;
switch(riqi){
case 1:i='n';break;
case 2:i='y';break;
case 3:i='n';break;
case 4:i='y';break;
case 5:i='n';break;
case 6:i='y';break;
case 7:i='y';break;
}
if(i=='n')
cout<<"NO"<<endl;
if(i=='y')
cout<<"YES"<<endl;
return 0;
}
3、
#include<iostream>
using namespace std;
int main(){
int weight;
cout<<"请输入weight的值"<<endl;
cin>>weight;
if(weight>=155||weight<125)
cout<<"true"<<endl;
else
cout<<"false"<<endl;
char ch;
cout<<"请输入ch"<<endl;
cin>>ch;
if(ch=='q')
cout<<"是q"<<endl;
if(ch=='Q')
cout<<"是Q"<<endl;
int x;
cout<<"请输入x"<<endl;
cin>>x;
if(x%2==0&&x%26!=0)
cout<<"true"<<endl;
else
cout<<"false"<<endl;
int d,g;
cout<<"请依次输入d,g"<<endl;
cin>>d>>g;
if(d>=1000&&d<=2000||g==1)
cout<<"true"<<endl;
char ch2;
cout<<"请输入ch"<<endl;
cin>>ch2;
if(ch2>='a'&&ch2<='z'||ch2>='A'&&ch2<='z')
cout<<"true"<<endl;
return 0;
}