EBK DATA STRUCTURES AND ALGORITHMS IN C
4th Edition
ISBN: 9781285415017
Author: DROZDEK
Publisher: YUZU
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 1, Problem 10E
Program Plan Intro
Class template declaration and function definition:
The general syntax of a generic class declaration is shown below:
Syntax:
template<class type> class class-name
{
return type function(arguments);
}
The function declaration syntax is shown below:
Syntax:
return type class-name<type>::function(arguments)
{
};
Here, “type” denotes the placeholder type name, which will be specified when a class is instantiated. A comma-separated list could be used to define more than one generic data type. Here, the return type of function is stated in beginning, followed by class name, template class “type name” and finally the name of function.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
. Write a class definition that creates a class called leverage with one private data member, crowbar, of type int and one public function whose declaration is void pry(). Write a member function called getcrow(). This function should return the value of the crowbar data. Assume the function is defined within the class definition.
Opp Java
In C++
The base class Pet has private data members petName, and petAge. The derived class Dog extends the Pet class and includes a private data member for dogBreed. Complete main() to:
create a generic pet and print information using PrintInfo().
create a Dog pet, use PrintInfo() to print information, and add a statement to print the dog's breed using the GetBreed() function.
Ex. If the input is:
Dobby2Kreacher3German Schnauzer
the output is:
Pet Information: Name: Dobby Age: 2Pet Information: Name: Kreacher Age: 3 Breed: German Schnauzer
hm help
Part 1: Implement a Place class as specified:data members:name - name of the Place (dynamic variable)functions:Place(): default constructor set name to “TBD”Place(string): one argument constructor set nameaccessor - an accessor for the name variablemutator - an mutator for the name variablePart 2: Implement the big three for Place class.Part 3: An operator overload >> function for Place class.An operator overload << function for Place class.Use following main() to test your class.int main() {// part 1Place a1,a2("Bookstore");cout<<"a1: "<<a1.getName()<<endl; // print "a1: TBD"a1.setName("Supermarket");cout<<"a1: "<<a1.getName()<<endl; // print "a1: Supermarket"cout<<"a2: "<<a2.getName()<<endl; // print "a2: Bookstore"// part 2Place b1("Bookstore");cout<<"b1: "<<b1.getName()<<endl; // print "b1: Bookstore"Place b2(b1),b3;cout<<"b2: "<<b2.getName()<<endl; // print "b2:…
Chapter 1 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
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
- Each member-function definition outside its corresponding class template definitionmust begin with template and the same template parameters as its class template T/Farrow_forwardc++ Build the ShoppingCart class with the following specifications. Note: Some can be function stubs (empty functions) initially, to be completed in later steps. Default constructor Parameterized constructor which takes the customer name and date as parameters Private data members string _customerName - Initialized in default constructor to "none" string _currentDate - Initialized in default constructor to "January 1, 2016" vector < ItemToPurchase > _cartItems Public member functions customerName() accessor date() accessor addItem() Adds an item to cart items vector. Has a parameter of type ItemToPurchase. Does not return anything. removeItem() Removes item from cart items vector. Has a parameter of type string (an item's name). Does not return anything. If item name cannot be found, output this message: Item not found in cart. Nothing removed. modifyItem() Modifies an item's description, price, and/or quantity. Has a parameter of type ItemToPurchase. Does not return…arrow_forwardAssume a class named Dollars exists. Write the headers for member functions that overload the prefix and postfix ++ operators for that class.arrow_forward
- What is the difference between a friend function of a class and a member function of a class? (3)arrow_forwardAssume the definition of class foodType as given in Exercise 6. Answer the following questions? (1, 2, 3, 5, 6) Write the definition of the member function set so that private members are set according to the parameters. The values of the int and double instance variables must be nonnegative. Write the definition of the member function print that prints the values of the data members. Write the definitions of the member functions getName, getcalories, getFat, getSugar, getCarbohydrate, getPotassium to return the values of the instance variable. Write the definition of the default constructor of the class foodType so that the private member variables are initialized to 0, 0. 0, 0, 0. 0, 0. 0, respectively. Write the definition of the constructor with parameters of the class foodType so that the private member variables are initialized according to the parameters. The values of the int and double instance variables must be nonnegative. Write a C + + statement that prints the value of the object fruit 2. Write a C++ statement that declares an object my Fruit of type foodType, and initializes the member variables of myFruit to Apple, 52, 0. 2, 10,13.8, and 148.0, respectively.arrow_forward. Write a class definition that creates a class called leverage with one private data member, crowbar, of type int and one public function whose declaration is void pry(). Write a member function called getcrow(). This function should return the value of the crowbar data. Assume the function is defined within the class definition.arrow_forward
- writte in c++ Write a Circle class that has the following member variables: • radius : a double • pi : a double initialized with the value 3.14159 The class should have the following member functions: • Default Constructor. A default constructor that sets radius to 0.0. • Constructor. Accepts the radius of the circle as an argument. • setRadius. A mutator function for the radius variable. • getRadius. An accessor function for the radius variable. • getArea. Returns the area of the circle, which is calculated as area = pi * radius * radius • getCircumference. Returns the circumference of the circle, which is calculated as circumference = 2 * pi * radiusarrow_forwardIn C++ Design a class named QuadraticEquation for a quadratic equation . The class contains: Data fields: a, b, and c that represents three coefficients. A default constructor A constructor for the arguments for a, b, and c. Three get functions for a, b, and c. Three set function for a, b and c. A function named getDiscriminant() that returns the discriminant, which is . Two member functions named getRoot1() and getRoot2() for returning two roots of the equation and These functions are useful only if the discriminant is non-negative. Let these functions return 0 if the discriminant is negative. Implement the class. Write a test program that prompts the user to enter values for , , and , and displays the result based on the discriminant. If the discriminant is positive, display the two roots. If the discriminant is 0, display the one root. Otherwise, display “The equation has no roots”.arrow_forwardWhen a pointer to a base class is made to point to a derived class, the pointer ignoresany __________ the derived class performs, unless the function is __________.arrow_forward
- 1) In C++, it asks to define a new class Fighter that inherits from the Spaceship class below. - Add a private member variable: int firePower; - Create a default constructor which initializes firePower to 10 and initializes name to "X-wing" - Create a member function in Fighter void warp(). This function should increase position by 10, and decrease health by 5. - Redefine function wasHit(). Instead of decrementing health by 5, decrement it by 2. COde: class Spaceship { protected: string name; int health; int position; public: Spaceship() { name = ""; health = 100; position = 0; } void moveLeft() { position--; } void moveRight() { position++; } void wasHit() { health -= 5; } };arrow_forwardA nonmember function must be declared as a(n)_________ of a class to have access tothat class’s private data members.arrow_forwardDescribe how to redefine the member functions of a base class.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
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