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
Write a FancyCar class to support basic operations such as drive, add gas, honk horn, and start engine. FancyCar.java is provided with method stubs. Follow each step to gradually complete all methods. Note: This program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress. The main() method includes basic method calls. Add statements in main() as methods are completed to support development mode testing. Step 0. Declare private fields for miles driven as shown on the odometer (int), gallons of gas in tank (double), miles per gallon or MPG (double), driving capacity (double), and car model (String). Note the provided final variable indicates the gas tank capacity of 14.0 gallons. Step 1 (2 pts). 1) Complete the default constructor by initializing the odometer to five miles, tank is full of gas, miles per gallon is 24.0, and the model is "Old Clunker". 2)…
Find the error: daily_sales = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0] days_of_week = ['Sunday', 'Monday', 'Tuesday',                     'Wednesday', 'Thursday', 'Friday',                     'Saturday'] for i in range(7):         daily_sales[i] = float(input('Enter the sales for ' \                                      + day_of_week[i] + ': ')
Find the error: daily_sales = [0.0, 0,0, 0.0, 0.0, 0.0, 0.0, 0.0] days_of_week = ['Sunday', 'Monday', 'Tuesday',                     'Wednesday', 'Thursday', 'Friday',                     'Saturday'] for i in range(7):         daily_sales[i] = float(input('Enter the sales for ' \                                      + days_of_week[i] + ': ')
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
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Text book image
Systems Architecture
Computer Science
ISBN:9781305080195
Author:Stephen D. Burd
Publisher:Cengage Learning
Text book image
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