CS304 Assignment No 3 Solution fall 2017 | Virtual Study Solutions

Adsetra Ads

 

CS304 Assignment No 3 fall 2017

Dear Students, Here you can read or Download CS304 - object oriented programming Assignment No 3 Solution and Discussion of Semester Fall 2017. CS304 Assignment Solution has been added. Assignment Due Date is 15 January, 2017. Total Marks are 20. We are here to facilitate your learning and we do not appreciate the idea of copying or replicating solutions. Previously we shared CS304 Assignment No 2 Solution Fall 2017.

CS304 Assignment No 3 Solution fall 2017
CS304 Assignment No 3 Solution fall 2017

CS304 Assignment 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.
Please 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


Recommended : CS304 Solved MCQs with Reference

CS304 Assignment Objective

The objective of CS304 Assignment No 3 is:
  • To give you the idea of practical implementation of Inheritance in CPP.

CS304 Assignment 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.
CS304 Assignment Figure: UML for METRO Cash & Carry Pakistan
 Figure: UML for METRO Cash & Carry Pakistan

CS304 Assignment Tasks

  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.

CS304 Assignment No 3 Solution fall 2017

You can see the sample Solution file page preview below. and You can easily Download CS304 Assignment Solution File from the Download Button given below:

Solution Idea :

Please Note : Its just a solution idea if you find any mistakes Please Correct it Yourself or Share with us in comments. Solution file will be added Soon.

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


class Item
{
 
private:
int barcode;
char *item_name;

public:


Item(int code=0,char *name= "not given"): barcode(code) 
{
 item_name=new char[strlen(name)+1];
 strcpy(item_name,name);
 
}

setcode(int code)
{barcode=code; 
}

int getcode()
{return barcode;
}


void scanner(int x)
{
if(x=barcode) 
cout<<"\n code is matched item is ="<<item_name;
else
cout<<"\n code is not matched item is ="<<item_name;
}

printer()
{
if(barcode!=0)
cout<<"\n code="<<barcode<<"\tItem name is ="<<item_name; 
else
cout<<"\n code="<<barcode<<"\t\tItem name is ="<<item_name;

}

~Item()
{delete []item_name;

}

};

class PackedFood: public Item
{
 private:
 int price_per_piece;
 public:
 
PackedFood(int p=0,int c=0,char *n="not given"):price_per_piece(p),Item(c,n)
{
}



int getprice(void) 
{return price_per_piece;} 

setprice(int x)
{price_per_piece=x;}

void scanner(int x)
 {
  Item::scanner(x);
  cout<<"\t price per item="<<price_per_piece;
 }

void printer(void) 
 {
   Item::printer();
   cout<<"\t price per item="<<price_per_piece;
 }
};
class FreshFood: public Item
{
private:
int weight;
int price_per_ruppe;


public:
FreshFood(int w=0,int p=0,int c=0,char *n="not given"):weight(w),price_per_ruppe(p),Item(c,n)
{
}


setweight(int x)
{weight+x;
}


int getweight(void)
{return weight;
}

printer()
{Item::printer();
cout<<"\t price per weight="<<price_per_ruppe*weight; 
}
scanner(int x)
{Item::scanner(x);
cout<<"\t price per weight="<<price_per_ruppe*weight;
}

};


int main()

{
Item a(37,"Iron");
PackedFood c(23,34,"bulb"); 
FreshFood e(10,20,30,"carrot");
 
a.printer(); 
c.printer(); 
e.printer(); 
 
 
 cout<<endl;
 
 
Item b;
PackedFood d;
FreshFood f;

b.printer();
d.printer();
f.printer();


 return 0;
 
 
}

CS304 Assignment Solution Download Link


Download  [ Solution File will be added Soon ]

If Assignment Solution provided by (Virtual Study Solutions) was helpful. Please Share it with your friends. You can also like our Facebook Page or Subscribe Us below for Updates. Thank You.

Post a Comment

  1. kindly send me the cs 304 cpp and step for execution @ gulamdastagir09@gmail.com

    ReplyDelete
  2. Hi Friends i have a complete code
    https://youtu.be/CNnwZ_OmgTs

    ReplyDelete

 

Top