Question

RFIDs and lot Internet of things lloT) is one of the hottest technologies at the moment. The concept of loT is to provide obj
Write a method to get the containers Add a virtual function called getContentList, or will returnering This function will be in c++ please
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Screenshot

Ship ContainerMain.cpp - X Ship Container.cpp Ship Container.h Ship ContainerMain 5 //Test main 6 #include ShipContainer.h

Program

ShipContainer.h

#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;
//Create base class
class ShipContainer {
//Member variable
private:
   int ID;
//Member functions
public:
   void setID(int id);
   int getID();
   virtual string getContenetList();
};
//Derived class
class ManualContenetList :public ShipContainer {
//Member variable
private:
   string contentList;
//Member functions
public:
   void setContentList(string content);
   string getContenetList();
};
//Create next derived class
class ShippingContainerRFID:public ShipContainer{
//Member variables
private:
   vector<string> contentList;
   vector<int>quantity;
//Member functions
public:
   void add(string content, int quant);
   string getContenetList();
};

ShipContainer.cpp

//Implementation of classes
#include "ShipContainer.h"
void ShipContainer::setID(int id) {
   ID = id;
}
int ShipContainer::getID() {
   return ID;
}
string ShipContainer::getContenetList() {
   return "";
}
void ManualContenetList::setContentList(string content) {
   if (contentList == "") {
       contentList += content;
   }
   else {
       contentList += ", "+content;
   }
}
string ManualContenetList::getContenetList() {
   return "Container "+to_string(getID()) + " contains " + contentList;
}
void ShippingContainerRFID::add(string content, int quant) {
   if (!(std::find(contentList.begin(), contentList.end(), content) != contentList.end())) {
       contentList.push_back(content);
       quantity.push_back(quant);
   }
}
string ShippingContainerRFID::getContenetList() {
   string str = "Container " + to_string(getID());
   for (int i = 0; i < contentList.size()-1; i++) {
       str = " contains " + to_string(quantity[i] )+ " of "+contentList[i]+", ";
   }
   str = " contains " + to_string(quantity[contentList.size() - 1]) + " of " + contentList[contentList.size() - 1];
   return str;
}

Main.cpp

//Test main
#include "ShipContainer.h"

int main()
{
    //ShipContainer pointer object array
   ShipContainer* shipContainer[7];
   //shipContainer = new ShipContainer[7];
   //3 Manual objects
   ManualContenetList mContainer[3];
   //3 RFID object array
   ShippingContainerRFID rfid[3];
   //Add 3 contents in mContainer
   mContainer[0].setContentList("100 boxes of lysol wipes");
   mContainer[1].setContentList("50 boxes of 70% alcohol hand sanitizer");
   mContainer[2].setContentList("100 boxes of toilet papers");
   shipContainer[0] =&mContainer[0];
   shipContainer[0]->setID(1);
   shipContainer[1] = &mContainer[1];
   shipContainer[1]->setID(2);
   shipContainer[2] = &mContainer[2];
   shipContainer[2]->setID(3);
   //Display details
   for (int i = 0; i < 3; i++) {
       cout << shipContainer[i]->getContenetList() << endl;
   }
   return 0;
}

Output

Container 1 contains 100 boxes of lysol wipes
Container 2 contains 50 boxes of 70% alcohol hand sanitizer
Container 3 contains 100 boxes of toilet papers

Note

Please add clear picture of the question.I assume you are expecting this way.From RFID class onwards picture is not clear.

Add a comment
Know the answer?
Add Answer to:
in c++ please RFIDs and lot Internet of things lloT) is one of the hottest technologies...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT