Question
Below is the Can class #include #include using namespace std; // Can class class Can { // private variables to store item name and weight
Below is the Can class
#include
// Can class class Can { // private variables to store item name and weight private: string item; int weight; public: // Constructor Can(string i, int w) { item = i; weight = w; } // method to get name of the item string getItem() { return item; } // method to get weight of the item int getWeight() { return weight; } };
// main int main() { // Creating 4 objects of class Can Can can1("Pepsi", 12); Can can2("pears", 16); Can can3("mustard", 32); Can can4("apple juice", 40);
// variable to store the total weight of everything int totalWeight = 0;
// printing the 4 objects and sum their weights cout
// print the weight of everything cout
return 0; }
1. Separate the Can class into a header file and an implementation file 2. The main function will be in a separate file as well - so you will have 3 files: main.cpp, Can.h, Can.cpp 3. In the main file, you will create an array of Cans with the following items: a. 12 ounce can of Coke b. 16 ounce can of Mango Monster Energy Drink c. 8 ounce can of Red Bull d. 16 ounce can of Bang! e. 16 ounce can of Venom Energy f. 12 ounce can of Jolt Cola 4. Write a function in main program that passes the array of Cans, prints the contents and weight of each can and then prints the total weight of all cansStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started