C++ primer plus(第六版)编程练习答案 第4章 复合类型

一、程序清单

arrayone.cpp 

// arrayone.cpp -- small arrays of integers
#include 
int main()
{
	using namespace std;
	int yams[3];    // creates array with three elements
	yams[0] = 7;    // assign value to first element
	yams[1] = 8;
	yams[2] = 6;

	int yamcosts[3] = { 20, 30, 5 }; // create, initialize array
// NOTE: If your C++ compiler or translator can't initialize
// this array, use static int yamcosts[3] instead of
// int yamcosts[3]

	cout << "Total yams = ";
	cout << yams[0] + yams[1] + yams[2] << endl;
	cout << "The package with " << yams[1] << " yams costs ";
	cout << yamcosts[1] << " cents per yam.\n";
	int total = yams[0] * yamcosts[0] + yams[1] * yamcosts[1];
	total = total + yams[2] * yamcosts[2];
	cout << "The total yam expense is " << total << " cents.\n"

你可能感兴趣的:(C++,primer,plus(第六版)编程练习答案,c++,算法,蓝桥杯)