码迷,mamicode.com
首页 > 编程语言 > 详细

C++学习心得

时间:2015-09-07 22:31:59      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:

习题答案:2.7

 

5.

#include <iostream>

using namespace std;

void Fah();

int main()

{

  Fah();

  return 0;

}

 

void Fah()

{

           int Celsius;

           cout<<"Please enter a Celsius value:";

           cin>>Celsius;

           double Fahrenheit;

           Fahrenheit=1.8*Celsius+32.0;

           cout<<Celsius<<"degrees Celsius is"<<Fahrenheit<<"degrees Fahrenheit."<<endl;

           int i;

           cin>>i;

}

 

技术分享

错误原因:没有在头文件中写申明//void Fah();

运行结果:

技术分享

6.#include <iostream>

using namespace std;

void change();

int main()

{

  change();

  int i;

  cin>>i;

  return 0;

}

 

void change()

{

           double light;

           cout<<"Please enter the number of light years:";

           cin>>light;

           double ast;

           ast=63240*light;

           cout<<light<<"light years"<<ast<<"astronomical units."<<endl;

            

}

运行结果 技术分享

7.#include <iostream>

using namespace std;

void see(int hours,int minutes);//里面的参数将决定主函数中调用参数的个数

int main()

{

           cout<<"Enter the number of hours:";

           int hours;

           cin>>hours;

           cout<<"Enter the number of minutes:";

           int minutes;

           cin>>minutes;

           see(hours,minutes);

 

 

  int i;

  cin>>i;

  return 0;

}

 

void see(int hours,int minutes)

{

            

            

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

            

}

技术分享

 

C++学习心得

标签:

原文地址:http://www.cnblogs.com/FFDC3EM/p/4790054.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!