C++ PRIMER PLUS第六版课后编程题答案3.1–3.7


 

 

//3.1

#include <iostream>
const char c=10;

int main31()
{
	using namespace std;
 cout<<"please enter your level"<<c<<endl;
 int l;
 cin>>l;
 cout<<"your level is"<<l*c<<endl;
 cin.get();
 cin.get();
 return 0;
 
     
    
} 

3.2

//3.2
#include <iostream.h>
#include <math.h>
const int CToC=12; //1英尺=12英寸 
const double KToB=2.2;//1KG=2.2磅 
const float CToM=0.0254;//1英尺=0.0254m 


int main()
{
    cout<<"Enter your Level:(英尺)";
    int yc;
    cin>>yc;
    cout<<"Enter your level:(英寸)";
    int yci;
    cin>>yci;
    cout<<"\nNow Enter your Weight:"<<endl;
    double w;
    cin>>w;
    int l=yc*CToC+yci;
    float li=l*CToM;
    double wi=w*KToB; 
    double bmi=wi/sqrt(li);
    cout<<"BMI="<<bmi;
    cin.get();
    cin.get();
    return 0;
    
}

 

3.3

//3.3

#include <iostream.h>

const int DToM=60;
const int MToS=60;

int main()
{
 cout<<"Enter a latitude in degrees,Minute,an seconds:"<<endl;
 cout<<"First,enter the degreess:";
 int d;
 cin>>d;
 cout<<"\nNext,enter the minutes of arc:";
 int m;
 cin>>m;
 cout<<"\nFinally,enter the seconds of arc:";
 int s;
 cin>>s;
 cout<<d<<" degreess ,"<<m<<" minutes, "<<s<<" seconds"
                    <<"="<<float(m/DToM+s/MToS/DToM+d)<<"degress"<<endl;
    cin.get();
    cin.get();
    return 0;
}

 

3.4-3.7懒得找了,这一章就发这两道算了

 

 


发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注