CS201 Assignment 3 Solution Spring 2021 100% complete Solution Guideline | Circle, Rectangle Classes

CS201 Assignment 3 Solution Spring 2021 100% complete Solution Guideline - Circle, Rectangle Classes

CS201 Assignment 3 Solution Spring 2021 100% complete Solution Guideline | Circle, Rectangle Classes examples with following problem statement. Here is complete code with an example of Circle and Rectangle classes how to define classes in separate files in C++ and how to class these classes to create objects in any other program to access their data members and member functions.

Example | CS201 Assignment 3 Spring 2021

To achieve the above task you first need to create three separate classes Circle and Rectangle. The description of each class should be as follows:

Circle class will have ‘radius as its data member and setRadius(), computeAreaCirc() as itsmember functions. The setRadius() function willset the value of its data member ‘radius’ in the main function. The computeAreaCirc() member function will compute and display the area and circumference of the circle class.

Rectangle class will have ‘height’, ‘width’ as its data members and setLength(), setWidth() and computeArea() as its member functions. The setLength(), setWidth() willset the value of its data member ‘height’ and ‘width’ in the main function. The computeArea() function will compute and display area of the rectangle class.

You also need to create constructor of each class which will initialize its data members with default values.

For consistency of the assignment, source data of the class data members should be set as follows:

RADIUS = 5.6

LENGTH = 5.0

WIDTH = 4.0

Note: Marks will be deducted if the source data of the class is varied from the above data.

Sample Screenshot of Output:

If the user selects option ‘1’.

If the user selects option ‘2’

If the user selects any other option.

After completing the calculations the program should prompt the user to perform the calculation again Y/N:

If the user does not want to perform any calculation. The program should terminate successfully.

Rectangle Class

#include<iostream>
using namespace std;

class Rectangle{
	
	private: 
	
		float height;
		float width;
	public:
		
		void setLength(float h){
			height =h;
		} 
		
		void setWidth(float w){
			width =w;
		} 
		
		void computeArea(){
			
			float area = 0.0;
			area = width * height;
			cout<<"Arear of Rectangle : "<<area;
				}		
	
		
};

Circle Class

include

using namespace std;

class Circle{

    private:
    float radius;


public:
    void setRadius(float r){
        radius=r;
    }   

    void computeAreaCirc(){
        float area=0.0;
        float circ=0.0;

        circ= 2*3.14*radius;
        area= 3.14*radius*radius;

        cout<<"Area of circle is : "<<area<<endl;
        cout<<"Circumference of Circle is : "<<circ;


    }

};

C++ program with Main Function

Watch the Video to find the third and main program to use these classes and output

Author: Habibullah Qamar

Its me Habib Ullah Qamar working as a Lecturer (Computer Sciences) in Pakistan. I have an MS(M.Phil) degree in computer sciences with specialization in software engineering from Virtual University of Pakistan Lahore. I have an experience of more than 15 years in the filed of Computer Science as a teacher. Blog Writing is my passion. I have many blogs, This one is special made with the aim of providing 100% Free online coaching and training to the students of under-graduate and postgraduate classes. Most of the students enrolled in computer sciences, information technology, software engineering and related disciplines find it difficult to understand core concepts of programming and office automation. They find difficult in understanding and solving their assignments.