C++ Pimer Plus课后编程练习个人代码

C++ Pimer Plus(第6版中文)课后编程练习个人代码

2.7


1.

#include <iostream>

using namespace std;

int main()
{


      cout << " Name " << endl;
         cout << " Address is  "  << endl;
    return 0 ;
}

2.

#include <iostream>

using namespace std;

double Mar(int);

int main()
{
    int Long;
    cout << " Enter Long : " << endl;
      cin >> Long ;
      double mar = Mar(Long);
      cout << " Mar is : " << mar << endl;
    return 0;
}

double Mar(int Long)
{
 double Mar;
 Mar = Long /220;
 return Mar ;
}

3.

#include <iostream>

using namespace std;

void fun1()
{
    cout << " Three blind mice " << endl;

}

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

}
int main()
{
   fun1();
    fun1();
   fun2();
   fun2();
    return 0;
}

4.

#include <iostream>

using namespace std;

int exchange(int);

int main()
{
   cout << "Enter your age : " ;
   int age;
   cin >> age ;
   int month = exchange(age);
     cout << "The month of your age is : " << month << endl;
    return 0;
}

int exchange(int age)
{
   return age*12 ;
}

5.

#include <iostream>

using namespace std;

int exchange(int);

int main()
{
   cout << "Please enter a Celsius value : " ;
   int celsius;
   cin >> celsius ;
   int Fahrenheit = exchange(celsius);
     cout << celsius << " degrees Celsius is " << Fahrenheit << " degrees Fahrenheit."<< endl;
    return 0;
}

int exchange(int celsius)
{
   int Fahrenheit;
   Fahrenheit = 1.8 * celsius +32.0;
   return Fahrenheit ;
}

6.

#include <iostream>


double exchange(double);

int main()
{

    using namespace std;
    cout << " Enter the number of light years: ";
    double lightyears;
    cin >> lightyears;
    double astronomicunits = exchange(lightyears);
    cout << lightyears << " light years = " << astronomicunits << " astronomic units." << endl;
    return 0;
}

double exchange(double lightyears)
{
    double astronomicunits = lightyears*63240 ;
    return astronomicunits;
}

7.

#include <iostream>
using namespace std;

void time(int,int);

int main()
{
    cout << " Enter the number of hours: ";
    int hours;
    cin >> hours;
    cout << " Enter the number of minutes: ";
    int minutes;
    cin >> minutes;
    time(hours,minutes);
    return 0;
}

void time(int hours , int minutes)
{

    cout << "Time :"<< hours << ":" << minutes << endl;
}

教训:1.一定注意函数的命名前后一致不然出错,一定要仔细;

2.函数的参数成员赋值可以直接将变量放入自动赋值如第7题

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值