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_forward16. Assume the declaration of Exercise 14. (Each of these have { and } and will be on their own lines.) A. Write the definition of the default constructor of smart so that the instance variables of smart are initialized to 0. B. Write the definition of the default constructor of superSmart so that the instance variables of superSmart are initialized to 0. C. Write the definition of the mermber function set of smart so that the instance variables are initialized according to the parameters. D. Write the definition of the member function sum of the class smart so that it returns the sum of the instance variables. E. Write the definition of the member function manipulate of the class superSmart so that it returns the (x + y)? , that is, return x plus y to the power of z.arrow_forwardWeek One: Introduction to Object oriented Programming Course overview. Reading: Key Differences between Procedural Programming and Object-Oriented Programming (OOP). Chapter One Assignment: Write C++ code to implement void and return type functions. The code should contain more than one function. Use the implemented code to investigate the possibility of the following by indicating them as valid or invalid 1- Returning (directly or indirectly) values using void function. 2- Returning (directly or indirectly) multiple values. 3- Passing an Array to a function. 4- Implementing more than one function with same name. 5- Controlling access to functions. 6- Declaring a variable with multiple data types simultaneously.arrow_forward
- Help me with C++ please: 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 member variables. Add a member function, isLeapYear, to check whether a year is a leap year. Moreover, write a test program to test your class. Input should be format month day year with each separated by a space. Output should resemble the following: Date #: month-day-year An example of the program is shown below: Date 1: 3-15-2008 this is a leap year There are 3 tabs: dateType.h, dateTypelmp.cpp, main.cpp dateType.h: #ifndef date_H #define date_H class dateType { public: void setDate(int month, int day, int year); //Function to set the date. //The member variables dMonth, dDay, and dYear are set //according to the parameters //Postcondition: dMonth = month; dDay = day; // dYear = year int getDay() const; //Function to return the day.…arrow_forward1. 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_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. Fill in the blanks for Questions 1 & 2 a. Instance of a class is called b. functions have same name but different sets of parameters. of arguments in a function call must match c. Number, the parameters in function parameter list and d. functions are defined once and can be used for different data Тypes. 2. Most important attributes of OOP (Object Oriented Programming) are: _ , that is creating new classes from an existing base class. when a program calls a virtual function using base class b. pointers or references to use the same function with different forms/structures.arrow_forwardWrite a student class that will keep track of the grades of students and generates a final mark. •You should store three quiz marks, each out of a total of 20 marks, one midterm score out of a total of 50 marks, one final project out of 100 and an overall score with a letter grade associated with it. Further, create the respected accessor and mutator methods necessary. •The function calculateOverallScore() should calculate the weight as follows; quizzes are 15% total, midterm is 35% total and final is worth 50% for a total of 100% when summed up. •The function finalLetterGrade() should return the letter based off the following: 100-90 A, 90-80 B, 70-80 C, 60-70 D, 0 – 60 F •When complete create a student object, set the marks for quizzes/midterm/final and print the letter and final grade to the console.arrow_forwardDefine Function evaluateExpression.arrow_forward
- Given 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_forwardResearch assistants provide support to professionals who are conducting experiments or gathering andanalyzing information and data. Suppose you are working as RA (research assistant) with a Professor who isworking on a project and evaluating complex mathematical equations. Your duty is to assist him, so in thisregard he has assigned a task to you. Your task is to write a oop c++ program to create a class named equation which will have the data members a, b and c which are the coefficients of the quadratic equation. The class will have two more data members namely proot and nroot which stand for the positive root and negative root of the equation. Suppose that variables a, b and c are integers. Where proot and nroot are floats. Input Function to get values of a, b and c Then design a friend function which will determine the proot and nroot of the equation. Create another friend function which will display the values of proot and nroot.arrow_forwardInstructionsDefine an enumeration type triangleType that has the values scalene, isosceles, equilateral, and noTriangle.Write a function triangleShape that takes as parameters three numbers, each of which represents the length of a side of the triangle. The function should return the shape of the triangle. (Note: In a triangle, the sum of the lengths of any two sides is greater than the length of the third side.)Write a program that prompts the user to input the length of the sides of a triangle and outputs the shape of the triangle.arrow_forward
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning