Question

In: Computer Science

C++ Define a class PersonalRecord, which will be storing an employee’s information. Internally, the class should...

C++

Define a class PersonalRecord, which will be storing an employee’s information.


Internally, the class should have the following attributes:

SSN (string type), fullName (string type), homeAddress (string type), phoneNumber (string type), salaryRate (per year, float type), and vacationDays (accrued vacation, int type).


The constructor should take six parameters:

four of them are necessary to provide values to at the time of initialization (when a constructor will be called/invoked): SSN, fullName, homeAddress, and phoneNumber;

and two of them are optional parameters: salaryRate, vacationDays with values by default to be 0 for each.


Provide natural implementation for the member functions:

getName(), setName(name), getSalary(), and setSalary(salary).


Use the header file (.h) and the source-code file (.cpp) to separate the interface of the class from its implementation.


You don’t need to incorporate any checks on validity of data.


The test code given below creates two records for the following people (if you want to use it for testing, put in into a separate .cpp file):

John Hue; SSN: 111119911; Address: 234 Avenue B, Brooklyn, NY; phone number: (718) 222-3445; salary: $35000.

Mary Jones; SSN: 222334455; Address: 123 Kings Avenue, Apt. 10, Queens, NY; phone

number: (718) 555-3112.

Then calls some of the methods to see that they are working.


Feel free to use a C++ code editor. When putting the answer below, first put the content of the header file, followed with

//--------------- implementation

comment, then put the content of the source-code file.

Test code:

#include <iostream>

#include "PersonalRecord.h"
using namespace std;


int main() {

  PersonalRecord p1("111119911", "John Hue", "234 Avenue B, Brooklyn, NY", "(718)222-3445", 35000);

  cout << p1.getName() << " earns $" << p1.getSalary() << " per year\n";

  PersonalRecord p2("222334455", "Mary Jones", "123 Kings Avenue, Apt. 10, Queens, NY", "(718)555-3112");

  cout << p2.getName() << " earns $" << p2.getSalary() << " per year\n"; cout << " after the information is updated: " << endl;

p2.setName("Mary A Jones");

p2.setSalary(50000);

cout << p2.getName() << " earns $" << p2.getSalary() << " per year\n";

}

Solutions

Expert Solution

//PersonalRecord.h

//PersonalRecord header file
#include<iostream>

class PersonalRecord{

private:
//private data members
std::string SSN, fullName, homeAddress,phoneNumber;
float salaryRate;
int vacationDays;

public:

//constructors with four parameters
PersonalRecord(std::string SSN, std::string fullName,
std::string homeAddress, std::string phoneNumber);

//constructors with five parameters
PersonalRecord(std::string SSN, std::string fullName,
std::string homeAddress, std::string phoneNumber,
float salaryRate, int vacationDays);

//constructors with six parameters
PersonalRecord(std::string SSN, std::string fullName,
std::string homeAddress, std::string phoneNumber,
float salaryRate);

//method to set name
void setName(std::string name);

//method returns name
std::string getName ();

//method to set salary
void setSalary(float salary);

//method returns salary
float getSalary();
};

//PersonalRecord.cpp

#include"PersonalRecord.h"
//PersonalRecord.cpp
//implementation file

//constructors

PersonalRecord::PersonalRecord(std::string SSN, std::string fullName,
std::string homeAddress, std::string phoneNumber){

this->fullName = fullName;
this->SSN = SSN;
this->homeAddress = homeAddress;
this->phoneNumber = phoneNumber;
this->salaryRate = 0;
this->vacationDays = 0;

}

PersonalRecord::PersonalRecord(std::string SSN, std::string fullName,
std::string homeAddress, std::string phoneNumber,
float salaryRate){

this->fullName = fullName;
this->SSN = SSN;
this->homeAddress = homeAddress;
this->phoneNumber = phoneNumber;
this->salaryRate = salaryRate;
this->vacationDays = 0;

}

PersonalRecord::PersonalRecord(std::string SSN, std::string fullName,
std::string homeAddress, std::string phoneNumber,
float salaryRate, int vacationDays){

this->fullName = fullName;
this->SSN = SSN;
this->homeAddress = homeAddress;
this->phoneNumber = phoneNumber;
this->salaryRate = salaryRate;
this->vacationDays = vacationDays;

}

//member functions

void PersonalRecord:: setName(std::string name){
this->fullName = name;
}

std::string PersonalRecord::getName (){
return this->fullName;
}

void PersonalRecord::setSalary(float salary){
this->salaryRate = salary;
}

float PersonalRecord::getSalary(){
return this->salaryRate;
}

//Main.cpp

#include <iostream>

#include "PersonalRecord.h"
using namespace std;


int main() {

PersonalRecord p1("111119911", "John Hue", "234 Avenue B, Brooklyn, NY", "(718)222-3445", 35000);
cout << p1.getName() << " earns $" << p1.getSalary() << " per year\n";

PersonalRecord p2("222334455", "Mary Jones", "123 Kings Avenue, Apt. 10, Queens, NY", "(718)555-3112");
cout << p2.getName() << " earns $" << p2.getSalary() << " per year\n";
cout << " after the information is updated: " << endl;

p2.setName("Mary A Jones");

p2.setSalary(50000);

cout << p2.getName() << " earns $" << p2.getSalary() << " per year\n";

}

/*
Output

John Hue earns $35000 per year
Mary Jones earns $0 per year
after the information is updated:
Mary A Jones earns $50000 per year

Process returned 0 (0x0) execution time : 0.016 s
Press any key to continue.

*/


Related Solutions

In C++ Define a base class called Person. The class should have two data members to...
In C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and...
Write a C++ program for storing information on on a series of balls collected by a...
Write a C++ program for storing information on on a series of balls collected by a person. The balls should have these characteristics: 1. Diameter in mm 2. Color 3. if the texture of the surface is smooth or rough 4. an identification id/number The program should allow the person to enter the values for the balls' attributes as they are entered in a database. The program should then offer the choice to save all new data into a file....
Write a C++ program for storing information on on a series of balls collected by a...
Write a C++ program for storing information on on a series of balls collected by a person. The balls should have these characteristics: 1. Diameter in mm 2. Color 3. if the texture of the surface is smooth or rough 4. an identification id/number The program should allow the person to enter the values for the balls' attributes as they are entered in a database. The program should then offer the choice to save all new data into a file....
C++ Define a base class called Person. The class should have two data members to hold...
C++ Define a base class called Person. The class should have two data members to hold the first name and last name of a person, both of type string. The Person class will have a default constructor to initialize both data members to empty strings, a constructor to accept two string parameters and use them to initialize the first and last name, and a copy constructor. Also include appropriate accessor and mutator member functions. Overload the operators == and !=...
Define a class template called genericStack for storing any data type in a static stack. Your...
Define a class template called genericStack for storing any data type in a static stack. Your class template must include a constructor, a destructor, push, pop, peek, isFull, and isEmpty functions (no display function is required). Write a simple main function in your program that demonstrates the class template with a stack of strings.
//LinkNode is a class for storing a single node of a linked list storing integer values....
//LinkNode is a class for storing a single node of a linked list storing integer values. It has two public data fields for the data and the link to //the next node in the list and has three constructors: public class LinkNode { public int data;       public LinkNode next; // post: constructs a node with data 0 and null link public ListNode() {      this(0, null); } // post: constructs a node with given data and null link public LinkNode (int...
Create a class named GameCharacter to define an object as follows: The class should contain class...
Create a class named GameCharacter to define an object as follows: The class should contain class variables for charName (a string to store the character's name), charType (a string to store the character's type), charHealth (an int to store the character's health rating), and charScore (an int to store the character's current score). Provide a constructor with parameters for the name, type, health and score and include code to assign the received values to the four class variables. Provide a...
C++ please Create a Stats class whose member data includes an array capable of storing 30...
C++ please Create a Stats class whose member data includes an array capable of storing 30 double data values, and whose member functions include total, average, lowest, and highest functions for returning information about the data to the client program. These are general versions of the same functions you created for Programming Challenge 7, but now they belong to the Stats class, not the application program. In addition to these functions, the Stats class should have a Boolean storeValue function...
Term Project C++ Pet Class Problem Specification: Design a class named Pet, which should have the...
Term Project C++ Pet Class Problem Specification: Design a class named Pet, which should have the following fields: • name: The name field holds the name of a pet. • type: The type field holds the type of animal that a pet is. Example values are “Dog”, “Cat”, and “Bird”. • age: The age field holds the pet’s age. The Pet class should also have the following methods: • setName: The setName method stores a value in the name field....
write a c++ program. Define a class ‘Matrix’ which contain 2D int array ‘m’ of size...
write a c++ program. Define a class ‘Matrix’ which contain 2D int array ‘m’ of size 3x3 as private member.        There should be two public methods within the class definition namely: void setMatrixValue(int i, int j); that should set m[i][j] with user defined values int getMatrixValue(int i, int j); that should return m[i][j] Make a global function named ‘CrossProduct(Matrix m1, Matrix m2)’ that should compute the marix multiplication
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT