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 a class dayType that implements the day of the week in a program. The classdayType should store the day, such as Sun for Sunday. The program should be able to perform thefollowing operations on an object of type dayType:a) Set the day.b) Print the day.c) Return the day.d) Return the next day.e) Return the previous day.f) 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.g) Add the appropriate constructors.The class dateType was designed to implement the date in a program, but the member function setDateand the constructor do not check whether the date is valid before storing the date in the member variables.Rewrite the definitions of the function setDate and the constructor so that the values for the month, day,and year are checked before storing the date into the…
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.
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
- 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 agearrow_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 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_forward
- Create the following class diagram: The print method in: - Author prints the Authors data - Page prints page no and text - Textbook prints the subject and all pages - Novel prints the genre and all pages The toString method in: - Book returns title and authors - textbook returns subject in additions to super toString - Novel genre in additions to super toString Test your implementation create objects of different types example : - Create a book of type Novel which has many pages and several authors - Create a book of type Textbook which has many pages and several authors - Access these objects polymorphically, variable of class book contains objects of its subclasses Textbook and novel - Print a hall book - Print a single page of a book - Print the book and its authorsarrow_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_forwardjava 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_forward
- #this is a python programtopic: operation overloading, Encapsulation Please find the attached imagearrow_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_forwardA 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_forward
- 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) otherwisearrow_forwardDesign a class named Rectangle to represent a rectangle. The class must have the following: • double data fields named width and height. The default values are 1 for both width and height A no-argument constructor that creates a default bag. A constructor that creates a rectangle with the specified width and height A getParameter() method to return the perimeter. • A getArear() method to return the area of the Rectangle. Create two Rectangle objects. One with width 4.0 and height 10.0. The other object has width 6.3 and height 10.5.arrow_forwardRectangle Object Monitoring Create a Rectangle class that can compute the total area of all the created rectangle objects using static fields (variables). Remember that a Rectangle has two attributes: Length and Width. Implement the class by creating a computer program that will ask the user about three rectangle dimensions. The program should be able to display the total area of the three rectangle objects. For this exercise, you are required to apply all OOP concepts that you learned in class. Sample output: Enter Length R1: 1 Enter Width R1: 1 Enter Length R2: 2 Enter Width R2: 2 Enter Length R3: 3 Enter Width R3: 3 The total area of the rectangles is 14.00 Note: All characters in boldface are user inputs.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