Consider the definition of the class product Type as given in Exercise 8.
Answer the following questions. (1, 2, 3, 5, 7)
Write the definition of the function set so that instance variables are set according to the paramaters. Instance variables quantitieslnStock, price, and discount must be nonnegative.
Write the definition of the function print to output the values of the instance variables.
Write the definition of the function setQuantitiesInStock to set the value of the instance variable quantitiesInStock according to the parameter.
Write the definition of the function updateQuantitiesInStock to update the value of instance variable quantitiesInStock by adding the value of the parameter.
Write the definition of the function getQuantitiesInStock to return the value of instance variable quantitiesInStock.
Write the definition of the function setPrice to set the value of the instance variable price according to the parameter.
Write the definition of the function getPrice to return the value of the instance variable price.
Write the definition of the function setDiscount to set the value of the instance variable discount according to the parameter.
Write the definition of the function getDiscount to return the value of the instance variable discount.
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
C++ Programming: From Problem Analysis to Program Design
- Consider the definition of the class product Type as given in Exercise 8. Which function members are accessors and which are mutators? (4)arrow_forwardUse the definition of the class productType to answer the questions a,b,c,d, and e pictured below. *class productType is also pictured below *Everything is in C++arrow_forwardRedo Programming Exercise 3 by overloading the operators as nonmembers of the class boxType. Write a test program that tests various operations on the class boxType. Reference: Chapter 11 defined the class boxType by extending the definition of the class rectangleType. In this exercise, derive the class boxType from the class rectangleType, defined in Exercise 1, add the functions to overload the operators +,–, *, ==, !=, <=, <, >=, >, and pre- and post-increment and decrement operators as members of the class boxType. Also overload the operators << and >>. Overload the relational operators by considering the volume of the boxes. For example, two boxes are the same if they have the same volume. Write the definitions of the functions of the class boxType as defined above and then write a test program that tests various operations on the class.arrow_forward
- I need the answer as soon as possiblearrow_forwardExplain the question in a very simple way Example 3: Student Grades (Returning a List of Objects from Function) create a class Student, with attributes name, and grade.We will return students who have a grade above a specified threshold using a function. class Student: def __init__(self, name, grade): self.name = name self.grade = grade def high achievers(students, min_grade): return (student for student in students if student.grade > min_grade] students = [ Student("Alice", 85), Student("Bob", 76), Student("Charlie", 92), Student("Diana", 88) • Output: top_students = high achievers(students, 80) for student in top_students: print(f"Student: (student.name}, Grade: (student.grade}") 27/04/1446 • Student: Alice, Grade: 89 Student: Charlie, Grade • Student: Diana, Gradearrow_forwardCreate a class Test with two private integer data members: x and y and one member function: getdata() for taking input of x and y. Create two non-member friend functions: task1() and task2() to class Test, such as task1() is displaying squares of integers from 1 to x and task2() is finding the sum of all integers from 1 to y. in c++ onlyarrow_forward
- 1. Short questions: a. What is the difference between having a function return type being "const dataType &" and it being "dataType&"? b. When is it necessary to make a function or a class a friend of another class? c. List all who can access: the private member of a class protected member of a class public member of a class d. What is difference between static data and a regular data of a class?arrow_forwardSolve This ASAParrow_forwardneed help in c++ code screenshot and outputarrow_forward
- Write a C++ code for the following question as quickly as you can. But please do the same as asked in the Question...arrow_forwardGiven the Class Definition for ClockType discussed extensively in class, write what would have to be added to the IMPLEMENTATION FILE for the Class ClockType to overload the “= =”, i.e., the comparison “equal-equal sign,” here: That is, write the FULL FUNCTION DEFINITION for THE FUNCTION associated with Class ClockType to overload the “= =” remembering the private members are: b) int hr; // that contains the hours int min; // that contains the minutes int sec; // that contains the secondsarrow_forwardI'm confused about this question. Any help is appreciated!arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr