第三周作业
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;
}
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;
}
相关文章推荐
- linux压缩包解压缩
- 静态链表
- SQL一列三行变成一列一行
- java JDBC(二):Statement、ResultSet、PreparedStatement
- Vim常用配置(~/.vimrc)(转载)
- 网络垃圾的来源和处理措施详解
- POJ 2195 二分图最小权匹配KM算法
- XCODE插件 之 Code Pilot 无鼠标化
- matlab基础知识 randperm()的用法
- 20140506朗沃(1)
- linux下安装loadrunner步骤以及出错解决方法(外加linux下ip地址欺骗)
- C++ 指针和多维数组
- 使用srvany.exe将程序安装成windows服务的详细教程
- Exchange2010RPC配置静态RPC端口客户端访问、通讯簿服务和公用文件夹连接
- OpenStack看似给我们提供了非常多的选项
- 关于AWS使用细节:
- C++输入cin详解
- Windows 2003 远程桌面
- 恒大客场5-1血洗樱花.nice
- Javascript代码优化技巧