Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

---------------------------------------------------------------------------------------------------------------------------------------------------- For the given header( Here is a link to the Assembly.h file.) //Assembly.h #ifndef ASSEMBLY_H #define ASSEMBLY_H #include #include Part.h using namespace std; class

image text in transcribed

image text in transcribed

image text in transcribed

----------------------------------------------------------------------------------------------------------------------------------------------------

For the given header( Here is a link to the Assembly.h file.)

//Assembly.h
#ifndef ASSEMBLY_H
#define ASSEMBLY_H
#include
#include "Part.h"
using namespace std;
class Assembly : public Part{
private:
vector m_parts;
public:
//Assembly constructor
Assembly(string id, string dwg, int qty);
//Add a part to this assembly
void addPart(Part p);
//Print out the BOM
string toString();
};
#endif

image text in transcribed

Here are the constructor variables stored in Assembly class:

Part.h

#ifndef PART_H #define PART_H #include using namespace std; class Part { //declare private variables private: string identifier,drawing; int quantity; public: //declare parameterized constructor Part(string id,string dwg,int qty); //mutator and accessor methods declaration string getId(); string getDrawing(); int getQuantity(); void setId(string id); void setDrawing(string drawing); void setQuantity(int qty); //print string representation of the part string toString(); }; #endif

Part.cpp

#include //to use stringstream for building the string #include "Part.h" using namespace std; Part::Part(string identifier,string drawing,int quantity) { this->identifier=identifier; this->drawing=drawing; this->quantity=quantity; } void Part::setId(string identifier) { this->identifier=identifier; } void Part::setDrawing(string drawing) { this->drawing=drawing; } void Part::setQuantity(int quantity) { this->quantity=quantity; } string Part::getId() { return this->identifier; } string Part::getDrawing() { return this->drawing; } int Part::getQuantity() { return this->quantity; } string Part::toString() { stringstream ss; //sets the contents of the stream ss

Testclass.cpp

#include #include "Part.h" using namespace std; int main(int argc,char **argv) { //constructs new part Part p("12-00001","12-00001.dwg",1); //print part out cout Programming Assignment DUE Date: See your Blackboard Objectives Use Inheritance- extend a base class Use the vector class from the standard template library Using standard in and standard out Implement basic user data validation Extend existing code to create a new program Tasks For this homework you are going to extend the Part class and create a simple Bill of Material (BOM) that represents an assembly. We will take the part class and extend it using Inheritance to create an assembly class. Using the is-a relationship test, we know that an assembly IS-A part however a part is not necessarily an assembly. In other words our base class will be a part, and our child class will be an assembly. Your job is to implement the class defined in Assembly.lh You must use the public methods defined on Part.h to get and set the private variables defined in Part. You will be adding two new methods in Assembly.cpp and overriding the toString method. In the Assembly method you should use the stringstream class to build up a string object that contains the Assembly Id, Drawing, and Quantity, as well as, the parts of the Assembly, which is returned to the caller. Call the toString function in each Part object in the parts vector to get the string representation of each Part. Your main function should read from standard in an Assembly. Here is a link to the Assembly.h file You will need to write your own 'main' program, which you can 'reverse-engineer' from the sample output below Using stringstreanm To get full credit for this assignment, you need to use the stringstream object to build the string returned in the toString accessor. You can think of a string stream as a bunch of characters floating down a stream sequentially where they all stack up at a dam. They aren't a string yet, they're still in the stream. You then need to convert the stringstream into a string, which can then be returned from the toString accessor to the caller. To use the stringstream object you need to include 'sstream' into your program. For background on how to use the stringstream object you can start here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Outlook 2023

Authors: James Holler

1st Edition

B0BP9P1VWJ, 979-8367217322

More Books

Students also viewed these Databases questions