Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (9th Edition)
9th Edition
ISBN: 9780133862218
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 11.4, Problem 25STE
The following is the first line of the copy constructor definition for the class StringVar. The identifier StringVar occurs three times and means something slightly different each time. What does it mean in each of the three cases?
StringVar::StringVar(const StringVar& stringObject) |
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Given the following class, I need help writing a constructor that initializes all instance variables using appropriate parameters.
I need to make sure it enforces the preconditions
public class BrowserTab {private String title;private int id;/*** Creates a BrowserTab* @precondition title != null && id >= 0*/}
JAVA PROGRAM
For this program, you are tasked to implement the Beverage class which has the following private properties:
name - a string value
volume - this is an integer number which represents its current remaining volume in mL
isChilled - this is a boolean field which is set to true if the drink is chilled
It should have the following methods:
isEmpty() - returns true if the volume is already 0
{toString() - returns the details of the object in the following format: {name} ({volume}mL) {"is still chilled" | "is not chilled anymore"}.Example returned strings:
Beer (249mL) is still chilled
Water (500mL) is not chilled anymore
A constructor method with the following signature: public Beverage(name, volume, isChilled)
Getter methods for all the 3 properties.
Then, create two final subclasses that inherit from this Beverage class. The first one is the Water class which has the additional private property, type, which is a String and can only be either "Purified", "Regular",…
In this exercise, you have to calculate the student's total marks using the concept of Classes
Problem Statement# Write a Java class called Student with
● private fields:
○ name(String type)
○ mark1 and mark2 (double type)
And methods:
● getMarks(int markNumber), a method which should return mark1 if markNumber equals 1 and mark2 otherwise.
● calcTotal() method should take the two marks entered and return their sum. Also define two constructors:
● A default constructor that takes no parameters and initializes the values to zeros and null.
● A constructor that takes the three variables and sets them as the values of the appropriate fields.
Input#
Name of the student and the marks obtained in the first and second tests
Output#
Sum of both marks
Sample Input#
Student student = new Student("Jack", 60, 70);
Sample Output# getMarks(1) => 60 getMarks(2) => 70 calcTotal() => 130.0
Part of solution
class Student {
// Define private fields here
public Student() {
// Write…
Chapter 11 Solutions
Problem Solving with C++ plus MyProgrammingLab with Pearson eText-- Access Card Package (9th Edition)
Ch. 11.1 - Write a function definition for a function called...Ch. 11.1 - What is the difference between a friend function...Ch. 11.1 - Suppose you wish to add a friend function to the...Ch. 11.1 - Prob. 4STECh. 11.1 - Notice the member function output in the class...Ch. 11.1 - Notice the definition of the member function input...Ch. 11.1 - The Pitfall section entitled Leading Zeros in...Ch. 11.1 - Give the complete definition of the member...Ch. 11.1 - Why would it be incorrect to add the modifier...Ch. 11.1 - What are the differences and the similarities...
Ch. 11.1 - Given the following definitions: const int x = 17;...Ch. 11.2 - What is the difference between a (binary) operator...Ch. 11.2 - Prob. 13STECh. 11.2 - Suppose you wish to overload the operator = so...Ch. 11.2 - Prob. 15STECh. 11.2 - Give the definition for the constructor discussed...Ch. 11.2 - Here is a definition of a class called Pairs....Ch. 11.2 - Following is the definition for a class called...Ch. 11.3 - Give a type definition for a structure called...Ch. 11.3 - Write a program that reads in five amounts of...Ch. 11.3 - Change the class TemperatureList given in Display...Ch. 11.3 - Prob. 22STECh. 11.3 - If a class is named MyClass and it has a...Ch. 11.4 - Prob. 24STECh. 11.4 - The following is the first line of the copy...Ch. 11.4 - Answer these questions about destructors. a. What...Ch. 11.4 - a. Explain carefully why no overloaded assignment...Ch. 11 - Modify the definition of the class Money shown in...Ch. 11 - Self-Test Exercise 17 asked you to overload the...Ch. 11 - Self-Test Exercise 18 asked you to overload the...Ch. 11 - Prob. 1PPCh. 11 - Define a class for rational numbers. A rational...Ch. 11 - Define a class for complex numbers. A complex...Ch. 11 - Enhance the definition of the class StringVar...Ch. 11 - Define a class called List that can hold a list of...Ch. 11 - Define a class called StringSet that will be used...Ch. 11 - This programming project requires you to complete...Ch. 11 - Redo Programming Project 6 from Chapter 9 (or do...Ch. 11 - Solution to Programming Project 11.12 To combat...Ch. 11 - Repeat Programming Project 11 from Chapter 10 but...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Bond Yield One measure of a bond's performance is its Yield To Maturity (YTM). YTM values for government bonds ...
Introduction To Programming Using Visual Basic (11th Edition)
Explain the problems that denormalized tables may have for insert, update, and delete actions.
Database Concepts (7th Edition)
When the operator's left operand is a list and its right operand is an integer, the operator becomes this. a. ...
Starting Out with Python (4th Edition)
(Geometry: rightmost lowest point) In computational geometry, often you need to find the rightmost lowest point...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Suppose the memory cells at addresses 0x00 through 0x09 in the Vole contain the following bit patterns: Address...
Computer Science: An Overview (12th Edition)
List the five major hardware components of a computer system.
Starting Out with Java: From Control Structures through Objects (6th Edition)
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- To what class does the following constructor belong? public Student(String name)arrow_forward******* In java ***** create a class , and objects for the following exercise 1- for car car - make -yearModel + setMake() + setYearModel() + getMake() + getYearModel() 2- for cellphone cellPhone - manufact : String - model : String - retailPrice : double + setManufact(man : String) : void + setModel(mod : String) : void + setRetailPrice( price : double) : viod + getManufact() : String + getModel() : String + getRetailPrice() : doublearrow_forwardIn the class definition, initialize the private fields owner (string), rating (integer), and state (string) with the default values "Unstated", -1, and "Undefined", respectively. Ex: If the input is Ken 4 NY, then the output is: Default values: Name: Unstated's Food Truck, Rating: -1, State: Undefined After mutator methods: Name: Ken's Food Truck, Rating: 4, State: NY Note: The class's print() method is called before and after the input is passed to the setters. Eatery.java public class Eatery { private /* Your code goes here */ private/* Your code goes here */ private/* Your code goes here */ publicvoidsetOwner(StringeateryOwner) { owner=eateryOwner; } publicvoidsetRating(inteateryRating) { rating=eateryRating; } publicvoidsetState(StringeateryState) { state=eateryState; } publicvoidprint() { System.out.println("Name: "+owner+"'s Food Truck, Rating: "+rating+", State: "+state); } }arrow_forward
- Create a class MyTime which has the datamembers as follows: 1. hour: integer (1 to 12)2. minute: integer (0 to 59)3. second: integer (0 to 59)4. pm: bool variable. True means PM time and false means AM time. Implement a default constructor, a parameterized constructor and a copy constructor. Write set and get functions for all the four members of the class. Overload these operators: 1. Extraction operator >> : Prompt the user for hours, minutes, seconds and for am/pm and initialize the structure. Left operand istream object and right operand MyTime2. Assignment = : Assign the right object to the left object. Both operands are of type MyTime.3. Insertion << : Print the time in the format HH:MM SS PM. Left operand of type ostream and right operand of type MyTime. this in c++.arrow_forwardThe goal of this coding exercise is to create two classes BookstoreBook and LibraryBook. Both classes have these attributes: author: Stringtiltle: Stringisbn : String- The BookstoreBook has an additional data member to store the price of the book, and whether the book is on sale or not. If a bookstore book is on sale, we need to add the reduction percentage (like 20% off...etc). For a LibraryBook, we add the call number (that tells you where the book is in the library) as a string. The call number is automatically generated by the following procedure:The call number is a string with the format xx.yyy.c, where xx is the floor number that is randomly assigned (our library has 99 floors), yyy are the first three letters of the author’s name (we assume that all names are at least three letters long), and c is the last character of the isbn.- In each of the classes, add the setters, the getters, at least three constructors (of your choosing) and override the toString method (see samplerun…arrow_forwardFrom the below given code, Add default and parameterized constructor for the given data fields and write down the instantiation statement that invokes both constructor. Illustrate the use of this. class person { int reg; string name; int age; …….. public static void main(string [] args) { …..arrow_forward
- Write a Java class named PhoneRecord.java that performs the following functions: The class should contain the following data attributes and methods: private String name - The customer's name private String number - The customer's phone number public PhoneRecord(String personName, String phoneNumber) - Constructor get/set Methods - For each data attribute public String toString( ) - Special method to be used when printing a phoneRecord object Thank you so much for your help. Trying to write this class has really been stumping me.arrow_forwardGiven below is the code for the controlling class with constructor overloading, analyse the code and write the Java code for the class program with all details. Make your assumptions wherever needed. public class DriverClass { public static void main( String[] args ) { Number N1 = new Number (2,3,5); Number N2 = new Number (2.5,3.5,5,5); Number N3 = new Number (2,3); N1.displayAverage(); N2.displayAverage(); N3.displayAverage(); } }arrow_forwardCreate a class Fraction with two integer final fields: numeratorand denominator. Its constructor creates fractions when given valuesfor both, but it has to avoid fractions with null denominators by throwing aNullDenominatorExceptionarrow_forward
- Change the following case in a way that it randomly moves down and eat/drink something only if it's present. Give the output screenshot import random#Dog Classclass Dog: #constructor def __init__(self, name): self.name = name def eat(self): print("{} is eating.".format(self.name)) def drink(self): print("{} is drinking.".format(self.name))# The Blind-Dog class inherits from the Dog classclass BlindDog(Dog): def __init__(self, name, hunger=0, thirst=0): super().__init__(name) self.hunger = hunger self.thirst = thirst # The Blind-Dog can only feel what's in his location def feel(self, environment): if environment == "food": return True elif environment == "water": return True else: return False # The Blind-Dog is hungry and needs to search for food def search_for_food(self): if self.feel("food"): print("I found food!") self.eat() else: print("There is no food around.") # The Blind-Dog is thirsty and needs to search for water def search_for_water(self): if…arrow_forwardIn blue J add a no argument constructor for the constructor of the code below: public class Book{ private String author; private String title; private int pages; private String publisher; //String for phone number because it is too big a number to store in int or long private String phone; //constructor public Book () { } public Book(String author, String title, int pages, String publisher, String phone) { this.author = author; this.title = title; this.pages = pages; this.publisher = publisher; this.phone = phone; } //getters and setters public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public int getPages() { return pages; } public void setPages(int…arrow_forwardWrite a java application that contain the following classes A) Pizza class that contains the following 1- private Data fields - Size (e.g. small, medium, and Large) - price (e.g. small (10 CAD), medium (12 CAD), and Large (15 CAD)) - number of Pizzas 2- public Methods: - Two constructors - Setters and Getters (setters should check that in put is valid) - total that returns the total price (users buying three pizzas or more gets 15% discount) - to string method B) Main class that contains main method Inside the main method - Create Array of Pizza objects - Display the array on Console.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY