Introduction to Programming Dev C++

Introduction to Programming Dev C++

 

Assignment No.  3 Semester: Spring 2021 CS201 – Introduction to Programming



Recommended tool to develop Assignment

-          Dev C++

 

Objectives:

To enable students to understand and practice the concepts of:

  • Classes and its structure.
  • Data Members and Member functions of the class.
  • Constructor of the class.

Problem Statement:

 

Suppose an XYZ company hires you as a C++ developer and assigns you the task of developing a scientific calculator (program) for the user. The program has to be developed in such a way that it should display the following menu to the user.

 

 

Ø  For option ‘1’ the program should set the radius of the circle, calculate its area, circumference and display it on the screen.

Ø  For option ‘2’ the program should set the width and height of the rectangle, calculate its area and display it on screen.

Ø  For any option other than 1, and 2 the program should display invalid output.

Ø  After performing any of the above operations the program should also ask the user if he/she wants to carry out the same operation again.

 

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:

Introduction to Programming
Introduction to Programming


#include <iostream>

using namespace std;

#define PI 3.14159265


class circle 

{

private:

double radius 

public:

woid setRadius ();

woid computeAreaCirc();

circle();

-circle();  

};


circle: :Circle()

{

redius - 0.0;

 } 

 

void circle::setRadius()

{

redius - 5.6;

}


void circle::computeAreaCirc()

{

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

cout << "circunference of circle is: " << 2 * PI * redius << endl;

}


circle::-circle()

{

}

class Rectangle

Private:

double length;

double with;

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()

{

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 of the rectangle" << endl;

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

cin >> option;

if(option -- "1")

{

circle ncircle;

ncircle.setredius();

ncircle.comuteAreaCirc();

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

cin >> choice;

if(choice == "Y" !! choice == "Y")

{

continue;

}

{

else

{

break;

}

}

else if (option == "2")

{

rectangle nRectangle.setlength;

nRectangle.setlength();

nRectangle.setwidth();

nRectangle.computeArea();

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

cin >> Choice;

if(choice == "Y" !! choice == "Y")

{

continue;

}

else

{

breck;

}

}

else

{

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

}

}

}



Post a Comment

1 Comments

  1. I've read you artcle and i found it very useful, but you've to create you blog on wordpress, I know a very reputed web development company in your town you should contact them.

    ReplyDelete