Exercise 1: Program UsePart is a client program that used PartsType (file Parts.
ID: 3705054 • Letter: E
Question
Exercise 1: Program UsePart is a client program that used PartsType (file Parts.h) and ExtPartsType (file ExtParts.h) The .cpp files for these classes dont even compile! there is one syntax error in file Parts.h and two syntax errors in extParts.h find these errors and correct them describe the errors. Look at your output carefully. Ypu are missing some *VALUES* correct the logic, recompile and run your program describe the error. Some of the missing output is now visable but not all of it! keep looking for the error. When you find it correct it and rerun the program. The output should now be correct desrcibe the error
// This is a specification file for class Parts.
class Parts
{
public:
long IdNumIs() const;
float PriceIs() const;
void Print() const;
void Initialize(long, float);
Parts();
Parts(long, float);
private:
long idNum;
float price;
}
// This is the specification file for ExtParts.
#include "Parts.h"
class ExtParts
{
public:
long NumInStockIs() const;
void Print() const;
void Initialize(long, long, float);
ExtParts();
ExtParts(long, long, float);
private:
long inStock;
}
Explanation / Answer
// This is a specification file for class Parts.
class Parts
{
public:
long IdNumIs() const;
float PriceIs() const;
void Print() const;
void Initialize(long, float);
Parts();
Parts(long, float);
private:
long idNum;
float price;
}
// This is the specification file for ExtParts.
#include "Parts.h"
class ExtParts :public Parts // Make ExtParts derived class of Parts
{
public:
long NumInStockIs() const;
void Initialize(long); // initialize member of this class only
void Print() const;
ExtParts();
ExtParts(long, long, float);
private:
long inStock;
}
Parts.cpp
long Parts::IdNumIs() const
{
return idNum;
}
float Parts::PriceIs() const
{
return price;
}
void Parts::Print() const
{
cout<<" Id Num : "<<idNum+" Price : "<<price;
}
void Parts::Initialize(long idNum, float price)
{
this->idNum = idNum;
this->price = price;
}
Parts::Parts()
{
idNum = 0;
price = 0.0;
}
Parts::Parts(long idNum, float price)
{
this->idNum = idNum;
this->price = price;
}
ExtParts.cpp
long ExtParts::NumInStockIs() const
{
return inStock;
}
void ExtParts::Print() const
{
cout<<" In Stock : "<<inStock;
}
void ExtParts::Initialize(long inStock)
{
this->inStock = inStock;
}
ExtParts::ExtParts()
{
this->inStock = 0;
}
ExtParts::ExtParts(long inStock, long idNum, float price):Parts(idNum,price)
{
this->inStock = inStock;
}
Do ask if any doubt. Please upvote.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.