8.1
#include <iostream>
using namespace std;
void p1(const string &str, const int times=0)
{
static int called = 0;
int repeat = times>0 ? called : 0;
do
{
cout << str << endl;
} while (repeat--);
called++;
return;
}
8.2
#include <iostream>
using namespace std;
struct CandyBar
{
string brand;
double weight;
int calorie;
};
void p2_construct(CandyBar& candybar, char* brand = "Millennium Munch", const double weight= 2.85, const int calorie = 350)
{
candybar.brand = brand;
candybar.weight = weight;
candybar.calorie = calorie;
}
void p2_print(const CandyBar& candybar)
{
cout << "CandyBar brand: " << candybar.brand << endl;
cout << "CandyBar weight: " << candybar.weight << endl;
cout