C++ Primer Plus(第6版) 中文版 第二章编程练习

测试时分开测试

#include <iostream>
void threeTest1();
void threeTest2();
void fiveTest1(float celsius);
void sixTest1(double  lightYears);
void sevenTest1(int hour,int minute);

int main()
{

    //1
    std::cout<<"姓名:Ryan"<<std::endl;
    std::cout<<"地址:深圳"<<std::endl;

    //2
    int number;
    std::cout<<"请输入你的距离长度:";
    std::cin>>number;
    std::cout<<"长度为:"<<number*220<<"码"<<std::endl;

    //3
    threeTest1();
    threeTest1();
    threeTest2();
    threeTest2();

    //4
    int age;
    std::cout<<"Enter your age:";
    std::cin>>age;
    std::cout<<"Your age:"<<age*12<<std::endl;;

    //5
    float celsius;
    std::cout<<"Please enter a Celsius value:";
    std::cin>>celsius;
    fiveTest1(celsius);


    //6
    double lightY;
    std::cout<<"Enter the number of light years :";
    std::cin>>lightY;
    sixTest1(lightY);

    //7
    int hour,minute;
    std::cout<<"Enter the number of hours :";
    std::cin>>hour;

    std::cout<<"Enter the number of minutes :";
    std::cin>>minute;

    sevenTest1(hour,minute);


}

void threeTest1()
{
    std::cout<<"Three blind mice"<<std::endl;
}
void threeTest2()
{
    std::cout<<"See how they run"<<std::endl;
}
void fiveTest1(float celsius)
{

    std::cout<<celsius<<" degrees Celsius is "
             <<celsius*1.8+32.0
             <<" degress Fahrenheit."
             <<std::endl;

}
void sixTest1(double lightYears)
{

    std::cout<<lightYears<<" light years = "
             <<lightYears*63240
             <<" astronomical units."
             <<std::endl;

}
void sevenTest1(int hour,int minute)
{
    //时间不在规定范围内无效直接返回,不执行之后的语句
    if(!(hour<24)||!(minute<60))
    {
        std::cout<<"Enter is invalid"<<std::endl;
        return;
    }
    std::cout<<"Time: "<<hour<<":"<<minute
             <<std::endl;

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值