Answer to Question #283968 in C++ for rjc

Question #283968

Create a class named Laboratory containing • Two data fields i.e. name (a string) and location (string)

• A no-argument constructor to initialize all 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 Lab 9 - Function Overloading and Function Overriding Capital University of Science and Technology, Islamabad Department of Computer Science (2020) Page 106 Derive a class named WetLab from class Laboratory that includes

• data members no_of_microscopes and Scientist_name,

• respective mutator and accessor functions • overriding function named 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 the Laboratory class, derive a class named DryLab that contain

• a data field named no_of_computers and Capacity • Setters and getters



1
Expert's answer
2021-12-31T15:43:33-0500


#include<iostream>
#include<string>


using namespace std;


class Laboratory{
private:
	string name, location; 
public:
	//A no-argument constructor to initialize all data fields with default values “NoName” and “NULL”
	Laboratory() { 
		this->name = "NoName"; 
		this->location = "NULL"; 
	} 
	//A member function named input()
	void input() { 
		cout << "Enter Lab Name: "; 
		getline(cin,name); 
		cout << "Enter Location: "; 
		getline(cin,location);
	}
	//A member function named show() to display the details associated with an instance of this class 
	void show() { 
		cout<<"Lab Name: "<<name<<"\n";
		cout<<"Lab location: "<<location<<"\n";
	}
};


class WetLab:public Laboratory{
private:
	//data members no_of_microscopes and Scientist_name,
	int no_of_microscopes;
	string scientist_name;
public:
	// respective mutator and accessor functions 
	void setNo_of_microscopes(int no_of_microscopes){
		this->no_of_microscopes=no_of_microscopes;
	}


	int getNo_of_microscopes(){
		return this->no_of_microscopes;
	}


	void setscientist_name(string scientist_name){
		this->scientist_name=scientist_name;
	}


	string getscientist_name(){
		return this->scientist_name;
	}


	
	//overriding function named input() to take input from user in all data members
	void input() { 
		Laboratory::input();
		cout << "Enter WetLab no of microscopes: "; 
		cin>>no_of_microscopes; 
		cout << "Enter WetLab scientist name: "; 
		getline(cin,scientist_name);
	}
	//overriding function named show() to display the details associated with an instance of class WetLab
	void show() { 
		Laboratory::show();
		cout<<"WetLab no of microscopes: "<<no_of_microscopes<<"\n";
		cout<<"WetLab scientist name: "<<scientist_name<<"\n";
	}
};


class DryLab:public Laboratory{
private:
	//a data field named no_of_computers and Capacity 
	int no_of_computers;
	int capacity;
public:


	//Setters and getters
	void setNo_of_computers(int no_of_computers){
		this->no_of_computers=no_of_computers;
	}


	int getNo_of_computers(){
		return this->no_of_computers;
	}
	void setCapacity(int capacity){
		this->capacity=capacity;
	}


	int getCapacity(){
		return this->capacity;
	}


};




int main(){










	system("pause");


	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