Share:
Notifications
Clear all

[Solved] CS304 Assignment 3 Spring 2020  

  RSS

talhaofficial0
(@talhaofficial0)
Moderator
Joined: 1 year ago
Posts: 25
30/07/2020 5:14 am  
 

Assignment No. 03

Semester: Spring 2020

CS304- Object Oriented Programme

Total Marks: 20

Due Date: 6th August 2020  

Objective

The objective of this assignment is:

To give you the idea of practical implementation of C++ Inheritance and Polymorphism.

 

Uploading instructions:

  • Your assignment should be in .CPP format (Any other formats like scan images, PDF, zip, doc, rar and bmp etc. will not be accepted).
  • Save your assignment with your ID (e.g. bc000000000.CPP).
  • No assignment will be accepted through email.

Rules for Marking:

It should be clear that your assignment will not get any credit if:

·         The assignment is submitted after due date.

·         The submitted assignment does not open, execute or file is corrupted.

·         Your assignment is copied from internet, handouts or from any other student.

      (Strict disciplinary action will be taken in this case).

 

Lectures Covered:

This assignment covers Lecture # 22-29.

Assignment No. 03

 

A public sector university has its bookstores throughout the country from where students can buy study material like handouts, lecture DVDs, books etc. Each bookstore maintains the stock data of study material. This data is helpful for the university to maintain information about quantity, price and other data of each item available at different bookstores.  Keeping in view the above scenario,  you are required to write a C++ program that should contain three classes: StockItem, Handouts and Lecture_DVD, where StockItem should be base class and Handouts and Lecture_DVD should be its derived classes.

You are required to use concept of Polymorphism to generate the sample output. The detail of data members and member functions for each class is provided in the given table.

Class

Data Members

Member Functions

StockItem

  • Name of Item
  • Quantity of Item
  • Price of Item
  • Course_Code
  • Course_Name

 

  • Default Constructor
  • Setter functions to set values of data members of this class.
  • Getter functions to get the values of data members of this class.
  • A function to set data of a stock item
  • A function to display data of a stock item

Handouts

  • No_Pages
  • Author
  • Default Constructor
  • A function to set data of handouts
  • A function to display data of handouts.

Lecture_DVD

  • Total minutes
  • Total Lectures
  • Default Constructor
  • A function to set data of DVD.
  • A function to display data of DVD.

Solution Guidelines:

  • You have to use concept of Polymorphism to generate the sample output.

 

Sample Output:

NOTE:  Do not put any query on MDB about this assignment, if you have any query then email at [email protected].  Furthermore, if any student found cheating from any other student or from online forums then he/she will be awarded ZERO right away and strict disciplinary action will be taken against the student.

Deadline: Your assignment must be uploaded/submitted on or before  6th August 2020

       
This topic was modified 1 week ago by admin

Quote
admin
(@admin)
Admin
Joined: 2 years ago
Posts: 3608
04/08/2020 2:01 pm  

CS304 Assignment 3 Solution idea:

Credit: Muhammad Aaqib Saleem

 

#include

#include

using namespace std;




// Stock item class

class StockItem

{

      protected :

           // data members of StockItem class

           string item_name;

           int quantity;

           int price;

           string course_code;

           string course_name;

     

      public :

           // Default Constructor

           StockItem()

            {

                 item_name="";

                 quantity=0;

                 price=0;

                 course_code="";

                 course_name="";

           }

           //Setter functions

           void set_Item_name(string n)

           {

                 item_name=n;

           }

           void set_quantity(int q)

           {

                 quantity=q;

           }

           void set_price(int p)

           {

                 price=p;

            }

           void set_course_code(string c)

           {

                 course_code=c;

           }

           void set_course_name(string nm)

           {

                 course_name=nm;

           }

           //Getter functions

           string get_item_name()

           {

                 return item_name;

           }

           int get_quantity()

           {

                 return quantity;

           }

           int get_price()

           {

                 return price;

           }

           string get_course_code()

           {

                 return course_code;

           }

           string get_course_name()

           {

                 return course_name;

           }

          

           // virtual function for set stock items

           virtual void set_stock()

           {

                 cout<<"Enter Data for Stock";

                 cout<<"nEnter Item Name : ";

                 cin>>item_name;

                 cout<<"Enter Item Quantity : ";

                 cin>>quantity;

                 cout<<"Enter Item Price : ";

                 cin>>price;

                 cout<<"Enter Course Name : ";

                 cin>>course_name;

                 cout<<"Enter Course Code : ";

                 cin>>course_code;

           }

          

           // virtual function for display stock items

           virtual void display_stock()

           {

                 cout<<"nItem Name : "<<item_name;

                 cout<<"nCourse Name : "<<course_name;

                 cout<<"nCourse Code : "<<course_code;

                 cout<<"nQuantity : "<<quantity;

                 cout<<"nPrice : "<<price; 

           }    

};




// Handout class inherited from Stock Item class

class Handouts : public StockItem

{

      private :

           //data members of Handouts class

           int no_pages;

           string author;

      public :

           //default constructor of Handouts class

           Handouts() : StockItem ()

           {

                 no_pages=0;

                 author="";

           }

           //overriding set_stock function for Handouts class

           virtual void set_stock()

           {

                 cout<<"nEnter following Data for Handouts Items";

                 cout<<"nEnter Item Name : ";

                 cin>>item_name;

                 cout<<"Enter Item Quantity : ";

                 cin>>quantity;

                 cout<<"Enter Item Price : ";

                 cin>>price;

                 cout<<"Enter Course Name : ";

                 cin.ignore();

                 getline(cin, course_name);

                 cout<<"Enter Course Code : ";

                 cin>>course_code;

                 cout<<"Enter Pages : ";

                 cin>>no_pages;

                 cout<<"Enter Author : ";

                 cin>>author;

           }

           //overriding display_stock function for Handouts class

           virtual void display_stock()

           {

                 cout<<"nDisplaying Book Information";

                 cout<<"n----------------------------------";

                 cout<<"nItem Name : "<<get_item_name();

                 cout<<"nCourse Name : "<<course_name;

                 cout<<"nCourse Code : "<<course_code;

                 cout<<"nHandouts Quantity : "<<quantity;

                 cout<<"nHandouts Price : "<<price;

                 cout<<"nHandouts Pages : "<<no_pages;

                 cout<<"nHandouts Author : "<<author;     

           }

};




//Lecture_DVD class inherited from Stock Item class

class Lecture_DVD : public StockItem

{

      private :

           //data members of Lecture_DVD class

           int total_minutes;

           int total_lectures;

      public :

           // defualt constructor of Lecture_DVD class

           Lecture_DVD() : StockItem ()

           {

                 total_minutes=0;

                 total_lectures=0;

           }

           //overriding set_stock function for Lecture_DVD class

           virtual void set_stock()

           {

                 cout<<"nEnter Data following Data for Lecture DVD";

                 cout<<"nEnter Item Name : ";

                 cin>>item_name;

                 cout<<"Enter Item Quantity : ";

                 cin>>quantity;

                 cout<<"Enter Item Price : ";

                 cin>>price;

                 cout<<"Enter Course Name : ";

                 cin.ignore();

                 getline(cin, course_name);

                 cout<<"Enter Course Code : ";

                 cin>>course_code;

                 cout<<"Enter Minutes : ";

                 cin>>total_minutes;

                 cout<<"Enter Lectures : ";

                 cin>>total_lectures;

           }

           //overriding display_stock function for Lecture_DVD class

           virtual void display_stock()

           {

                 cout<<"nnDisplaying Lecture DVD Information";

                 cout<<"n----------------------------------";

                 cout<<"nItem Name : "<<item_name;

                 cout<<"nCourse Name : "<<course_name;

                 cout<<"nCourse Code : "<<course_code;

                 cout<<"nQuantity : "<<quantity;

                 cout<<"nPrice : "<<price;

                 cout<<"nMinutes : "<<total_minutes;

                 cout<<"nLectures : "<<total_lectures;     

           }

};

//main function

main()

{

      //variable declaration

      int items=0;

      char choice;

      char d;

      int i=0;

      //prompt user for items

      cout<<"nHow many items you want to enter? : ";

      cin>>items;

      //declare array of objects as user enter number of items

      StockItem* stock[items];

     

      do

      {

      again:

           //prompt user for item choice

           cout<<"Enter choice: H for Handouts, L for lecture DVD : ";

           cin>>choice;

           if(choice=='H' || choice =='h')

           {

                 // initialize object

                 stock[i]=new Handouts();

                 //set stock items

                 stock[i]->set_stock();

                 i++;

           }

           else if(choice=='L' || choice =='l')

           {

                 // initialize object

                 stock[i]=new Lecture_DVD();

                 //set stock items

                 stock[i]->set_stock();

                 i++;

           }

           else

           {

                 cout<<"nSorry Invalid Choice , Try Againn";

                 goto again;

           }

           //prompt user for another item entry

           cout<<"Do you want to enter more data (Y for yes, N for No) : ";

           cin>>d;

      }while((d=='Y'|| d=='y') && i<items);

      //display stock detail

      for(int j=0; j<i; j++)

      {

           stock[j]->display_stock();

      }

}
This post was modified 11 hours ago by talhaofficial0

How is this website, please share your feedback through this link: https://forms.gle/mZ5rsd995RxU2gEZ7
---------------------
WhatsApp Groups Subject wise #QueryVU
Join Now


ReplyQuote
Share: