Starting from:
$35

$29

Lab03 Solution

1. The CandyBar structure contains three members.The first member holds the brand name of a candy bar.The second member holds the weight (which may have a fractional part) of the candy bar, and the third member holds the number of calories (an integervalue) in the candy bar. Write a program that declares such a structure and creates a CandyBar variable called snack ,initializing its members to "Mocha Munch" , 2.3 ,and 350 ,respectively.The initialization should be part of the declaration for snack .Finally,the program should display the contents of the snack variable.

Sample output:
``` log
Brand: Mocha Munch
Weight: 2.3
Calorie: 350
```

1. The CandyBar structure contains three members,as described in Exercise 1. write a program that uses a structure variable of that type.The program should ask the user to enter each of the preceding items of information,and then the program should display that information.Use cin (or its methods) and cout .

Sample output:
``` log
Enter brand name of a Candy bar: Mocha Munch
Enter weight of the candy bar: 2.3
Enter calories(an integer value) in the Candy bar: 350
Brand: Mocha Munch
Weight: 2.3
Calorie: 350
```

3. The CandyBar structure contains three members,as described in Exercise 1.Write a program that creates an array of three CandyBar structures,initializes them to values of your choice,and then displays the contents of each structure.

Sample output:
``` log
Brand: Mona coke
Weight: 3
Calorie: 31
Brand: Mona coke
Weight: 11.2
Calorie: 45
Brand: Mona coke
Weight: 91.1
Calorie: 92
```

More products