我是靠谱客的博主 欣喜台灯,最近开发中收集的这篇文章主要介绍C++primer plus第七章编程练习,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

#include<iostream>
using std::cout;
using std::cin;
using std::endl;
const unsigned SIZE{ 10 };
const double func1(const double a, const double b)
{
return 2.0 * a * b /(a + b);
}
const int func2a( double* score,int len=10)
{
cout << "enter 10 score ,EOF to lastn";
int i = 0;
for ( i = 0; i <len; ++i)
{
cin >> score[i];
if (!cin)
break;
}
len = i;
return len;
}
const double func2b(double* score,const int& len)
{
double sum{ 0 };
for (int i = 0; i < len; ++i)
sum += score[i];
return sum;
}
void func2c(double* score, const int& len,double& sum)
{
for (int i = 0; i < len; ++i)
cout << i+1<<"次
" << score[i] << "
";
cout << "总分:
" << sum;
}
int func5(int a)
{
if (a == 0 || a == 1)
return 1;
return a * func5(a - 1);
}
double add(double x, double y)
{
return x * y;
}
double ADD(double x, double y)
{
return x * y*x*y;
}
double calculate(double a, double b, double(*p)(double, double))
{
return (*p)(a, b);
}
int main(int argc, char* arhv[])
{
//1
double amount1;
double amount2;
cout << "enter two amounts: ";
cin >> amount1 >> amount2;
while (amount1 == 0 || amount2 == 0)
{
cout << "enter two amounts: ";
cin >> amount1 >> amount2;
}
cout << "调和:
" << func1(amount1, amount2) << endl;
//2
double score[SIZE]{ 0 };
int len{0};
double sum{0};
len= func2a(score, SIZE);
sum=func2b(score, len);
func2c(score, len, sum);
//5
while (1)
{
int amount;
cin >> amount;
cout << "阶层" << amount << "!: " << func5(amount) << endl;
}
//10
double q = calculate(2.5, 10.4, add);
cout << q << endl;
double(*(P[2]))(double, double) { add, ADD };
for (int i = 0; i < 2; ++i)
cout << ( * (P[i]))(2.5, 10.4) << "
";
system("pause");
return 0;
}

 

最后

以上就是欣喜台灯为你收集整理的C++primer plus第七章编程练习的全部内容,希望文章能够帮你解决C++primer plus第七章编程练习所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(41)

评论列表共有 0 条评论

立即
投稿
返回
顶部