VU Projects Video Lectures Handouts Past Papers Quizzes Assignments & GDB border= Members Free SMS Service FB Page
VU Projects Video Lectures Handouts Past Papers Quizzes Assignment,GDB Members SMS Service FB Page

Instructions:

Please read the following instructions carefully before submitting assignment:

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

  • The assignment is submitted after due date.
  • The assignment is submitted via email.
  • The assignment is copied from Internet or from any other student.
  • The submitted assignment does not open or file is corrupt.
  • It is in some format other than .cpp.

Note: You are supposed to submit your assignment in .cpp format. Any other formats like scan images, PDF, zip, doc, rar and bmp etc will not be accepted. All types of plagiarism are strictly prohibited.

For any query about the assignment, contact at CS304@vu.edu.pk

Objective

The objective of this assignment is:

  • To give you the idea of practical implementation of Inheritance in CPP.

 

Problem Statement:

Suppose METRO Cash & Carry Pakistan has given you a task to develop an automatic checkout system in C++. All items are identifiable by means of a merchandise computer code (barcode) and the item name. Groceries are either sold in packs or by weight. Packed items have fixed prices. The price of groceries sold by weight is calculated by multiplying the weight by the current price per kilogram. As a software developer your task is to develop the classes needed to represent the products first and organize them hierarchically according to the UML diagram given on next page.

 

 

 

                                                            

                                                                               Items

Properties:

Bar code

Item Name

 

Methods:

setbarCode()

getbarCode()

...

scanner()

printer()

 

 

 

 

 

 

 

 

 

                                       PackedFood                                                                                             FreshFood

 

Properties:

Price per piece

 

Methods:

getPrice()

setPrice()

...

scanner()

printer()  

Properties:

Weight

Price per rupee

 

Methods:

setWght()

getWght()

...

scanner()

printer()

 

 

 

 

 

 

 

 

 

Figure: UML for METRO Cash & Carry Pakistan

 

 

 

 

Tasks for you:

  1. Make a base class named Item then define its private and public members. Define a constructor with parameters for both data members (Barcode, Item Name). You should add default values for the parameters to provide a default constructor for the class. In addition to the access methods setCode() and getCode(), you are also required to define the methods scanner() and printer(). These methods will simply output item data on screen or read the data of an item from the keyboard.
  2. Define two derived classes PackedFood and FreshFood. In addition to the Item class data, the PackedFood class should contain the unit price. The FreshFood class should contain a weight and a price per kilogram as data members. You are required to define a constructor with parameters providing default-values for all data members in both classes. Also define the access methods needed for the new data members.
  3. Make the main() function then test the classes in it, that creates two objects each of the types Item, PackedFood and FreshFood. One object of each type should be fully initialized in the object definition. You can use the default constructor to create the other object. The get() and set() methods and the scanner() method should be well written and the printer() method should display the items on screen.

Views: 2134

Attachments:

Replies to This Discussion

cs304 Assignment no.3 solution plz


#include<iostream>
#include<string>
using namespace std;

class Item
{
long  int barcode;
string item_name;

  public:
  Item()
  {
  barcode =0;
  item_name = " ";
  }
  Item( int k)
  {
  barcode = k;
  }
int  setbarcode()
{
cout"Enter the barcode =    :: ";
     cin >> barcode;
     return 0;
}
int getbarcode()
{
return barcode;
}
     void scanner ()
     {
     cout "Enter the item name =   :: ";
     cin.ignore();
     getline(cin,item_name);
     }
     void printer()
     {
cout "\nThe name of item is  =  ::    "item_nameendl;
     }
};

class Packedfood:public Item
{
int price_per_piece;
int quantity;

  public:

Packedfood() :Item()
{
    price_per_piece=0;
    quantity = 0;
}
  Packedfood( int x ) :Item( x )
{ }
 
  void setprice()
  {
  cout "\n\nEnter the price =   ::     ";
  cin >> price_per_piece;
  cout "\nEnter the quantity =     ::    ";
  cin >> quantity;
  }
  int getprice()
  {
  return price_per_piece;
  }
 
  void printer()
  {
  cout "The price per item is =      " price_per_piece;
  cout "\n The quantity is =      "quantity;
  cout "\nThe total price of this item is =        " price_per_piece * quantity;
  }
 
};

class Freshfood :public Item

{
private:
double weight;
double price_per_kilo;
public:
Freshfood () :Item()
{ }
Freshfood( int y ) :Item( y )
{ }
void setweight()
{
cout "Enter the weight in Grams "endl;
cin >> weight;
}
void setprice()
{
cout "Enter the price per kilo"endl;
cin >> price_per_kilo;
}
void printer()
{
cout"\nThe weight of an item is =  "weight" Grams";
cout "\nThe price per kilo is =  "price_per_kilo" Rupees";
cout"\nThe total price of this item is  =   " (weight * price_per_kilo)/1000" Rupees";
}
};

int main()
{
cout "********************************************"endl;
cout "***** Matro Cash and carry in pakistan ***** "endl;
cout "********************************************"endlendl;

Item *p,i1,i2(0);
Packedfood p1,p2(123456789);
   Freshfood f1,f2(987654321);
   

i1.setbarcode();
    if( i1.getbarcode() == p2.getbarcode() )
    {
    cout"\n\n";
    p = &p1;
    p1.scanner();
    p1.setprice();
    p->printer();
        p1.printer();
   

    }
    else if( i1.getbarcode() == f2.getbarcode())
{
cout"\n\n";
p = &f1;
f1.scanner();
    f1.setprice();
    f1.setweight();
        p->printer();
        f1.printer();
}
else if(i1.getbarcode() != p2.getbarcode() != i1.getbarcode() != f2.getbarcode())
cout"********* barcode not matched *********";


else if (i1.getbarcode() != p2.getbarcode() && i1.getbarcode()  != f2.getbarcode())
cout " ******Get Correct Barcode****** ";



return 0;
}

 

here is the link for complete assignment

https://youtu.be/O9xE5ndWtCo

it is complete but try yourself also as instructor surrly know that you copy it that affect your assignment marking 

Solution 

Attachments:

RSS

© 2018   Created by Muhammad Anwar Tahseen.   Powered by

Badges  |  Report an Issue  |  Terms of Service

-->