Problem Solving with C++, Student Value Edition
10th Edition
ISBN: 9780134543680
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 10.2, Problem 24STE
Program Plan Intro
Constructor initialization section
Program plan:
- In the “DayOfYear” class, declare the default and parameterized constructor in the “public” access specifier.
- Define the default constructor of class “DayOfYear”.
- Assign the value “1” to the variable “month” in the constructor initialization section.
- Assign the value “1” to the variable “day” in the constructor initialization section.
- Define the parameterized constructor of class “DayOfYear”.
- Assign parameter values to the variables “month” and “day” in the constructor initialization section.
- Call the “checkDate()” function to check the date is valid.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write down code that can declare a class of an employee with the properties, name and salary, and the methods, getSalary and getName, that return the salary and name of the employee respectively. Function members should be declared as prototypes only andinclude a parameterised constructor prototype to initialise with the name and salary.
Hi can you assist me on the problem below for a class and a test class that conforms to the following specifications: 1. The name of the class is RightTriangle 2. The class has member variables base and height 3. The class has a constructor that initializes base and height 4. The class has accessors and mutators for base and height 5. The class has a toString method that produces String representation of a RightTriangle like the following example for a triangle with base 12 and height 10. Base : 12 Height 10 6. The class has a method called findArea to compute the area of the right triangle. Here is a suggested implementation. public double findArea() { return 0.5* this.base*this.height; } 7. The class using proper naming conventions
Write a test class called RightTriangleTest that conforms to the following: 1. Create an object with base = 10 and height = 20, for example myTriangle. 2. To print the toString for myTriangle. 3. To print the area of myTriangle. System.out.println(“The…
Can you implement the Derived Class Parameterized constructor? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first.
Implement the constructor Dell(String name) of the Derived Class Dell which takes a string, name. We have already implemented the Base Class Laptop with the member function getName() and a parameterized constructor.
Input#
Laptop name is being passed through the parameterized constructor.
Output#
getName() method is returing Laptop name.
Sample Input#
Dell dell = new Dell("Dell Inspiron");
Sample Output# "Dell Inspiron"
Chapter 10 Solutions
Problem Solving with C++, Student Value Edition
Ch. 10.1 - Given the following structure and structure...Ch. 10.1 - Consider the following type definition: struct...Ch. 10.1 - What is the error in the following structure...Ch. 10.1 - Given the following struct definition: struct A {...Ch. 10.1 - Here is an initialization of a structure type....Ch. 10.1 - Write a definition for a structure type for...Ch. 10.1 - Prob. 7STECh. 10.1 - Prob. 8STECh. 10.1 - Give the structure definition for a type named...Ch. 10.1 - Declare a variable of type StockRecord (given in...
Ch. 10.2 - Below we have redefined the class DayOfYear from...Ch. 10.2 - Given the following class definition, write an...Ch. 10.2 - Prob. 13STECh. 10.2 - The private member function DayOfYear::checkDate...Ch. 10.2 - Suppose your program contains the following class...Ch. 10.2 - Suppose you change Self-Test Exercise 15 so that...Ch. 10.2 - Explain what public: and private: do in a class...Ch. 10.2 - a. How many public: sections are required in a...Ch. 10.2 - Give a definition for the function with the...Ch. 10.2 - Give a definition for the function with the...Ch. 10.2 - Give a definition for the function with the...Ch. 10.2 - Suppose your program contains the following class...Ch. 10.2 - How would you change the definition of the class...Ch. 10.2 - Prob. 24STECh. 10.3 - When you define an ADT as a C++ class, should you...Ch. 10.3 - When you define an ADT as a C++ class, what items...Ch. 10.3 - Suppose your friend defines an ADT as a C++ class...Ch. 10.3 - Redo the three- and two-parameter constructors in...Ch. 10.4 - How does inheritance support code reuse and make...Ch. 10.4 - Can a derived class directly access by name a...Ch. 10.4 - Suppose the class SportsCar is a derived class of...Ch. 10 - Solution to Practice Program 10.1 Redefine...Ch. 10 - Redo your definition of the class CDAccount from...Ch. 10 - Define a class for a type called CounterType. An...Ch. 10 - Write a grading program for a class with the...Ch. 10 - Redo Programming Project 1 (or do it for the first...Ch. 10 - Define a class called Month that is an abstract...Ch. 10 - Redefine the implementation of the class Month...Ch. 10 - My mother always took a little red counter to the...Ch. 10 - Write a rational number class. This problem will...Ch. 10 - Define a class called Odometer that will be used...Ch. 10 - Redo Programming Project 7 from Chapter 5 (or do...Ch. 10 - The U.S. Postal Service printed a bar code on...Ch. 10 - Consider a class Movie that contains information...
Knowledge Booster
Similar questions
- This chapter uses the class rectangleType to illustrate how to overload the operators +, *, ==, !=, >>, and <<. In this exercise, first redefine the class rectangleType by declaring the instance variables as protected and then overload additional operators as defined in parts 1 to 3. Overload the pre- and post-increment and decrement operators to increment and decrement, respectively, the length and width of a rectangle by one unit. (Note that after decrementing the length and width, they must be positive.) Overload the binary operator – to subtract the dimensions of one rectangle from the corresponding dimensions of another rectangle. If the resulting dimensions are not positive, output an appropriate message and do not perform the operation. The operators == and != are overloaded by considering the lengths and widths of rectangles. Redefine the functions to overload the relational operator by considering the areas of rectangles as follows: Two rectangles are the…arrow_forwardWrite a program to model a student class with roll number and name as the sensitive information. Initialize default values for the sensitive information using a default constructor, use a copy constructor to copy from another object, use a member function to take user input and update the name and roll number and display the same using another member function. b.Add constructor overloading to the above code and enable initialization of name, roll number via constructor arguments. NAME ROHI ROLLNO 18arrow_forwardCan you call a constructor from another constructor? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first. Problem Statement# A class can have multiple parameterized constructors which can call each other. You are given a partially completed code of a Car class in the editor. Modify the parametrized constructor which assigns parameters to the required fields. Input# carName, carModel, carCapacity Output# carName, carModel, carCapacity Sample Input# "Ferrari", "F8", "100" Sample Output# "Ferrari", "F8", "100" Part of solution // Car class class Car { // Private Fields private String carName; private String carModel; private String carCapacity; // Default Constructor public Car() { this.carName = ""; this.carModel = ""; this.carCapacity = ""; } // Parameterized Constructor 1 public Car(String name, String model) { this.carName = name; this.carModel = model; } // Parameterized Constructor 2 public…arrow_forward
- Consider a class BankAccount that has • Two attributes i.e. accountID and balance and• A function named balanceInquiry() to get information about the current amount in the account Derive two classes from the BankAccount class i.e. CurrentAccount and the SavingsAccount. Both classes (CurrentAccount and SavingsAccount) inherit all attributes/behaviors from the BankAccount class. In addition, followings are required to be the part of both classes• Appropriate constructors to initialize data fields of base class• A function named amountWithdrawn(amount) to withdraw certain amount while taken into account the following conditionso While withdrawing from current account, the minimum balance should not decrease Rs. 5000o While withdrawing from savings account, the minimum balance should not decrease Rs. 10,000• amountDeposit(amount) to deposit amount in the accountIn the main() function, create instances of derived classes (i.e. CurrentAccount and SavingsAccount) and invoke their respective…arrow_forwardConsider the following class implementation, which represents a price in dollars and cents: class Price { private: int dollars; int cents; public: Price() { dollars = cents = 0; } Price(int d, int c) { dollars = d; cents = c; } bool operator!=(Price); bool operator<(Price); }; Write an implementation for both overloaded operators. != should return true if the Prices are not equivalent, and should return false if they are equivalent. < should return true if the Price of the calling object (left object) is less than the parameter Price object (right object). You do not need to demonstrate calling these operators.arrow_forwardQ2: Consider the following statements: public class YClass { private int a; private int b; public void one() { } public void two(int x, int y); { } public YClass() { } } class XClass extends YClass { private int z; public void one() { } public XClass() { } } YClass yObject; XClass xObject; Write the definition of the default constructor of YClass so that the instance variables of YClass are initialized to 0. Write the definition of the default constructor of XClass so that the instance variables of XClass are initialized to 0. Write the definition of the method two of YClass so that the instance variable a is initialized to the value of the first parameter of two and the instance variable b is initialized to the value of the second parameter of two. please I want solution :(arrow_forward
- Make class Student, you need to add the normal constructor with parameters not default with 5 attributes age, gender, ID full name, date of registration JAVAarrow_forwardCreate a program that has the following classes: Point - Just like in the lecture, with attributes x and y set to 0 by default. Circle - Contains two attributes, center and radius. center is of type Point defined above (initialize a Point instance for this), while radius is set to 0 by default. The program must have the function point_in_circle(c, p) where c is a Circle and p is a Point. The function returns True if the point is within the circle, and False otherwise. You may use the math module (and nothing else) if necessary. You may also create other functions that can help you code the main function much easier. Example usage # Initialize a circle with center at (0, 0) and radius 1 (unit circle). c = Circle() c.center.x, c.center.y, c.radius = 0, 0, 1 # Initialize a point located at (1, 1) p = Point() p.x, p.y = 1, 1 # This returns False since (1, 1) is outside the circle point_in_circle(c, p)arrow_forwardConsider the following code snippet. 1. /* 2. * The Student class models a student with a name, age 3. * and a faculty in which is currently enrolled in. 4. */ 5. public class Student 6. { 7. // private instance variable, not accessible from outside this class 8. private String firstName; 9. private String lastName; 10. private int birthYear; 11. private String faculty; 12. 13. // The constructor with the. correspondent parameters. 14. public Student(String first, String last, int birthYear, String faculty) 15. { 16. this.firstName= first; 17. this.lastName = last; 18. this.birthYear = birthYear; 19. this.faculty = faculty; 20. } 21. } 1. Implement an accessor method that returns the age of the student given as parameter the current year. 2. Implement a new method called printDetails, taking the currentYear as a parameter, that prints the full name, age and faculty of the student in the following way: Full name: Donald Duck Age: 24 years Faculty:…arrow_forward
- Consider the following class Date, which represents a date using three ints for month, day and year: class Date { private: int month; int day; int year; public: Date() { month = day = year = 0; } Date(int m, int d, int y) { month = m; day = d; year = y; } bool operator==(Date); bool operator<(Date); }; Write an implementation for both overloaded operators. == should return true if the Date objects are equivalent and false if not. < should return true if the Date of the calling object (left object) comes before the parameter Date object (right object) and false if not. You may assume that all objects of class Date are valid, i.e. month is between 1 and 12, inclusive; day contains an appropriate day for the given month, and year can be anything. You do not need to demonstrate calling these operators.arrow_forwardThis chapter uses the class rectangleType to illustrate how to overload the operators +, *, ==, !=, >>, and <<. In this exercise, first redefine the class rectangleTypeby declaring the instance variables as protected and then overload additional operators as defined in parts 1 to 3. Overload the pre- and post-increment and decrement operators to increment and decrement, respectively, the length and width of a rectangle by one unit. (Note that after decrementing the length and width, they must be positive.) Overload the binary operator – to subtract the dimensions of one rectangle from the corresponding dimensions of another rectangle. If the resulting dimensions are not positive, output an appropriate message and do not perform the operation. The operators == and != are overloaded by considering the lengths and widths of rectangles. Redefine the functions to overload the relational operator by considering the areas of rectangles as follows: Two rectangles are the…arrow_forwardWhat is the role of a normal constructor? Create the class Student, which must have a normalconstructor and at least 5 attributesarrow_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 Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning