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
In C++   class film { public:     void setFilmDirector(string s); //sets the filmTitle to  s     void setFilmYear(string year);        //sets the private member filmYear to year     void setFilmProdCost(double cost);        //sets the private member filmProdCost to cost     void setFilmGenre (string type);        //sets the private member filmGenre to type     void printAllFilmInfo() const;        //prints the filmDirector, filmYear, the filmProdCost and the filmGenre     string geFilmGenre() const;        //returns the filmGenre     string getFilmYear() const;        //returns the filmYear     double getFilmProdCost() const;        //returns the filmProdCost     void updateFilmProdCost(double cost); //adds cost to the filmProdCost, so that the filmProdCost now has it original value plus the //parameter sent to this function private:     string filmDirector;     string filmYear;     double filmProdCost;     string filmGenre; };   Assume the following in your main program (the…
class Player {   protected:    string name;    double weight;    double height;   public:    Player(string n, double w, double h)      { name = n; weight = w; height = h; }    string getName() const      { return name; }    virtual void printStats() const = 0; };   class BasketballPlayer : public Player {   private:    int fieldgoals;    int attempts;   public:    BasketballPlayer(string n, double w,     double h, int fg, int a) : Player(n, w, h)      { fieldgoals = fg; attempts = a; }    void printStats() const      { cout << name << endl;         cout << "Weight: " << weight;         cout << " Height: " << height << endl;        cout << "FG: " << fieldgoals;        cout << " attempts: " << attempts;        cout << " Pct: " << (double) fieldgoals / attempts << endl; } }; a. What does = 0 after function printStats() do? b. Would the following line in main() compile: Player p; -- why or why not? c. Could…
Library Information System Design and Testing Library Item Class Design and TestingDesign a class that holds the Library Item Information, with item name, author, publisher. Write appropriate accessor and mutator methods. Also, write a tester program(Console and GUI Program) that creates three instances/objects of the Library Items class.   Extending Library Item Class Library and Book Classes: Extend the Library Item class in (1) with a Book class with data attributes for a book’s title, author, publisher and an additional attributes as number of pages, and a Boolean data attribute indicating whether there is both hard copy as well as eBook version of the book. Demonstrate Book Class in a Tester Program (Console and GUI Program) with an object of Book class.
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
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
    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
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