C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
Expert Solution & Answer
Book Icon
Chapter 11, Problem 9SA

Explanation of Solution

The errors are in the following lines:

  1. class hourlyEmployee: public class employee - has the word “class” mentioned before the base class.

  2. public:: - should be public:

  3. void setHoursWorked(double hrsWk) const; - set functions should not be constant functions as they modify data members.

  4. void setPay() const; - set functions should not be constant functions as they modify data members.

  5. private; - should be private:

Hence the correct program is:

class hourlyEmployee: public employee

{

    public:

        void setData(string n = "", string d = "", int a = 0,

        double p = 0, double hrsWk = 0,

        double payRate = 0.0);

        // Data members are set according to the parameters.

        // Values assigned to numeric data is nonnegative.

        void setHoursWorked(double hrsWk);

        // Function to set hours worked.

        // if hrsWk>= 0, hoursWorked = hrsWk;

        // Otherwise hoursWorked = 0;

        double getHoursWorked() const;

        // returns the value of hoursWorked...

Blurred answer
Students have asked these similar questions
5 points Save Answer QUESTION 4 What is printed? public class Puppy { private int puppyAge; private String puppyName; Puppy(String name){ puppyName = name ;} public void setAge( int age ) { puppyAge = ++age; } public int getAge(){ return puppyAge; } %3D public class TestPuppy{ public static void main(String []args) { Puppy myPuppy = new Puppy( "tommy" ); myPuppy.setAge( 2 ); System.out.print("Puppy's age is :" + myPuppy.getAge()); System.out.print(" %3D Name chosen is :" + myPuppy.puppyNname ); D Puppy's age is : 2 Name chosen is : tommy Puppy's age is : 3 Name chosen is : tommy O Syntax Error O Run Time Error Save All Answers Close Window Save and Submit - Save and Submit to save and submit. Click Save All Answers to save all answers. MacBook Pro 888 ES F6 F3 96 7
class Lease{     private String name;     private int aptNumber;     private double rent;     private int term;     private static final int FEE = 10;     public Lease(){        name = "XXX";        aptNumber = 0;        rent = 1000;        term = 12;     }     public void setName(String tenant)  {        name = tenant;     }     public void setAptNumber(int apt){        aptNumber = apt;     }     public void setRent(double monthRent) {        rent = monthRent;     }     public void setTerm(int t){        term = t;     }     public String getName(){        return name;     }     public int getAptNumber(){        return aptNumber;     }     public double getRent(){        return rent;     }     public int getTerm(){        return term;     }     public void addPetFee(){        rent = rent + FEE;     } }    Create a class named TestLease as instructed below:  Instantiate four Lease objects in the main()method.  Change the aptNumber value for the first object to 20  Change the rent value…
class Player {   protected:    string name;    double weight;    double height;   public:    Player(string n, double w, double h)      { name = n; weight = w; height = h; }    string getName() const      { return name; }    virtual void printStats() const = 0; };   class BasketballPlayer : public Player {   private:    int fieldgoals;    int attempts;   public:    BasketballPlayer(string n, double w,     double h, int fg, int a) : Player(n, w, h)      { fieldgoals = fg; attempts = a; }    void printStats() const      { cout << name << endl;         cout << "Weight: " << weight;         cout << " Height: " << height << endl;        cout << "FG: " << fieldgoals;        cout << " attempts: " << attempts;        cout << " Pct: " << (double) fieldgoals / attempts << endl; } }; a. What does = 0 after function printStats() do? b. Would the following line in main() compile: Player p; -- why or why not? c. Could…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education