C++第一次作业

C++作业1

  • 1、

编写一个程序,要求从屏幕输入你的名字和年龄,在屏幕显示你的名字和你明年的年龄。
代码:

#include <iostream>
#include <string>
using namespace std;
int main()
{
string sName;
int iAge;
cout<<"请输入名字:";
cin>>sName;
cout<<"请输入年龄:";
cin>>iAge;
cout<<"我的名字是"<<sName<<",我今年"<<iAge<<"岁了,我明年"<<iAge+1<<"岁了。"<<endl;
return 0;
}
  • 2、

在屏幕上输入两个整数,求两个数的差,并将结果运算出来。
代码:

#include <iostream>
#include <string>
using namespace std;
int main()
{
int a;
int b;
cout<<"请输入第一个整数:";
cin>>a;
cout<<"请输入第二个整数:";
cin>>b;
cout<<"您输入的第一个数是"<<a<<"您输入的第二个数是"<<b<<"两个整数的差是"<<a-b<<"。"<<endl;
return 0;
}

  • 3、

从屏幕上输入3个整数,计算后,输出最大的数。
代码:

#include <iostream>
using namespace std;
int main()
{
int a,b,c,max;
cout<<"请输入三个整数(用空格隔开)";
cin>>a>>b>>c;
max=(a>b)?a:b;
max=(max>c)?max:c;
cout<<"最大的数数:"<<max<<endl;
    return 0;
}
  • 4、

从屏幕上输入一个成绩(整数)然后输出相应的等级(100-90:优秀;89-70:良好;69-60:及格;59-0:不及格;其他:非法输入)
代码:

#include<iostream>
using namespace std;
int main()
{
int score;
cout << "请输入成绩:" << endl;
cin >> score;
if (score > 100)
cout << "非法输入" << endl;
else if (score >= 90 && score <= 100)
cout << "成绩为:优秀" << endl;
else if (score >= 70 && score <=89)
cout << "成绩为:良好" << endl;
else if (score >= 60 && score <=69)
cout << "成绩为:及格" << endl;
else if (score >= 0 && score <=59)
cout << "成绩为:不及格" << endl;
else
cout << "非法输入" << endl;
    return 0;
}
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值