您的位置:首页 > 其它

第三周作业

2014-05-07 12:44 411 查看
[cpp] view
plaincopy





#include "stdafx.h"    

#include<iostream>    

#include<iomanip>    

using namespace std;    

int main()    

{    

    bool love=true;    

    cout<<love<<endl;    

    cout<<boolalpha<<love<<endl;    

    cout<<love+5<<endl;    

    love=0;    

    cout<<"执行语句love=0;后love的值为:"<<boolalpha<<love<<endl;    

    love=0.0;    

    cout<<"执行语句love=0.0;后love的值为:"<<boolalpha<<love<<endl;    

    return 0;    

}  

  


例2.2

[cpp] view
plaincopy





#include "stdafx.h"    

#include<iostream>    

#include<iomanip>    

using namespace std;    

int main()    

{    

    int a,b,c,d;  

a=5,b=5;  

b%=4;  

c=d=a;  

c*=a;  

d%=a+b;  

  cout<<"a="<<a<<endl;  

  cout<<"b="<<b<<endl;  

  cout<<"c="<<c<<endl;  

  cout<<"d="<<d<<endl;  

    return 0;    

}    



例题2.3

[cpp] view
plaincopy





#include "stdafx.h"    

#include<iostream>   

using namespace std;  

int main()    

{    

    short a,b,c,d;   

    a=1000;  

b=500;  

if (a>b)  

{c=a+b;  

d=a*b;}  

else  

{c=a*b,d=a+b;}  

cout<<"c="<<c<<endl;  

    cout<<"d="<<d<<endl;      

      

    return 0;  

}    



例题2.4

[cpp] view
plaincopy





#include "stdafx.h"    

#include<iostream>   

using namespace std;  

int main()    

{    

    int a=5,b,c;  

a=++a;  

b=a++;  

c=++b;  

++a=1;  

cout<<"a="<<a<<endl;  

cout<<"b="<<b<<endl;  

cout<<"c="<<c<<endl;  

      

    return 0;  

}    



例题2.7

[cpp] view
plaincopy





#include "stdafx.h"    

#include<iostream>    

using namespace std;    

int main()    

{    

    int ab,bc;    

    double b=3.14;    

    char c='A';    

    ab=int(b);    

    bc=int(c);    

    cout<<"b="<<b<<endl;    

    cout<<"ab="<<ab<<endl;    

    cout<<"c="<<c<<endl;    

    cout<<"bc="<<bc<<endl;    

    return 0;    

}   

计算三角形的周长和面积

 

[cpp] view
plaincopy





#include "stdafx.h"   

#include<iostream>    

#include<cmath>  

using namespace std;  

int main()    

{    

    int a,b,c,p,d,s;  

cout<<"请分别输入三条边:";  

cin>>a>>b>>c;  

if ((a+b<c)||(a+c<b)||(b+c<a))  

cout<<"不能构成三角形"<<endl;  

else  

{  

d=a+b+c;  

p=d/2;  

s=sqrt(p*(p-a)*(p-b)*(p-c));   

cout<<"周长="<<d<<endl;  

cout<<"面积="<<s<<endl;  

}  

  

  

    return 0;    

}   

习题3

[cpp] view
plaincopy





#include "stdafx.h"   

#include<iostream>    

#include<math.h>    

using namespace std;    

    

int main()    

{    

    int e=1,f=4,g=2,a=7;    

    float m=10.5,n=4.0,k;    

    float x=2.5,y=4.7,z;    

    k=(e+f)/g+sqrt((double)n)*1.2/g+m;    

    z=x+a%3*(int(x+y)%2)/4;    

    cout<<"k="<< k<<endl    

        <<"z="<<z<<endl;    

    return 0;    

}    



求一元二次方程

[cpp] view
plaincopy





#include "stdafx.h"   

#include<iostream>    

#include<math.h>    

using namespace std;    

    

int main()    

{    

    int a,b,c,x1,x2,t;      

    cout<<"请分别输入方程二次项、一次项、常数项系数"<<endl;      

    cin>>a>>b>>c;      

    t=b*b-4*a*c;      

    if(t>=0)      

    {      

        x1=(-b+sqrt(t))/(2*a);      

        x2=(-b-sqrt(t))/(2*a);      

        cout<<"x1="<<x1<<endl<<"x2="<<x2<<endl;      

    }      

    else      

    {    

       cout<<"方程没有实数解";   

    }      

    return 0;    

}    

5.编写程序,自己确定一个加密算法,将自己的音标姓名(英文)加密,并输出加密后结果,请注释你的加密算法。

[cpp] view
plaincopy





#include "stdafx.h"   

#include<iostream>    

#include<math.h>    

using namespace std;    

    

int main()    

{  char ch1,ch2,ch3;  

cout<<"请输入名字音标:";  

cin>>ch1,ch2,ch3;  

ch1=ch1>='a'&&ch1<='z'?ch1-'a'+'9':ch1;  

ch2=ch2>='a'&&ch2<='z'?ch2-'a'+'4':ch2;  

ch3=ch3>='a'&&ch3<='z'?ch3-'a'+'8':ch3;  

cout<<"加密后:"<<ch1<<ch2<<ch3<<endl;  

    return 0;    

}    

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: