Question
Q.1 Declare a class Salary it should have the following members i. An integer called payAmount (holds the amount of salary) ii. A float called
Q.1 Declare a class Salary it should have the following members
i. An integer called payAmount (holds the amount of salary)
ii. A float called incomeTaxPercentage (holds the % of income that is deducted as tax)
Declare a class Staff it should have the following members:
i. a char pointer to point to a name called namePtr (to save a location of the char array that holds the name)
ii. an object of class Salary
iii. a char pointer to point to the job description called jDescPtr (to save a location of the char array that holds the job description) Reminder: All pointers are only memory address holders they cannot store variable values in them. In this class namePtr cannot hold the name but it can point to the memory address of the array that holds name. Same for jDescPtr. Interface:
Task 1: a constructor that takes a name, a salary object and job description and assigns these to the members of the new object.
1. Declare memory (or char array) to copy the name in.
2. store the location of this array in the pointer called namePtr
3. Copy the contents of salary type argument to the salary member variable.
4. Declare memory or char array to copy the job description in.
5. store the location of this array in the pointer called jDescPtr
Task 2: a print function that prints out the members of the object.
Task 3: Test whether your constructor and print function work or not by declaring and using 2 objects of Staff class.
Task 4: Object vs Pointer
i. Declare an object of type Salary and give the object some values
ii. Declare a pointer of type Salary and assign it the address of the object from i)
iii. What is the size of the object in i) in bytes. Explain the size you have mentioned.
iv. What is the size of the pointer in ii) in bytes. Explain the size you have mentioned.
v. Use the pointer in ii) to change the values of the member variables of the object it is pointing to.
Q2. Add a third question to make a node class that has two data members:
An object of the class Staff
A pointer that can point to the next Node, called next
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started