Question

for c++ answer the following and create the following (1)Declare a class to hold Employee Data....

for c++ answer the following and create the following

(1)Declare a class to hold Employee Data. It must have at least 2 attributes and 1 method in addition to getters/setters for 1 of the 2 attributes. Also, include at least 2 constructors and a destructor. Put the appropriate members in public and private sections. You don't need to write the code to implement the class except for getters and setters which should include the appropriate inline code.

(2)

What is/are the error(s) of the following class declaration?

     #include <iostream>

     using namespace std;

     class TestClass

     {

     private:

         int val;

     public:

         TestClass() { val = 10; }

         TestClass(int x=10) { val = x; }

     };

0 0
Add a comment Improve this question Transcribed image text
Answer #1
1)
#include <string>
#include <iostream>
using namespace std;

class Employee {
private:
    string name;
    int age;
public:
    Employee() {}

    Employee(string name, int age) : name(name), age(age) {}

    string getName() const {
        return name;
    }

    void setName(string name) {
        this->name = name;
    }

    int getAge() const {
        return age;
    }

    void setAge(int age) {
        this->age = age;
    }

    void print() {
        cout << "Name: " << name << ", Age: " << age << endl;
    }
};

2)
TestClass default constructor is ambiguous because of (int x=10). to fix it remove =10.
Modified code:
------------------
#include <iostream>

using namespace std;

class TestClass {
private:
    int val;
public:
    TestClass() { val = 10; }

    TestClass(int x) { val = x; }
};

Add a comment
Know the answer?
Add Answer to:
for c++ answer the following and create the following (1)Declare a class to hold Employee Data....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ Practice: Answer Whichever you can & it'll help a lot. Thank you! Question 1. Implement...

    C++ Practice: Answer Whichever you can & it'll help a lot. Thank you! Question 1. Implement the constructors and member function of each of the classes (Marks 15) class Fraction{ private: int numerator; int denominator; public: Fraction(int, int); float fractionValue();//determines the value of numerator/denominator }; class Problem{ private: Fraction f[3]; public: Problem(int, int, int, int, int, int); Fraction largestFraction();//Returns the fraction having largest fraction value }; Question 2: In the following Inheritance problem #include<iostream> #include<string> using namespace std; class Animal{...

  • C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to...

    C++ Lab 9A Inheritance Employee Class Create a project C2010Lab9a; add a source file Lab9a.cpp to the project. Copy and paste the code is listed below: Design a class named Employee. The class should keep the following information in member variables: Employee name Employee number Hire date // Specification file for the Employee class #ifndef EMPLOYEE_H #define EMPLOYEE_H #include <string> using namespace std; class Employee { private:        // Declare the Employee name string variable here. // Declare the Employee...

  • C++ Program 3 Create a class Person Include three(3) variables: firstName, lastName, YearOfBirth Write default and...

    C++ Program 3 Create a class Person Include three(3) variables: firstName, lastName, YearOfBirth Write default and parameterized constructors Write getters and setters for each variable. Declare 2 instances of the person class P1 and P2, one for both default and parm constructors Declare ptrPerson1 and ptrPerson2. Assign ptrPerson1 address of P1 Assign ptrPerson2 address of P2 Call all the getters and setters using the ARROW notation to test the class. Example:    ptrP1à getFirstName()

  • Write code to create a Java class called "Student". The class should hold information about a...

    Write code to create a Java class called "Student". The class should hold information about a student: name, id and whether or not the student is currently registered. There should be a constructor that takes name, id and registration status. Add getters and setters for the three properties. Make sure that you use appropriate visibility modifiers (public vs. private).

  • Need help to create general class Classes Data Element - Ticket Create an abstract class called...

    Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...

  • Please answer all the questions thank you 1) (Classes – 20 Points) Consider the following class...

    Please answer all the questions thank you 1) (Classes – 20 Points) Consider the following class declaration for Time to complete the questions below: DO NOT WRITE MORE THAN ASKED FOR. class Time private: int hours; int minutes; public: Time(); Time (int , int m = 0); void addMin(int m); void addHr(int h); void reset(int h = 0, int m = 0); Time operator+(const Time & t) const; Time operator-(const Time & t) const; Time operator*(double n) const; friend Time...

  • Greetings, everybody I already started working in this program. I just need someone to help me...

    Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...

  • In computer systems color is represented by RGB format (Red. Green and Blue color components) where...

    In computer systems color is represented by RGB format (Red. Green and Blue color components) where each component can hold a value from 0 to 255. Implement all functions and operators given in the following header file: # include using namespace std; class public://Default constructor//Constructor with parameters//Copy constructor//Getters//Setters//a function that increment all components//a print function to print all components//a function to add two private: int red; int green; int blue; Test your class with an appropriate main ()

  • PART 1: GETTING STARTED 1. Create a new Java Project. 2. Create a new Tree class...

    PART 1: GETTING STARTED 1. Create a new Java Project. 2. Create a new Tree class and enter this code. You do not have to type in the comments public class Tree { private String name; private int age; private bogJsAn evergreen; // true if evergreen // false if deciduous //CONSTRUCTORS public Tree( { name 0; evergreen = true; age } // you fill this one public Tree (String n, jnt a, bgalean e) //PUT YOUR CODE HERE } //...

  • Create a class named Date in C++ Class has 3 private data items (name the data...

    Create a class named Date in C++ Class has 3 private data items (name the data items month, day, year) int month int day int year Member functions ‘getters’   a getter for each data item Use ‘get’ and the data items name The data item name must be capitalized Return the data item Example: int getMonth()        {return month;} ‘setters’   a setter for each data item Use ‘set’ and the data items name The data item name must be capitalized Change...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT