Assignment No. 04 Semester: Fall 2012 CS201: Introduction to Programming

No Comments


Assignment No. 04
Semester: Fall 2012
CS201: Introduction to Programming


Total Marks: 20
Due Date:28/01/2013


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 submitted assignment does not open or file is corrupt.
§  Assignment is copied(partial or full) from any source (websites, forums, students, etc)

Note: You have to upload only .cpp file. Assignment in any other format (extension) will not be accepted and will be awarded with zero marks. For example, if you submit code in .doc (Word document) or .txt files, no reward will be given in any case.



Objective:

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

§  Objects and Classes
§  Constructors and Destructors in classes
§  Setters and Getters in classes
§  Use of friend functions
§  Operator overloading


Guidelines:

§  Code should be properly indented and well commented.
§  Follow C/C++ rules while writing variable names, function names etc
§  Use only dev-C++ for this assignment.


Problem Statement:     You are required to write a program for calculating area of Trapezoid. Formula for calculating area of trapezoid is



Where a and b are two bases of trapezoid and h corresponds to height.


Detailed Description:

  • Create a class named Trapezoid which contains two bases and height as data members.
  • Implement a default constructor to initialize all data members with zero and a parameterized constructor which takes three arguments to initialize data members of class.
  • Take input from user for base1, base2 and height of 2 objects.
  • Overload + operator for the class Trapezoid in such a way that corresponding elements of both objects of the same class can be added.
  • Also implement a friend function named calculateArea() which takes two objects of the class Trapezoid as arguments, adds both objects using overloaded + operator and calculates the area of resultant Trapezoid object.
Sample output:

 
 


 


 
Next PostNewer Post Previous PostOlder Post Home

0 comments

Post a Comment