C++ Programming: From Problem Analysis to Program Design
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN: 9781337102087
Author: D. S. Malik
Publisher: Cengage Learning
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 10, Problem 8SA

Consider the definition of the following class: (1, 2, 3, 5, 7)

classproductType                                    //Line 1 {                                                             //Line 2 public:                                                   //Line 3 productType();                                      //Line 4 productType ( int, double, double ) ;       //Line 5 productType(string, int, double, double);//Line 6 productType(string, string, string, int, double, double);                                //Line 7 voidset(string, string, string, int, double, double);                                       //Line 8 voidprint()const;                                     //Line 9 voidsetQuantitiesInStock(intx);              //Line 10

void updateQuantitiesInStock (int x);                 //Line11 int getQuantitiesInStock () const;                       //Line12 void setPrice (doublex);                                   //Line13 doublegetPrice()const;                                   //Line14 voidsetDiscount(doubled);                            //Line15 doublegetDiscount()const;                           //Line16 private:                                                        //Line17 string productName;                                   //Line18 string id;                                                     //Line19 string manufacturer;                                  //Line20 int quantitiesInStock;                                //Line21 double price;                                             //Line22 double discount;                                        //Line23 };                                                               //Line24

  1. Give the line number containing the constructor that is executed in each of the following declarations.

    i . productType productl; ii . productType product2 ( "Microwave" , "M3562", "GeneralPool", 35, 175 .00, 0 .1); iii . productType product3  ( "D1290", 25, 375 .00, 0 .05 ) ; iv . productType product4 ( 10, 8 .50, 0 .2 ) ;

  2. Write the definition of the constructor in Line 4 so that the instance variables are initialized to “ “, “ “, “ “, 0, 0.0, and 0.0, respectively.

  3. Write the definition of the constructor in Line 5 so that the string instance variables are initialized to””, and the other instance variables are initialized according to the parameters. Instance variables quantitieslnStock, price, and discount must be nonnegative.

  4. Write the definition of the constructor in Line 6 so that the instance variables productName and manufacturer are initialized to the empty string, instance variable id is initialized according to the first parameter, and the remaining instance variables are initialized according to the last three parameters. Instance variables quantitieslnStock, price, and discount must be nonnegative.

  5. Write the definition of the constructor in Line 7 so that the instance variables are initialized according to the parameters. Instance variables quantitieslnStock, price, and discount must be nonnegative.

Blurred answer
Students have asked these similar questions
Create an abstract class Product  with following  Properties Price (Decimal), Code (string), Description (string) Create an interface ISellable with the following Method sell that takes the count of the products to sell and returns the cost   public decimal sell(int count); Create a concrete class Book that  Inherits from class Product and implements interface ISellable Has additional Property Author (string) Add a constructor with parameters, and ToString method to display all of data of class Book Similarly, create anot concrete class Software that  Inherits from class Product and implements interface ISellable Has additional Property Version (string) Add a constructor with parameters, and ToString method to display all of data of the class Software Finally, write a client code (main program) that will utilize the class and interface hierarchy you created. Create two Book objects for the following books C# 8.0 in a Nutshell, with price $50.99 and with ISBN…
Person and Customer Classes Write a class named (Person) with data attributes for a person’s name, address, and telephone number. Provide accessors/getters and mutators/setters for each attribute. Write a displayPerson() to print out the attributes of the Person.  Next, write a class named (Customer) that is a subclass of the (Person) class. The (Customer) class should have a data attribute for a customer number, and a Boolean data attribute indicating whether the customer wishes to be on a mailing list. Provide accessors/getters and mutators/setters for each attribute. Write a display customer() to print out the attributes of the Customer. Demonstrate an instance of the (Customer) class in a simple program.
In java Create an abstract super class called Employee with the following attributes: name : String and the following methods getter and setter for the one attribute three constructors an abstract method called getSalary()  equals() toString()   Create a sub class of Employee called Faculty with the following attribute yearlyPay : double department: String and the following methods getter and setter for the  attributes three constructors getSalary() that returns the yearlyPay divided by 52 equals() toString() Create a sub class of Employee called Staff with the following attributes: hoursWorked : double payrate : double and the following methods getters and setters for the two attributes three constructors getSalary() that returns the weekly pay (multiply hoursWorked by payrate, overtime included and 1.5 times payrate for hours > 40) equals() toString()   Create a sub class of Employee called Sales with the following attributes: salesAmount : double //sales per week…
Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
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