第三周作业

来源:互联网 发布:国服魔兽世界mac版 编辑:程序博客网 时间:2024/05/17 00:05
作业第二题
/********************************************** **  计算三角形的面积以及周长  ** **  自动化1124曾树彪         ** **********************************************/    #include <iostream>                            #include<math.h>                                using namespace std;                            int main ()                                  {      float a,b,c,d,e;                               double mianji,zhouchang;    shuru:                                            cout<<"请输入所求三角形的三条边"<<endl;        cin>>a>>b>>c;      if(a+c>b&&a+b>c&&c+b>a)                         {          d=(a*a+b*b-c*c)/(2*a*b);                        e=sqrt(1-d*d);                                mianji=0.5*a*b*e;                               zhouchang=a+b+c;                               cout<<"该三角形的面积为"<<mianji<<endl                     <<"该三角形的周长为"<<zhouchang<<endl;          goto shuru;                                 }      else                                            {          cout<<"输入有错,请确认边长是否能构成三角形后重新输入"<<endl;          goto shuru;      }        return 0;    }  
作业第三题
#include<iostream>    #include <math.h>    using namespace std;        int main()    {        int e=1,f=4,g=2;        float m=10.5,n=4.0,k;        k=(e+f)/g+sqrt((double)n)*1.2/g+m;        cout<<k<<endl;        float x=2.5,y=4.7,z;        int a=7;        z=x+a%3*(int(x+y)%2)/4;        cout<<z<<endl;          return 0;    }  
作业第四题
/******计算一元二次方程******/    #include <iostream>  #include <math.h>                      using namespace std;    int main()  {      float a, b, c;                             double x1, x2, k;      cout<<"请输入二次项系数: "<<endl;      cin>>a;      cout<<"请输入一次项系数: "<<endl;      cin>>b;      cout<<"请输入常数项: "<<endl;      cin>>c;        k = b*b-4*a*c;                               x1 = (-b+sqrt(k))/(2*a);      x2 = (-b-sqrt(k))/(2*a);            if(k>=0)                                   {                 if(x1==x2)          {              cout<<"一元二次方程的解只有1个,x= "<<x1<<endl;          }          else          {              cout<<"一元二次方程的解有2个,x1= "<<x1                  <<"   x2= "<<x2<<endl;          }      }      else      {          cout<<"一元二次方程有虚根,x1=i* "<<x1                         <<"   x2=i* "<<x2<<endl;      }        return 0;  } 
作业第五题
#include <iostream>   #include <string>    using namespace std;        int main()    {        const int Size=20;        string name;        int num,i,name_num[Size];        cout << "Pleast enter your name :";        cin >> name;        cout << endl;        cout << "Please enter a number you like and don't forget: ";        cin >> num;        cout << endl;        for (i=0;name[i]!='\0';i++)        {           name_num[i]=int(name[i]);           name_num[i]=name_num[i] ^ num;        }        cout << "After the name Encryption :";        for (i=0;name[i]!='\0';i++)        {           cout << name_num[i]<<" ";        }        cout << endl;       return 0;    }   

0 0
原创粉丝点击