Question

In C++ Class creation: You have to create a simple class from scratch – You will...

In C++ Class creation: You have to create a simple class from scratch – You will need to create the member variables, constructors, accessors, mutators and one additional method. For this you will need to split the two sections up to show the declaration section and implementation section.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

class Cat // begin declaration of the class

{

public: // begin public section

Cat(int initialAge); // constructor

int GetAge() const; // accessor function

void SetAge(int age); // mutator function

void Meow();

private:

int itsAge; // member variable

};

// constructor of Cat,

Cat::Cat(int age)

{

itsAge = age;

}

// GetAge, Public accessor function

// returns value of itsAge member

int Cat::GetAge() const

{

return itsAge;

}

// Definition of SetAge

// mutator function

void Cat::SetAge(int age)

{

// set member variable its age to

// value passed in by parameter age

itsAge = age;

}

// definition of Meow method

// action: Prints "meow" to screen

void Cat::Meow()

{

cout << "Meow.\n";

}

Add a comment
Know the answer?
Add Answer to:
In C++ Class creation: You have to create a simple class from scratch – You will...
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
  • Define a class named Employee . Derive this class from the class Person. An employee record...

    Define a class named Employee . Derive this class from the class Person. An employee record inherits an employee's name from the class Person. In addition, an employee record contains an annual salary (represented by a single value of type double), a hire date that gives the year hired (as a single value of type int), an identification number of type int, and a department of type String. Give your class a reasonable complement of constructors, accessors, mutators, an equals...

  • 1a. Create a class named Computer - Separate declaration from implementation (i.e. Header and CPP files)...

    1a. Create a class named Computer - Separate declaration from implementation (i.e. Header and CPP files) 1b. Add the following private member variables - an int variable named year - a string variable named model - a string variable named purpose 1c Add the following public functions: - Default constructor which sets numeric members to -1 and string members to the empty string - Destructor to print "Removing instance from memory" - A non-default constructor to set the year and...

  • Create a class House with the private fields: numberOfUnits of the type int, yearBuilt of the...

    Create a class House with the private fields: numberOfUnits of the type int, yearBuilt of the type int, assessedPrice of the type double. A constructor for this class should have three arguments for initializing these fields. Add accessors and mutators for all fields except a mutator for yearBuilt, and the method toString. Create a class StreetHouse which extends House and has additional fields: streetNumber of the type int, homeowner of the type String, and two neighbors: leftNeighbor and rightNeighbor, both...

  • When answering this question, can you please specify what you name your files? Thank you! Write a...

    When answering this question, can you please specify what you name your files? Thank you! Write a Java application, and an additional class to represent some real-world entity. Keep in mind that a class is a model in code of something real or imagined, which has attributes (member variables) and behaviors (member methods). The class will: a. Create a total of 5 member variables for the class, selecting the appropriate data types for each field. For example, a class to...

  • 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...

  • Visual C# Homework 2 You are to write a program which will create a class called...

    Visual C# Homework 2 You are to write a program which will create a class called Student Each student has a name age height and weight. These variables should be declared as private. Create the correct constructors and functions. In the main, you will create 5 students. Input the data for the 5 students from a file which already has information in it. Name the file “Information.txt”. After setting up all the data, it is time to sort based on...

  • Making a rectangle class in java write a simple class that will represent a rectangle. Later...

    Making a rectangle class in java write a simple class that will represent a rectangle. Later on, we will see how to do this with graphics, but for now, we will just have to use our imaginations for the visual representations ofWthe rectangles. Instance Variables Recall that an object is constructed using a class as its blueprint. So, think about an rectangle on your monitor screen. To actually draw a rectangle on your monitor screen, we need a number of...

  • USING BLUEJ: You will write from scratch a class called Heater that represents an adjustable thermostat....

    USING BLUEJ: You will write from scratch a class called Heater that represents an adjustable thermostat. Follow the detailed steps below. This is based on Exercises 2.93 - 2.94 (6e) / 2.92 - 2.93 (5e) in the book, but with slight modifications, so be sure to follow the instructions below. Create a new BlueJ project named LastName-heater using your last name. Create a class named Heater At the top of the source code for Heater, add documentation like this: /**...

  • 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...

  • Design and implement a C++ class called Date that has the following private member variables month...

    Design and implement a C++ class called Date that has the following private member variables month (int) day (nt) . year (int Add the following public member functions to the class. Default Constructor with all default parameters: The constructors should use the values of the month, day, and year arguments passed by the client program to set the month, day, and year member variables. The constructor should check if the values of the parameters are valid (that is day is...

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