加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

摄氏度——华氏度转换器(C++代码)

(2010-12-24 18:29:53)
标签:

函数

摄氏温度

摄氏温标

转换器

c代码

it

分类: 编程

//摄氏度与华氏度的转换

#include <iostream>

#include<iomanip>

using namespace std;

float c,f;         //c为摄氏度,

int select;        //选择功能变量,1为摄氏度转华氏度,2为华氏度转摄氏度

char character;    //是否继续接收YN的变量

 

//主函数

int main()

{

    float transform1(float);        //摄氏度转华氏度(计算)

    float transform2(float);        //华氏度转摄氏度(计算)

    void Celsius_to_Fahrenheit();   //转换函数1(摄氏度转华氏度,调用计算函数后输出结果)

    void Fahrenheit_to_Celsius();   //转换函数2(华氏度转摄氏度,调用计算函数后输出结果)

while(1)

{   cout<<endl;

    cout<<"\t\t\t    华氏——摄氏温标转换器≮"<<endl<<endl;

    cout<<"\t\t\t       ********************"<<endl;

    cout<<"\t\t\t       1.摄氏度转华氏度 *"<<endl;

    cout<<"\t\t\t       2.华氏度转摄氏度 *"<<endl;

    cout<<"\t\t\t       3.退出           *"<<endl;

    cout<<"\t\t\t       ********************"<<endl<<endl;

    cout<<"\t\t\t       请选择:";

    cin>>select;

    system("cls");

switch(int(select))

    {

        case 1:Celsius_to_Fahrenheit();

            break;

        case 2:Fahrenheit_to_Celsius();

            break;

     case 3:system("cls");

            cout<<"程序作者:**"<<endl;

            cout<<"学号:209*******"<<endl;

            cout<<"班级:计算机***班"<<endl;

            cout<<"电话:138********/6*****"<<endl;

            cout<<"QQ:67*******"<<endl;

            system("pause");

            exit(0);

     default:cout<<endl<<"\t\t\t       你的输入有误,请重新输入!";

    }

}   

    cin.get();

    return 0;

}

 

float transform1(float  //计算摄氏度

{

c=5.0/9*(f-32);

return c;

}

 

float transform2(float  //计算华氏度 

{

f=(9.0/5)*c+32;

return f;

}

 

void Celsius_to_Fahrenheit(void //摄氏度转华氏度 

{

while(1)

{

 cout<<endl<<"\t\t\t       ﹦摄氏度转华氏度﹦"<<endl;

 cout<<"\t\t\t       请输入一个摄氏温度:";

 cin>>c;

 cout<<"\t\t\t       华氏度:"<<setprecision(3)<<transform2(c)<<endl;

 cout<<"\t\t\t       是否继续?(Y/N)";

 cin>>character;

 system("cls");

 if(character=='Y'||character=='y')

 continue;

 else if(character=='N')break;

 else cout<<endl<<"\t\t\t       你的输入有误,请重输:";

}

}

               

void Fahrenheit_to_Celsius(void  //华氏度转摄氏度

{

while(1)

{

  cout<<endl<<"\t\t\t       ﹦华氏度转摄氏度﹦"<<endl;

  cout<<"\t\t\t       请输入一个华氏温度:";

  cin>>f;

  cout<<"\t\t\t       摄氏度:"<<setprecision(3)<<transform1(f)<<endl;

  cout<<"\t\t\t       是否继续?(Y/N)";

  cin>>character;

  system("cls");

  if(character=='Y'||character=='y')

  continue;

  else if(character=='N')break;

  else cout<<endl<<"\t\t\t       你的输入有误,请重输:";

}

}

 

//本程序还有一个错误等更正,就是在主界面时如果输入字母或其它符号,会死循环。

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有