Concept explainers
Day of the Year
Assuming a year has 365 days, write a class named DayOfYear that takes an integer representing a day of the year and translates it to a string consisting of the month followed by day of the month. For example,
Day 2 would be January 2.
Day 32 would be February 1. Day 365 would be December 31.
The constructor for the class should take as parameter an integer representing the day of the year, and the class should have a member function print () that prints the day in the month-day format. The class should have an integer member variable to represent the day, and should have static member variables holding string objects that can be used to assist in the translation from the integer format to the month-day format. Test your class by inputting various integers representing days and printing out their representation in the month-day format.
Want to see the full answer?
Check out a sample textbook solutionChapter 14 Solutions
Starting Out with C++ from Control Structures to Objects (8th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Objects (6th Edition)
C++ How to Program (10th Edition)
Concepts of Programming Languages (11th Edition)
Starting out with Visual C# (4th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
- Problem: Create a Fraction class with two private positive integer member variables numerator and denominator, one constructor with two integer parameters num and den with default values 0 and 1, one display function that print out a fraction in the format numerator/denominator in the proper form such as 2/3 or ½ . Note: 2/4 should be displayed as ½.arrow_forwardUSING C++ Write a simple class named Circle, with three private variables: doubles named x, y and radius. The center of the circle is denoted by coordinates (x,y), and the radius of the circle is denoted by radius. It should have public member functions with the following signatures: void setRadius(double r)void setX(double value)void setY(double value)double getRadius()double getX()double getY()double getArea()bool containsPoint(double xValue, double yValue) The first six member functions are straightforward functions to set and get the private member variables. double getArea() This member function should return the area of the circle. When you are calculating the area you can use 3.14 for pi. The formula is radius * radius * pi. bool containsPoint(double xValue, double yValue) This member function should return true if the point at (xValue, yValue) is contained in the circle, and false if not. You can determine whether or not a point is in a circle by calculating the…arrow_forwardWhen working on this C++ assignment, focus on memorizing the syntax for writing classes. Write a simple class named Circle, with three private variables: doubles named x, y and radius. The center of the circle is denoted by coordinates (x,y), and the radius of the circle is denoted by radius. It should have public member functions with the following signatures: void setRadius(double r)void setX(double value)void setY(double value)double getRadius()double getX()double getY()double getArea()bool containsPoint(double xValue, double yValue) The first six member functions are straightforward functions to set and get the private member variables. double getArea() This member function should return the area of the circle. When you are calculating the area you can use 3.14 for pi. The formula is radius * radius * pi. bool containsPoint(double xValue, double yValue) This member function should return true if the point at (xValue, yValue) is contained in the circle, and false if not. You…arrow_forward
- Create a class named Employee which contains an employee name, available to the entire program (public), and an employee ID number and hourly pay rate, available only to the members of the Employee class (private). Also write a constructor (the __init__ member function) which accepts a pay rate and changes it to 7.25, if the value entered is less than that. Do not write any accessor or mutator methods for the class.arrow_forward(Date Class) Create a class called Date that includes three pieces of information as datamembers—a month (type int), a day (type int) and a year (type int). Your class should have a constructor with three parameters that uses the parameters to initialize the three data members. For thepurpose of this exercise, assume that the values provided for the year and day are correct, but ensurethat the month value is in the range 1–12; if it isn’t, set the month to 1. Provide a set and a get function for each data member. Provide a member function displayDate that displays the month, dayand year separated by forward slashes (/). Write a test program that demonstrates class Date’s capabilities.arrow_forwardBuild a class named car. This class is defined as follows: It has the fields: Car ID, Car model , Car make, Car color, Car year. Build a constructor that accepts the five parameters (Car ID, Car model , Car make,Car color, Car year). Override the method toString() to return the string representation of Car ID, Carmodel , Car make, Car color, Car year.arrow_forward
- "The program instantiates and uses instances of a derived class with default and parameterized constructors. Write A Base Class Declare a class named RealProperty that could be used to describe a piece of real property. It should contain these private fields: streetAddress (string) squareFootage (int) taxes (double) Each field should have a comment documenting what it is for. Add public member functions as follows: The default constructor. The default constructor initializes the fields so that the street address is an empty string and all numeric fields are 0 or 0.0. Implement the default constructor inline using the member initialization list syntax. The constructor that accepts these data: street address (string), square footage (int), and taxes (double). Implement this constructor inline using the member initialization list syntax and call the mutator function for square footage in the body of the constructor. Add mutator member functions to set the fields. One member function for…arrow_forwardCould this please be written in C++ 11, thanks ! Design a "Tips" class that calculates the gratuity on a restaurant meal. Its only class member variable, "taxRate", should be set by a one-parameter constructor to whatever rate is passed to it when a "Tips" object is created. If no argument is passed, a default tax rate of .085 should be used. The class should have just one public function, "computeTip". This function needs to accept two arguments, the total bill amount and the tip rate. It should use the total bill amount, along with the value stored in the "taxRate" member variable, to compute the cost of the meal before the tax was added. It should then apply the tip rate to just the meal cost portion of the bill to compute and return the tip amount. Demonstrate the class by creating a program that creates a single "Tips" object, and then has a sentinel-controlled loop to let the user retrieve the correct tip amount using various bill totals and desired tip rates.arrow_forwardwrite a class Point with parametrized constructor. This class have four member variables, a,b,c,d. Write the following member functions a. drawTriangle(int x, int y, int z ) b. drawRectangle(int x, int y, int z, int a). Each function should display the length of lines for each of the shape (triangle, rectangle). For example triangle should calculate length of its three lines by following methods as shown in code. Note: the number of lines depends on the name of shape. void drawTriangle(int x, int y, int z ) { int line 1 = x - y; // convert to positive value if line length is negative int line 2 = y -z; int line 3 = z -x; cout<< The length of each lines is: << //// here display length of each line with proper formatting. } Write similar code for drawRectangle(int x, int y, int z, int a). Wtite main function to call these three functionarrow_forward
- Create a class Vehicle and three additional classes (each derived from Vehicle) named Car, Truck and Boat. The member attributes and functions for each class are given below. Make parametrized constructor for all classes.Vehicle:private:int wheels;float weight;int model;int passenger_capicty;public:void print_info()=0;Car:public:void print_info();Truck:private: float load_capicty;public:void print_info();Boat:public:void print_info();arrow_forwardC # Write the code to create a class called Pet that can store the information about a pet: Example: a female dog named Molly who is 6 years old. Include at least 1 constructor that doesn't allow age to be negativearrow_forwardMartin your friend has declared a class called Employee with the following members; EmployeeID, Employee Name, Basic Salary, Allowance, and Net Salary.a) Write a code for a member function called get_input that will be used for data input.b) Write a code for a member function called Calculate that will be used to calculate netsalary as the sum of basic salary and allowances. c) Write a code for the default constructor that will assign values to the variables in theEmployee class. d) Write a code for the default constructor. e) Write a complete program that captures and includes all the details in (a-d) above.Run the code and show your output.arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT