Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Based on: #include<iostream> #include<string> using namespace std; class Asset {

ID: 3818434 • Letter: B

Question

Based on:

#include<iostream>
#include<string>

using namespace std;

class Asset
{
public:
   Asset(string manN, string pda, float co);
   void getAsset();

   //Data Members
protected:
   string Manufacture, purchaseDate;

private:
   float cost;
};

//Instantiation
Asset::Asset(string manN, string pda, float co)
   :Manufacture(manN), purchaseDate(pda), cost(co)
{}

//Asset printed details
void Asset::getAsset()
{
   cout << "Asset manufacturer name:" << Manufacture << endl;
   cout << "Asset purchage date:" << purchaseDate << endl;
   cout << "Asset cost:" << cost << endl;
}

//Hardware class inheriting from Asset
class Hardware : public Asset
{
public:
   Hardware(string mn, string pd, float cos, string mod);
   void getHardware();

   //Data Members
private:
   string model;
};

Hardware::Hardware(string mn, string pd, float cos, string mod)
   :Asset(mn, pd, cos), model(mod)
{}

//Member function of hardware
void Hardware::getHardware()
{
   cout << "detalis of hardware" << endl;
   getAsset();//this is from baseclass Asset, we got it via inheritance
   cout << "Hardware model name:" << model << endl;
}

//Software class inheriting from Hardware
class Software : public Hardware
{
public:
   Software(string mn, string pd, float cos, string mo, string ti);
   void getSoftware();

   //Data Members
protected:
   string title;
};

Software::Software(string mn, string pd, float cos, string mo, string ti)
   :Hardware(mn, pd, cos, mo), title(ti)
{}

//Member function of Software
void Software::getSoftware() {
   cout << "Details of Software" << endl;
   getAsset();//this is from baseclass Asset, we got it via inheritance
   cout << "software title:" << title << endl;
}


int main()
{
   //Data declaration
   string manufacture, date, model, title;
   float cost;

   //Input
   cout << "Enter details of hardware" << endl;
   cout << "Enter manufacturer name , purchased date ,cost and model: " << endl;
   cin >> manufacture >> date >> cost >> model;

   cout << "Now we are goining to instanciate Laptop" << endl;
   //Implementation
   Hardware o1(manufacture, date, cost, model);
   o1.getHardware();
  
   //Input
   cout << "Enter details of software" << endl;
   cout << "Enter manufacturer name , purchased date ,cost and title: " << endl;
   cin >> manufacture >> date >> cost >> model >> title;

   cout << "Now we are goining to instanciate software" << endl;
   //Implementation
   Software o2(manufacture, date, cost, model, title);
   o2.getSoftware();
}

Add the following for the Asset hierarchy

Cubicle
Data members
- area (float to represent sq. feet)
- length (float)
- width (float)
Chair
Data members
- office number (int)

Laptop
Data members
- O/S (string)
- memory (int)
- screen size (float)

Server
Data members
- O/S (string)
- memory (int)


1. Fix the hierarchy to comply with the DRY principle (look for repeated
data).
2. Instantiate and initialize an object of type Cubicle and Laptop.
3. Display ALL the appropriate information for the object using getters.

Explanation / Answer

#include<iostream>

#include<string>

using namespace std;

class Asset

{

public:

    Asset(string manN, string pda, float co);

    void getAsset();

    //Data Members

protected:

    string manufactureNo, purchaseDate;

private:

   float cost;

};

/* Modified Asset Constructor. Remove calling of Manufacture Constructor

Asset is the Primary Base Class as per Class Declaration */

//Asset Constructor

Asset::Asset(string manN, string pda, float price)

{

Strcpy(manufactureNo, manN);

Strcpy(purchaseDate, pda);

cost = price;

}

//Asset printed details

void Asset::getAsset()

{

    cout << " manufacturer name:" << manufactureNo << endl;

    cout << " purchage date:" << purchaseDate << endl;

    cout << " cost:" << cost << endl;

}

/* Instead of declaring Hardware and the Software inheriting from Hardware

Which is not correct in Real-life, we declare a ComputerSystem class

It derives from Asset class */

class ComputerSystem: public Asset

{

public:

    ComputerSystem (string mn, string pd, float cos, string mod, string op_system, int mem);

    void getComputerSystem();

    //Data Members

private:

    string model, os;

    int memory;

};

ComputerSystem:: ComputerSystem (string mn, string pd, float cos, string mod, string op_system, int mem) : Asset(mn, pd, cos), model(mod), os(op_system), memory(mem)

{}

//Member function of Computer System

void ComputerSystem::getComputerSystem()

{

    getAsset();//this is from baseclass Asset, we got it via inheritance

    cout << " model name:" << model << endl;

    cout << " operating system:" << os << endl;

    cout << " memory:" << mem << endl;

}

// Cubicle class

class Cubicle: public Asset

{

public:

    Cubicle (string mn, string pd, float cos, float ar, float len, float wid);

    void getCubicleDtls();

    //Data Members

private:

    float area, length, width;

};

Cubicle:: Cubicle (string mn, string pd, float cos, float ar, float len, float wid) : Asset(mn, pd, cos), area(ar), length(len), width(wid)

{}

//Member function of Cubicle

void Cubicle:: getCubicleDtls ()

{

    getAsset();//this is from baseclass Asset, we got it via inheritance

    cout << length:" << length << endl;

    cout << " width:" << width << endl;

    cout << " area:" << (length * width) << endl;

}

// Chair class

class Chair: public Asset

{

public:

    Chair (string mn, string pd, float cos, float off_no);

    void getChair();

    //Data Members

private:

    int office_num;

};

Chair:: Chair (string mn, string pd, float cos, float off_no) : Asset(mn, pd, cos), office_num(off_no)

{}

//Member function of Chair

void Chair:: getChair()

{

    getAsset();//this is from baseclass Asset, we got it via inheritance

    cout << office number:" << office_num << endl;

}

//Laptop class inherits from ComputerSystem

class Laptop: public ComputerSystem

{

public:

    Laptop (string mn, string pd, float cos, string mod, string op_system, int mem, float scr_size);

    void getLaptop();

    //Data Members

private:

    float screen_size;

};

Laptop:: Laptop (string mn, string pd, float cos, string mod, string op_system, int mem, float scr_size) : ComputerSystem (mn, pd, cos, mod, op_system, mem), screen_size(scr_size)

{}

//Member function of Laptop

void Hardware::getLaptop ()

{

    getComputerSystem ();//this is from baseclass ComputerSystem, we got it via inheritance

    cout << " screen size:" << screen_size << endl;

}

//Server class inherits from ComputerSystem

class Server: public ComputerSystem

{

public:

    Server (string mn, string pd, float cos, string mod, string op_system, int mem);

    void getServer();

    //Data Members

};

Server:: Server (string mn, string pd, float cos, string mod, string op_system, int mem) : ComputerSystem (mn, pd, cos, mod, op_system, mem)

{}

//Member function of Server

void Server::getServer ()

{

    getComputerSystem ();//this is from baseclass ComputerSystem, we got it via inheritance

}

int main()

{

    //Data declaration

    //Input laptop dtls

// Instantiate Laptop

// Input Cubicle Dtls

// Instantiate Cubicle

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote