반응형

C++ 기초플러스 4판 8장 : 함수 프로그래밍 연습 2번

#include <iostream>
using namespace std;

struct CandyBar{
 char name[20];
 double weight;
 int kalory;
};

void InputStruct(CandyBar &candy,
     char *name = "Millennium Munch",
     double weight = 2.85, int kalory = 350);

int main()
{
 CandyBar candy;
 InputStruct(candy, "abcde", 2.21, 300);
 cout << "not default : " << candy.name << ", " << candy.weight << ", " << candy.kalory << "\n";
 InputStruct(candy);
 cout << "use default : " << candy.name << ", " << candy.weight << ", " << candy.kalory << "\n";

 return 0;
}

void InputStruct(CandyBar &candy, char *name, double weight, int kalory){
 strcpy(candy.name, name);
 candy.weight = weight;
 candy.kalory = kalory;
}

반응형
Posted by Rainfly
l