CS201 Assignment 3 Solution 2021 - VU Answer

CS201 Assignment 3 Solution Spring 2021

In This Post, Provide CS201 Assignment 3 Solution Spring 2021. Complete Step by Step CS201 Assignment 3 Solution 2021. Easy to Download Assignment Solution File Give Below in .cpp, Word, and PDF File.

CS201 ASSIGNMENT 3 SOLUTION SPRING 2021 

Provide by VU Answer


Assignment Objective

To enable students to understand and practice the concepts of:

  • Classes and their structure.

  • Data Members and Member functions of the class.

  • The constructor of the class.

Code result screenshot is given below


Solution Code:

#include <iostream>

using namespace std;

#define PI 3.14159265


class Circle


{

private:

double radius;

public:

void setRadius(); 

void computeAreaCirc();

Circle();

~Circle();

};


Circle::Circle()

{

radius = 0.0;

}


void Circle::setRadius()

{

radius = 5.6;

}


void Circle::computeAreaCirc()

{

cout << "Area of circle is: " << PI * (radius * radius) << endl;

cout << "Circumference of circle is: " << 2 * PI * radius << endl;


}


Circle::~Circle()

{

}

class Rectangle

{

private:

double length; 

double width;

public:

void setLength(); 

void setWidth();

void computeArea();

Rectangle();

~Rectangle();

};


Rectangle::Rectangle()

{

length = 0.0;

width = 0.0;

}


void Rectangle::setLength()

{

length = 5.0;

}


void Rectangle::setWidth()

{

width = 4.0;

}


void Rectangle::computeArea()

{

cout << "Area of Rectangle: " << length * width << endl;

}


Rectangle::~Rectangle()

{

}


main()

{

cout<<"********************SCIENTIFIC CALCULATOR********************"<<endl;

cout<<""<<endl;

int run = 1;

string option, choice;

while(run)

{

cout << "\nOPTION 1 for computing Area and Circumference of the circle" << endl;

cout << "OPTION 2 for computing Area of the Rectangle" << endl;

cout << "Select your desired option(1-2): ";

// Provided by VUAnswer.com

cin >> option;

if(option == "1")

{

Circle nCircle;

nCircle.setRadius();

nCircle.computeAreaCirc();

cout << "Do you want to perform anyother calculation(Y/N):";

cin >> choice;

if(choice == "Y" || choice == "y")

{

continue;

}

else

{

break;

}

}

else if(option == "2")

{

Rectangle nRectangle;

nRectangle.setLength();

nRectangle.setWidth();

nRectangle.computeArea();

cout << "Do you want to perform anyother calculation(Y/N):";

cin >> choice;

if(choice == "Y" || choice == "y")

{

continue;

}

else

{

break;

}

}

else

{

cout << "Invalid Option!, Option should be from (1-2)" << endl;

}

}

}



CODE RESULT


CS201 Assignment 3 2021 Solution



DOWNLOAD CPP SOLUTION  FILE

DOWNLOAD MS WORD SOLUTION FILE


DOWNLOAD PDF SOLUTION FILE





Post a Comment

0 Comments