本文主要是介绍【C++ Primer Plus习题】7.8,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题:
解答:
#include <iostream>
using namespace std;#define SEASONS 4typedef struct _Spend
{double money[SEASONS];
}Spend;const char* Snames[SEASONS] = { "Spring","Summer","Fall","Winter" };void fill(double* expenses)
{for (int i = 0; i < SEASONS; i++){cout << "请输入" << Snames[i] << "季的费用:";cin >> *(expenses + i);}
}void show(double* expenses)
{double total = 0.0;for (int i = 0; i < SEASONS; i++){cout << Snames[i] << "季节的费用为:" << expenses[i] << endl;total += expenses[i];}cout << "总的费用为:" << total << endl;
}int main()
{double expenses[SEASONS];fill(expenses);show(expenses);Spend spend;fill(spend.money);show(spend.money);return 0;
}
运行结果:
2024年8月31日20:06:58
这篇关于【C++ Primer Plus习题】7.8的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!