C++ Primer Plus第六版编程练习第二章

最近开始刷书 希望别半途而废吧

第二章编程练习本人的答案如下,欢迎讨论纠错

#include <iostream>

using namespace std;

void question1();
void question2();
void question3_1();
void question3_2();
void question4();
void question5();
void question6();
void question7(int hours , int minutes);
 
int main()
{
    /*
    question3_1();
    question3_1();
    question3_2();
    question3_2();
    */
    
    int hours , minutes;
    cout << "Enter the number of hours: ";
    cin >> hours; 
    cout << "Enter the number of minutes: ";
    cin >> minutes;
    question7(hours , minutes);
    
    return 0;
}

void question1()
{
    string name , address;
    cout << "Enter your name:";
    cin >> name;
    cout << endl;
    cout << "Enter your address:"; 
    cin >> address;
    cout << endl;
    cout << "My name is " << name << endl;
    cout << "My address is " << address;
    
    return; 

void question2()
{
    double dis;
    cout << "enter the district in long : ";
    cin >> dis;
    cout << endl;
    cout << "the district in ma : " << 220 * dis << endl;
    
    return;
}

void question3_1()
{
    cout << "Three blind mice" << endl;
    
    return;
}

void question3_2()
{
    cout << "See how they run" << endl;
}

void question4()
{
    int age;
    cout << "Enter your age: ";
    cin >> age;
    cout << endl;
    cout << "which means " << age * 12 << " months" << endl;
    
    return;
}

void question5()
{
    double value;
    cout << "Please enter a Celsius value: ";
    cin >> value;
    cout << endl;
    cout << value << " degrees Celsius is " << 1.8 * value + 32.0 << " degrees Fahrenheit." << endl;
    
    return;
}

void question6()
{
    double value;
    cout << "Enter the number of light years: ";
    cin >> value;
    cout << endl;
    cout << value << " light years = " << 63240 * value << " astronomical units." << endl;
    
    return;
}

void question7(int hours , int minutes)
{
    cout << "Time: " << hours << ":" << minutes << endl;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值