- 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
- 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
1
1欢迎下载
1
1欢迎下载
日月年080^ ??间时试考
号学
精品文档
1.编写一个求方程 ax2 + bx + c = 0 零时的方程的根。要求从主函数输入
#include iostream.h
#include math.h
void equation_1 (int a, int b, int c) {
double x1, x2, temp; temp = b*b - 4 * a * c;
x1 = (-b + sqrt(temp) ) / (2 * a * 1.0); x2 = (-b - sqrt(temp) ) / (2 * a * 1.0); coutvv两个不相等的实根 endl;
coutvx1 = x1, x2 = x2 endl;
}
void equation_2 (int a, int b, int c)
{
double x1, x2, temp; temp = b*b - 4 * a * c;
x1 = (-b + sqrt(temp) ) / (2 * a * 1.0); x2 = x1;
coutvv两个相等的实根 endl; coutx1 = vv x1vv, x2 = vv x2vv endl;
}
void equation_3 (int a, int b, int c)
{
double temp, real1, real2, image1, image2; temp = - (b*b - 4 * a * c);
real1 = -b / (2 * a *1.0); real2 = real1;
image1 = sqrt(temp); image2 = - image1; coutvv两个虚根vv endl;
coutvvx1 = vv real1vv + vv image1vvjvv en dl; coutvvx2 = vv real2vv + vv image2vvjvv endl;
}
void main()
{
int a, b, c; double temp; coutvv输入 a,b,c 的值vv endl; cina?b?c;
《C++》编程题试卷
第三章
的根的程序,用3个函数分别求当b2-4ac大于零、等于零、和小于 a,b,c的值并输岀结果。
coutvv万程为: avvx*x+vv bvvx+vv c = 0 endl; temp = b*b - 4 * a * c;
if(temp 0)
equation」(a, b, c);
if(temp == 0)
equation_2 (a, b, c);
if(temp 0)
equation_3 (a, b, c);
2.定义函数up(ch),如字符变量ch是小写字母就转换成大写字母并通过 up返回,否则字符ch不改变。
要求在短小而完全的程序中显示这个程序是怎样被调用的。
#include iostream using namespace std; char up (char c)
{
if(c = 97 c = 122) return (c - 32);
else
return c;
}
void main()
{
int i;
char c[15] = {A,v,e,t,E,T,%,,4,Y,e,i,@,9,A}; for(i = 0 ; i v 15 ; i++)
coutvv up(c[i])vv,;
coutvv endl;
}
3.编写主程序条用带实数 r和整数n两个参数的函数并输岀 r的n次幂
#include v iostream.h
#include v math.h
double power(double a, int b)
{
int i;
double result = 1.0;
for(i=0;iv b;i++)
result = result * a;
return result;
}
void main()
{
double r;
int n;
coutvvr =;
cin?r;
cout?n = cin?n;
cout? r? 的vvnvv” 次幕是:? power(r,n)vv endl;}
C组成的三角形。其方式为第 编写有字符型参数 C和整形参数N的函数,让他们显示出由字符 个字符C,第2行有2个字符C ,
C组成的三角形。其方式为第
#include iostream
using namespace std;
void print_triangle(char c, int n)
{
int i, j;
for(i=0; i n; i++)
{
for(j=0; j=i; j++)
{
cout? c;
}
cout? endl;
}
}
文档评论(0)