Latest Activity In Study Groups

Join Your Study Groups

VU Past Papers, MCQs and More

We non-commercial site working hard since 2009 to facilitate learning Read More. We can't keep up without your support. Donate.


 

Assignment No. 4
Semester: Fall 2010

CS201: Introduction to Programming 

Total Marks: 20

 

Due Date: 24th Jan, 2011

 

Instructions:

Please read the following instructions carefully before submitting your assignment:

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 or file is corrupt.

 

All types of plagiarism are strictly prohibited.

 

Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted. If you will submit code any other file format like .doc or .txt etc. you will get zero marks.

 

Objective

The objective of this assignment is to provide hands on experience of using

 

§         Classes and objects manipulation in c++

§         Operators overloading

 

Guidelines

§         Code should be properly aligned and well commented.

§         Follow C/C++ rules while writing variables names, function names etc.

§         Use only Dev-C++ IDE for this assignment.

 

Assignment

 

 

Problem Statement: Price manipulation

 

You are required to create a class in C++ named Price with the following Data members, Data members should be publicly declared.

 

  • Rupees
  • Paisas

 

The Price class presents Price in Rupees and Paisa. For instance, Price (10, 80) means 10 rupees and 80 paisas. The Price class should have the following features as described in detailed descriptions:

 

Detailed Description:

Constructors

 

Class Price must have

 

  • Default constructor, which must set Rupees and Paisas to zero.

 

  • Parameterized constructor that receives two parameters of type int and initializes its private data: Rupees and Paisas with them. Note that if Paisas are 100 or greater than 100 then also convert it in Rupees.

Member Functions

  • Create a function named Print()that displays the price of object in terms of rupees and paisas.

Operator overloading

  • A member function that overloads the + Operator to add two objects of Price.

 

There should be an overloaded + operators:

 

  • Add two objects and return Price object. Note that Paisas should not exceed 100.
  • Add first number into second objects and return Price object. Note that paisas should not exceed 100.

 

 

Output of your program should be as follows:

 

Price is 10 rupees and 60 paisas

 

Price is 12 rupees and 80 paisas

 

After Addition

 

Price is 23 rupees and 40 paisas

 

 

 

Note: you have to use same Class and Function name as mentioned in the assignment details. If we find any deviation, marks will be deducted.

 

Deadline:

Your Assignment solution must be submitted on or before January 24th, 2011.

 





Only CPP file will be accepted, file other than CPP will be awarded zero (0) marks.

 

Views: 564

Attachments:

Replies to This Discussion

any one ?

 

CHANGE LAYOUT A LITTLE CODE IF YOU CAN AND COMMENT AS YOU LIKE ALSO CHANGE VARIABLE'S NAMES SO IT WILL LOOK DIFFERENT FROM MINE.

 

#include <iostream.h>
#include <conio.h>
class Price{
private:
int RS;
private:
int PS;
public:
Price();
Price(int,int);
void Print();
Price operator + (Price);};
void Price::Print(){
cout"Price Is " RS " Rupees And " PS " Paisas" endl;}
Price::Price(){RS = 0;PS = 0;}
Price::Price(int Rupee , int Paisa){RS = Rupee;PS  = Paisa;}
Price Price::operator + (Price PRICE_ONE){
Price PRICE_TWO;
const int unit = 100;
if (PRICE_ONE.PS + PS >= unit && (PRICE_ONE.PS + PS) % unit == 0){
PRICE_TWO.RS = (PRICE_ONE.RS  + RS) + (PRICE_ONE.PS + PS) / unit;}
else if (PRICE_ONE.PS + PS >= unit && (PRICE_ONE.PS + PS) % unit != 0){
PRICE_TWO.RS = (PRICE_ONE.RS  + RS) + (PRICE_ONE.PS + PS) / unit;PRICE_TWO.PS  = (PRICE_ONE.PS + PS) % unit;}
else if (PRICE_ONE.PS + PS < unit){
PRICE_TWO.RS = (PRICE_ONE.RS  + RS);PRICE_TWO.PS = (PRICE_ONE.PS + PS);}
return PRICE_TWO;}
int main(){
clrscr();
Price add_obj;
Price obj1(16,57);
Price obj2(28,72);
obj1.Print();
obj2.Print();
coutendl;
cout"After Addtion Of Two Objects"endl;
add_obj = obj1 + obj2;
add_obj.Print();
getch();
return 0;}

can any one share 4th solu?

RSS

© 2021   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service