Answer to Question #207041 in C++ for bryan

Question #207041

Create class named Laboratory

Two data fields name (a string) and location (string).

A no-argument constructor to initialize data fields with default values “NoName” and “NULL” .

A member function named input()

A member function named show() to display the details associated with an instance of this class.

Derive class WetLab from class Laboratory including

data members no_of_microscopes and Scientist_name.

respective mutator and accessor functions.

overriding function input() to take input from user in all data members.

overriding function named show() to display the details associated with an instance of class WetLab From Laboratory class,

derive a class named DryLab that contains

a data field no_of_computers and Capacity.

an overriding function named input().

overriding function show() to display the details associated with instance of this class.

Implement these classes and in main() create instances of each class and test functionality of overridden member functions with instances.


1
Expert's answer
2021-06-15T01:29:17-0400
#include <iostream>
#include <string>
using namespace std;
class Laboratory{
    protected:
    string name, location;
    public:
    Laboratory(): name("NoName"), location("NULL"){}
    virtual void input(){
        cout<<"Input name: "; cin>>name;
        cout<<"Input location: "; cin>>location;
    }
    virtual void show(){
        cout<<"Name: "<<name<<endl;
        cout<<"Location: "<<location<<endl;
    }
};
class WetLab: public Laboratory{
    int no_of_microscopes;
    string Scientist_name;
    public:
    WetLab(): Laboratory(){}
    void input(){
        cout<<"\nWetLab\n";
        Laboratory::input();
        cout<<"Input number of microscopes: "; cin>>no_of_microscopes;
        cout<<"Input Scientist name: "; cin>>Scientist_name;
    }
    void show(){
        cout<<"\nWetLab\n";
        Laboratory::show();
        cout<<"Number of Microscopes: "<<no_of_microscopes<<endl;
        cout<<"Scientist Name: "<<Scientist_name<<endl;
    }
};
class DryLab: public Laboratory{
    int no_of_computers, capacity;
    public:
    DryLab(): Laboratory(){}
    void input(){
        cout<<"\nDryLab\n";
        Laboratory::input();
        cout<<"Input number of computers: "; cin>>no_of_computers;
        cout<<"Input Capacity: "; cin>>capacity;
    }
    void show(){
        cout<<"\nDryLab\n";
        Laboratory::show();
        cout<<"Number of computers: "<<no_of_computers<<endl;
        cout<<"Capacity: "<<capacity<<endl;
    }
};
int main(){
    Laboratory laboratory;
    laboratory.show();


    DryLab drylab;
    drylab.input();
    drylab.show();


    WetLab wetlab;
    wetlab.input();
    wetlab.show();


    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog