Question

In: Computer Science

Task use c++ and Create Base class task with virtual method Create a pair of derivative...

Task use c++ and Create Base class task with virtual method Create a pair of derivative classes of architecture, scientist, economist - Define a salary in each of these classes and create a method that prints the salary for each job Create a working object Use dynamic_cast Use typeid Create an object for each job that it will include the number of employees of that type and the method of printing these numbers

Solutions

Expert Solution

I have implemented the Employee,Architect,Economist and Scientist classes and main function per the given description.

Please find the following Code Screenshot, Output, and Code.

ANY CLARIFICATIONS REQUIRED LEAVE A COMMENT

1.CODE SCREENSHOT :

2.OUTPUT :

3.CODE :

#include<iostream>
using namespace std;
/*Create a base class EMployee with pure virtual method*/
 class Employee {
         public :
         virtual void printSalary()=0;
};
/*Architect deived class from Employee that implement the virtual method.*/
class Architect : public  Employee{
        private:
        double salary;
        public :
         Architect(double d){
                 salary=d;
         }
         void printSalary(){
                cout<<"Architect Salary "<<salary<<endl;
         }
};
/*Scientist deived class from Employee that implement the virtual method.*/

class Scientist : public  Employee{
        private:
        double salary;
        public :
          Scientist(double d){
                 salary=d;
         }
         void printSalary(){
                cout<<"Scientist Salary "<<salary<<endl;
         }
};
/*Economist deived class from Employee that implement the virtual method.*/

class Economist : public Employee{
        private:
        double salary;
        public :
        Economist (double d){
                
                 salary=d;
         }
         void printSalary(){
                cout<<"Economist Salary "<<salary<<endl;
         }
};
int main(){
        /*Create working objects of each class and use dynamic_cast*/ 
        Employee *t=  new Economist(20000);
        Economist *e=dynamic_cast<Economist*>(t);
        e->printSalary();
        t=  new Scientist(10000);
        Scientist *s=dynamic_cast<Scientist*>(t);
        s->printSalary();
        t=  new Architect(30000);
        Architect *a=dynamic_cast<Architect*>(t);
        a->printSalary();
}

Related Solutions

In C++ write a program with a base class thet has a pure virtual function SALARY,...
In C++ write a program with a base class thet has a pure virtual function SALARY, and two derived classes. In the first derived class salary is increased by 20%, in the second derived class salary is increased by 30%
Write in C++ Abstract/Virtual Rock Paper Scissors Create an abstract Player class that consists of private...
Write in C++ Abstract/Virtual Rock Paper Scissors Create an abstract Player class that consists of private data for name, selection, wins, and losses. It must have a non-default constructor that requires name. It may not contain a default constructor. Create overloaded functions for the ++ and - - operator. The overloaded ++operator will add to the number of wins, while the - - operator will add to the losses. You will create two different child classes of player, Human and...
In C++ Create an abstract class called Shape Shape should have the following pure virtual functions:...
In C++ Create an abstract class called Shape Shape should have the following pure virtual functions: getArea() setArea() printArea() Create classes to inherit from the base class Circle Square Rectangle Both implement the functions derived from the abstract base class AND must have private variables and functions unique to them like double Radius double length calculateArea() Use the spreadsheet info.txt read in information about the circle, rectangle, or square text file: circle   3.5   square   3   rectangle   38   36 circle   23  ...
True or False: EXPLAIN the false ________ 1. An A-T base pair and a G-C base...
True or False: EXPLAIN the false ________ 1. An A-T base pair and a G-C base pair have about the same physical dimensions. ________ 2. mRNA is double-stranded. ________ 3. rRNA and tRNA may have modified nucleotide residues. ________ 4. Eukaryote DNA is normally complexed with histones. ________ 5. Circular DNA is supercoiled. ________ 6. Two strands of DNA run parallel from their 5’ to 3’ ends. ________ 7. An G-C base pair contains two hydrogen bonds. ________ 8. Positively...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet...
Code in C++ Objectives Use STL vector to create a wrapper class. Create Class: Planet Planet will be a simple class consisting of three fields: name: string representing the name of a planet, such as “Mars” madeOf: string representing the main element of the planet alienPopulation: int representing if the number of aliens living on the planet Your Planet class should have the following methods: Planet(name, madeOf, alienPopulation) // Constructor getName(): string // Returns a planet’s name getMadeOf(): String //...
C++: FramedI is an interface and appears as: class FramedI { public: virtual string getText()=0; virtual...
C++: FramedI is an interface and appears as: class FramedI { public: virtual string getText()=0; virtual char getFrameChar() =0; }; You must implement the interface and call the class FramedText. It must implement the FramedI interface. Any attributes used in the FramedText class MUST be private. Create a function called void showFramedText(ostream&, FramedI&); If the text to display is "Here's my text here" and the framing character is '*', the function must output *********************** * Here's my text here *...
Needs to be written in C# Console App! Create a base class BankAccount. Decide what characteristics...
Needs to be written in C# Console App! Create a base class BankAccount. Decide what characteristics are common for checking and saving accounts and include these characteristics in the base class. Define derived classes for checking and savings. In your design , do not allow the banking base account to be instantiated --only the checking and saving classes. Use a Program class to test your design.
Create a method on the Iterator class called forEach, which appropriate behavior. This method should use...
Create a method on the Iterator class called forEach, which appropriate behavior. This method should use next(), and should not use this._array.forEach! Take note of what should happen if you call forEach twice on the same Iterator instance. The estimated output is commented below In javascript please class Iterator { constructor(arr){ this[Symbol.iterator] = () => this this._array = arr this.index = 0 } next(){ const done = this.index >= this._array.length const value = this._array[this.index++] return {done, value} } //YOUR WORK...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of...
Create a PoemDriver.java class with a main method. In the main method, create an ArrayList of Poem objects, read in the information from PoemInfo.txt and create Poem objects to populate the ArrayList. After all data from the file is read in and the Poem objects added to the ArrayList- print the contents of the ArrayList. Paste your PoemDriver.java text (CtrlC to copy, CtrlV to paste) into the open space before. You should not change Poem.java or PoemInfo.txt. Watch your time...
(MUST BE DONE IN C (NOT C++)) In this task, you will create a structure with...
(MUST BE DONE IN C (NOT C++)) In this task, you will create a structure with arrays. You will have to create your own structure. However, make sure to meet these guidelines: - Give the structure whichever name you want. - It must have at least 3 members. - Two of the members must be arrays. - Your members should be of at least two different data-types. In other words, your members cannot be integers only (or floats, or doubles…)....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT