QuestionQuestion

1. What is a class constructor, when is it executed, and what is it used for?

2. Explain the difference between the default and non-default constructor.

3. What is the difference between a function and a member function?

4. Explain the difference between the private and public access modifier. Give an example using code when a private member cannot be accessed.

5. (Upload as Source) Create a Stock class which contains the following members:
a. String representing the name of the stock
b. Integer representing the number of shares owned
c. Float representing the price per share
d. Default Constructor which sets the name to be empty, and the share price and number of shares to zero.
e. Non-default constructor which allows setting of the name, number of shares and share price through the method’s parameters.
f. A member function which prints all the stock’s information to the console. Use whatever format you deem appropriate
g. A member function which returns back the value of the stock by multiplying the price per share by the number of shares. (No cout in this member function)
h. Test all member functions in the main to prove proper implementation.

6. (Upload as Source) Create a Date class which contains the following members:
a. integers representing the day, month, and year
b. Default constructor which sets the date to January first 2000
c. A non-Default constructor which allows the setting of day, month, and year through parameters
d. A member function which prints the date of the object to the console in the format MM/DD/YYYY, where MM, DD, and YYYY is month, day, and year respectively. Do not worry about zero padding month, day and year.
e. A member function which increments the date to the next day. Ensure that the code allows for proper increments the month and year when necessary. You may assume no leap years for simplicity.
f. Implement a method which compares the current Date object to another Date object passed in as a parameter. If the current object’s date comes before the passed in object’s date, return true, otherwise return false.
g. Test all member functions in the main to prove proper implementation.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

1. What is a class constructor, when is it executed, and what is it used for?
Class constructor is a special member functions for creating objects that belong to a class
It executes when we want to create an object of the class
It is used for constructing new objects and assigning values to their data members.

2. Explain the difference between the default and non-default constructor.
a. A default constructor is a constructor that is used to create an object when we don’t provide
explicit initialization values.
b. A non-default constructor is a constructor that is used to create an object when we provide explicit initialization values...
$40.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Visual Basic Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats