-
Notifications
You must be signed in to change notification settings - Fork 1
/
ex09.cpp
46 lines (34 loc) · 1.07 KB
/
ex09.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <iostream>
#include <string>
struct CandyBar
{
std::string name;
float weight;
int calories;
};
int main()
{
CandyBar *snack = new CandyBar[3];
snack[0].name = "Mocha Munch";
snack[0].weight = 2.3;
snack[0].calories = 350;
snack[1].name = "Super Snack";
snack[1].weight = 3.5;
snack[1].calories = 420;
snack[2].name = "Chocosnack";
snack[2].weight = 3.1;
snack[2].calories = 230;
std::cout << "name: " << snack[0].name << std::endl;
std::cout << "weight: " << snack[0].weight << std::endl;
std::cout << "calories: " << snack[0].calories << std::endl;
std::cout << std::endl;
std::cout << "name: " << snack[1].name << std::endl;
std::cout << "weight: " << snack[1].weight << std::endl;
std::cout << "calories: " << snack[1].calories << std::endl;
std::cout << std::endl;
std::cout << "name: " << snack[2].name << std::endl;
std::cout << "weight: " << snack[2].weight << std::endl;
std::cout << "calories: " << snack[2].calories << std::endl;
delete[] snack;
return 0;
}