Concept explainers
Day of the Year
Assuming that 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 of type string 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 11 Solutions
STARTING OUT WITH C++ MPL
Additional Engineering Textbook Solutions
Starting Out With Visual Basic (8th Edition)
SURVEY OF OPERATING SYSTEMS
Modern Database Management
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Starting Out with Python (4th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
- A(n) ____________ is one instance or variable of a class.arrow_forwardIN C++ Write a class named Employee that has the following member variables: name. A string that holds the employee’s name. idNumber. An int variable that holds the employee’s ID number. department. A string that holds the name of the department where the employee works. position. A string that holds the employee’s job title. The class should have the following constructors: A constructor that accepts the following values as arguments and assigns them to the appropriate member variables: employee’s name ( non-empty) , employee’s ID number( neither 0 nor negative numbers), department ( non-empty), and position ( non-empty). Write appropriate setter functions that store values in these member variables and getter functions that return the values in these member variables. Once you have written the class, write a main program that creates FOUR Employee objects to hold the above data. The program should store this data in the four objects and then display the data in tabular form for…arrow_forwardUse Python Programming Language (The Stock class) Design a class named Stock to represent a company’s stock that contains: A private string data field named symbol for the stock’s symbol. A private string data field named name for the stock’s name. A private float data field named previousClosingPrice that stores the stock price for the previous day. A private float data field named currentPrice that stores the stock price for the current time. A constructor that creates a stock with the specified symbol, name, previous price, and current price. A get method for returning the stock name. A get method for returning the stock symbol. Get and set methods for getting/setting the stock’s previous price. Get and set methods for getting/setting the stock’s current price. A method named getChangePercent() that returns the percentage changed from previousClosingPrice to currentPrice. Write a test program that creates a Stock object with the stock symbol INTC, the name Inte lCorporation, the…arrow_forward
- c++ Design a PayRoll class that has data members for an employee’s hourly pay rate,number of hours worked, and total pay for the week. Write a program with anarray of seven PayRoll objects. The program should ask the user for the number ofhours each employee has worked and will then display the amount of gross payeach has earned.Input Validation: Do not accept values greater than 60 for the number of hoursworked.arrow_forwardA constructor is like a function. It can return any type value needed.t or f?arrow_forwardUsing C++ 11 Design a class called NumDays. The class’s purpose is to store a value that represents a number of work hours and converts it to a number of days. For example, 8 hours would be converted to 1 day. 12 hours would be converted to 1.5 days, and 18 hours would be converted to 2.25 days. The class should have a constructor that accepts a member of hours, as well as member functions for storing and retrieving the hours and days. The class should also have the following overloaded operators: + Addition operator. When two NumDays objects are added together, the overloaded + operator should return the sum of the two objects’ hours members. - Subtraction operator. When one NumDays object is subtracted from another, the overloaded – operator should return the difference of the two objects’ hours members. ++ Prefix and postfix increment operators. These operators should increment the number of hours stored in the object. When incremented, the number of days…arrow_forward
- class Movie { A The code is correct. string title; int year; public: void set_title (string); string get_title(); void set_year (int); int get year(); bool equals (const Movie&); }; Regarding above code, select the correct answer among below 4 choices. B The code is wrong because ' private: ' should be included. The code is wrong because the class name is not defined. D) The code is wrong because member function is not included.arrow_forwardTrue or False It is legal to write a class without any constructors.arrow_forwardProblem C • -3: method consonants() had more than one loop • -3: method initials () had more than one loop • -3: at least one method used nested loopsarrow_forward
- In C++ compile a program to fufill purpose mentioned below, not copied from internet please. Assuming that 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.arrow_forwardC++ OOP use classes only.arrow_forwardIn pseudocode, write the first line of the definition for a Poodle class. The class should extend the Dog class.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTSystems ArchitectureComputer ScienceISBN:9781305080195Author:Stephen D. BurdPublisher:Cengage Learning