C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
expand_more
expand_more
format_list_bulleted
Question
Chapter 10, Problem 7PE
Program Plan Intro
Program Plan:
- Declare a class dayType to store a day and to check the day number is valid or not. If it is valid, then go to the next function. Otherwise print the message "Day number should be in between 0 and 6."
- Implement the main function that tests all constructors and functions in the class dayType.
- Implement set function that accepts a day as a parameter then verifies whether the day is valid and sets that day as the current day.
- Implement print function that accepts a day as an integer parameter and displays that day as a string.
- Implement getDay function that returns the current day as an integer.
- Implement next_day function that returns the next day to the current day as an integer.
- Implement prev_day function that returns the previous day to the current day as an integer.
- Implement a default constructor that sets 0 to the current day as Sun (Sunday).
- Implement parameterized constructor that sets the specified day to the current day.
Program Description: The purpose of the program is to implement the days of the week. It stores the day such as Sunday and it performs the specified operations.
Expert Solution & Answer
Trending nowThis is a popular solution!
Students have asked these similar questions
Design and implement a class dayType that implements the day of the
week in a program. The class dayType should store the day, such as Sun
for Sunday. The program should be able to perform the following operations
on an object of type dayType:
Set the day.
a.
b.
Print the day.
Return the day.
c.
d.
Return the next day.
Return the previous day.
е.
Calculate and return the day by adding certain days to the current day.
For example, if the current day is Monday and we add 4 days, the day to
be returned is Friday. Similarly, if today is Tuesday and we add 13 days,
the day to be returned is Monday.
f.
g.
Add the appropriate constructors.
Write the definitions of the functions to implement the operations for the
class dayType as defined in Programming Exercise 5. Also, write a
program to test various operations on this class.
Code for dayType class:
class dayType
{
public:
static string weekDays[7];
void print() const;
string nextDay) const;
string prevDay() const;
void addDay(int nDays);…
Design and implement the class Day that implements the day of the week in a program. The program should be able to perform the following operations on an object of the type Day:
Set the day.
Print the day.
Return the day.
Return the next day.
Return the previous day.
Add a comment with your full name in it in any part of the program.
Using JAVASCRIPT write an object prototype for a Person that has a name and age, has a printInfo method, and also has a method that increments the persons age by 1 each time the method is called. Create two people using the 'new' keyword, and print both of their infos and increment one persons age by 3 years. Use an arrow function for both methods */ // Create our Person Prototype // Use an arrow to create the printInfo method // Create another arrow function for the addAge method that takes a single parameter // Adding to the age
Chapter 10 Solutions
C++ Programming: From Problem Analysis to Program Design
Ch. 10 - Mark the following statements as true or false....Ch. 10 - Find the syntax errors in the following class...Ch. 10 - Find the syntax errors in the following class...Ch. 10 -
Find the syntax errors in the following class...Ch. 10 -
Find the syntax errors in the following class...Ch. 10 - Prob. 6SACh. 10 - Assume the definition of class foodType as given...Ch. 10 -
Consider the definition of the following class:...Ch. 10 - Consider the definition of the class product Type...Ch. 10 -
Consider the definition of the class product Type...
Ch. 10 - Prob. 11SACh. 10 -
Assume the definition of class houseType as given...Ch. 10 - Chapter 9 defined the struct studentType to...Ch. 10 - Write a program that uses the class productType...Ch. 10 -
Write a program that uses the class houseType...Ch. 10 - Prob. 6PECh. 10 - Prob. 7PECh. 10 - Some of the characteristics of a book are the...Ch. 10 - Define the class bankAccount to implement the...
Knowledge Booster
Similar questions
- Write code for an Invoice class for a car sale. Printing an object of the Invoice should print thedetails about the seller, the buyer, the dealer, the date of transaction, the car being sold, the purchase andselling price, the commission earned by the dealer, sales tax, and the total price of the car (calculated giventhe details in Question 3 part 3). A generation of the invoice object should set the isSold variable of the car class to true. You do not need to write code for any other classes import java.io.File;import java.io.FileWriter;import java.io.IOException; abstract class Car { // class car String[] name; int reg_number, eng_number, chassis_num, status; String[] city, model, color, date_reg, date_arr, type; float price; abstract float calculate(float price);} class Dealer extends Car { // inherits from Car String[] deal_name, deal_id, deal_add, deal_pno; float dealer_com; float calculate(float price) { dealer_com = (float) (0.01 * price + 0.01 * price); // adding extra 2%…arrow_forwardWrite code for an Invoice class for a car sale. Printing an object of the Invoice should print thedetails about the seller, the buyer, the dealer, the date of transaction, the car being sold, the purchase andselling price, the commission earned by the dealer, sales tax, and the total price of the car (calculated giventhe details in Question 3 part 3). A generation of the invoice object should set the isSold variable of the carclass to true. You do not need to write code for any other classesQuestion 3 part 3 is given Below[Question 3:1. Explain the importance of method signature in method overriding. 2. The system might want to use an overridden method (function) with a common signature across the relevant classes Seller, Dealer, Buyer, and distinct classes Car and Invoice for maintaining the finances. Details of the classes can be seen in Table 1. Explain with proper syntax as to how this can be achieved using object-oriented programming.3. Write Java code (for the methods only) that…arrow_forwardSlide Type Slide • Exercise # 1: Define a class Point that represents a point in 2 – D plane. The point has x and y coordinates. Define the following: • A constructor to initialize the x, y coordinates. • A method translate(self, dx,dy) to translate the point object dx , and dy units in x and y directions, respectively. • A method distanceTo (self, point2) to return the distance between the point referenced by self and point2. • getX(self) to return the value of x coordinate. • getY(self) to return the value of y coordinate Test the above class by: • Creating 2 point objects; one with (3,5) as x,y coordinates; the second with (-10,30) as x,y coordinates. • Move the first point 5.5 units in x direction and -12.5 units in y direction using translate method • Find the distance between the 2 points in their current location using distance To method A Sample output resulting from running the above test class is shown below new coordinates of point1= (8.5 , -7.5) Coordinates of point 2 =…arrow_forward
- java languageCreate a class with following attributes: The car's make The car's model The car's year Now let's identify the class's methods. Specifically, the actions are: Constructor of Car class Set and get the car's make Set and get the car's model Set and get the car's year Now create few instance of the Car in a Test class. Use getter and setter to set the instance variables. Create a class with following attributes: The car's make The car's model The car's year Now let's identify the class's methods. Specifically, the actions are: Constructor of Car class Set and get the car's make Set and get the car's model Set and get the car's year Now create few instance of the Car in a Test class. Use getter and setter to set the instance variables.arrow_forwardPlease do it in JavaScript or C# 1) Design and implement the class structure for a drawing application. A drawing is made up of a canvas that contains a collection of three different shapes: circles, lines, and boxes. Each shape can be drawn by calling a Draw() method for that shape. The canvas class should also have a draw method that draws all of the shapes it contains. You don’t have to actually draw anything on a screen; you can simulate drawing by writing a message to the console.For example, the code snippet: canvas.Draw();Drawing a circle at...Drawing a line at...etc. (For each shape on the canvas) 2)(Bonus) Consider re-writing the above answer (#1) differently where the canvas does not contain the shapes, but is able to draw any of the three shapes passed to it. Re-design canvas.Draw() if you need to. Your main() program should ask for user input on what shape to draw. Ask once, draw, then exit.could produce something like the following output to the console:arrow_forwardJAVA Task Write a JAVA class named Account to represent an account that you may find at a bank. Accounts have a balance and an annual interest rate. Include attributes in the Account class to reflect these. Write getters for both attributes and a setter for only the annual interest rate. Think about how real bank accounts work, you change your balance by withdrawing and depositing money, not just by telling the banker how much you want to change it to. Include a constructor with parameters used to assign values to both attributes. Users should be able to withdraw money from an Account, deposit money into an Account, find monthly interest rate, and find monthy interest. Include methods for each of these actions. More details on them below. withdraw method This method simulates withdrawing money from the Account. It should not return a value and take the amount to withdraw as a parameter and reduce the balance by this amount. deposit method This method simulates depositing money into…arrow_forward
- A TV Class The attributes of a TV object are the channel, the volume, and a flag (or switch) indicating whether the TV is on or off. The methods perform the following actions: • Turn the TV on or off. • Set the channel to an integer from 0 to 99 inclusive. • Raise or lower the volume by one unit. The volume can range from 0 to 20. • View the value of the volume. • View the channel. • Determine whether the TV is on or off. Write a TV class that implements all relevant functions. A newly created TV object is set to off with the channel set to 2 and the volume initially 10. Include a main(...) method that tests the methods of the TV class.arrow_forwardDefine the Artist class with a constructor to initialize an artist's information and a print_info() method. The constructor should by default initialize the artist's name to "None" and the years of birth and death to 0. print_info() should display Artist Name, born XXXX if the year of death is -1 or Artist Name (XXXX-YYYY) otherwisearrow_forwardPYTHON: Define the Artist class with a constructor to initialize an artist's information and a print_info() method. The constructor should by default initialize the artist's name to "None" and the years of birth and death to 0. print_info() should display Artist Name, born XXXX if the year of death is -1 or Artist Name (XXXX-YYYY) otherwise. Define the Artwork class with a constructor to initialize an artwork's information and a print_info() method. The constructor should by default initialize the title to "None", the year created to 0, and the artist to use the Artist default constructor parameter values. Ex: If the input is: Pablo Picasso 1881 1973 Three Musicians 1921 the output is: Artist: Pablo Picasso (1881-1973) Title: Three Musicians, 1921 If the input is: Brice Marden 1938 -1 Distant Muses 2000 the output is: Artist: Brice Marden, born 1938 Title: Distant Muses, 2000 I have the code but I am getting errors that I can't seem to get rid of any suggestions would be appreciatedarrow_forward
- #this is a python programtopic: operation overloading, Encapsulation please find the attached imagearrow_forwardAn object of the class Timer is used to indicate when a certain amount of time (in seconds) has elapsed, after which it provides a “DING”. The required data field is remainingTime which is the number of seconds until the “DING”. When a Timer object is constructed, it is set with the desired number of seconds. When the timer “ticks”, it is one second closer to the “DING”. This is represented with the tick() method. The dingCheck() method indicates whether the timer should be “DINGING”. Provide the code for the constructor method, and the methods getRemainingTime(), tick(), and dingCheck(). public class Timer { // Methods // Data private int remainingTime; }arrow_forwardplease code in python Answer the following questions about this Dog class: [refer image for dog class] 1. Construct an instance of the Dog class whose name is Snickers and was born in2011 and assign that instance to a variable called myDog.2. Call the bark method so that myDog barks 3 times.3. Add a method to the Dog class called isPuppy that returns True if the dog is lessthan 1 year old.4. Add the __str__ method to the Dog class. It should return a string that includesthe dog’s name and age.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:9781337102124
Author:Diane Zak
Publisher:Cengage Learning