Question

Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve...

Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve breaking the problem down into multiple classes that can be tied together into a single solution. In this project, you are given the task of writing some classes that would work together for providing a solution to a problem involving some basic computations. Learning Objectives The focus of this assignment is on the following learning objectives:

• Be able to identify the contents of class declaration header and class definition files and to segregate class functionality based on class description

• Be able to write object creation and initialization code in the form of constructors • Be able to implement an encapsulated approach while dealing with data members for the classes involved through accessors and mutators

• Be able to make the program code spread across multiple files work together for the solution to the computing problem Prerequisites To complete this project, you need to make sure that you have the following:

• C++ and the g++ compiler • A C++ IDE or text editor (multiple editors exist for developers) • An understanding of the material presented in class.

• An understanding of the material covered in zyBooks.

Problem Description You are to implement the necessary classes and program for creating a test program for reporting important parameters of some two-dimensional geometric shapes. For this project, you will need to utilize the concepts of classes and top-down design that has been discussed in class. The list of requirements and constraints for the system are as follows: 1. At the heart of the solution will be a test program shapetest.cpp (using all the classes specified below) that will test the full functionality of the classes required as part of this project. The shapes that the program would be considering will be a circle, a triangle and a rectangle. The program will call all functionality for each shape and print out the resultant object state to allow for visual inspection that the class is implemented correctly. For example, a Circle should be created with the default constructor, then its area, diameter, and circumference printed to the screen for verification that it has the correct state and those respective methods work correctly. Then, output of the state should be repeated after calling each mutator to ensure that the object’s new state reflects the change (note, there’s only one mutator for the circle).

2. A circle is a closed shape in which every point of the enclosure is equidistant from a central point. This common distance between the center and the periphery is known as its radius. Important mathematical parameters associated with a circle can be calculated using the radius of the circle, as follows. Circumference of the circle is the linear distance along the circle boundary and is given by: ? × ? × ?????? Diameter of the circle is the length of a line passing through the center that has its end points on the boundary of the circle and is given by: ? × ?????? Area of the interior of the circle can be calculated using the formula: ? × ?????? × ?????? Create a Circle class with the class implementation in a file named circle.cpp and the class declaration in a file named circle.h (or circle.hpp) with  private data member for double parameter: ‘radius’  a default constructor which has no parameters  an overloaded constructor which takes in a single double parameter for ‘radius’  accessor and mutator for ‘radius’ named getRadius(…) and setRadius(…)  member functions to return doubles for calculated parameters: area( ), diameter( ) and circumference( )  PI should be assumed to be exactly 3.141592. You may define this as a static const double at the class scope, as a const double inside any method that uses it, or as a literal in the expression in which it’s used.

3. A triangle is a closed shape bound within three lines. For an acute angled triangle, the base and the height of the triangle are the important parameters, as seen in the following figure. Area inside the triangle can be calculated using the formula: ? ? × ???? × ??????. Create a Triangle class with the class implementation in a file named triangle.cpp and the class declaration in a file named triangle.h (or triangle.hpp) with  private data members for double parameters: ‘base’, ‘height’  a default constructor which has no parameters  an overloaded constructor which takes in a double parameter for ‘base’ followed by a double parameter for ‘height’  accessors and mutators for ‘base’ named getBase(…) and setBase(…), and ‘height’ named getHeight(…) and setHeight(…)  member function to return a double for calculated parameter: area( )

4. A rectangle is a closed shape bounded by parallel sides that meet at right angles, with the other condition that opposite sides are parallel and equal, but all sides are not equal. Typically. the longer side in a rectangle is known as its length and the shorter side is known as width. Important mathematical parameters associated with a circle can be calculated using the length and width values of the rectangle, as follows. Perimeter of the rectangle is the linear distance along the rectangle boundary and is given by: ? × (?????? × ?????) Diagonal of the rectangle is the length of a line joining opposite corners and is given (via the Pythagorean Theorem) by: √??????? × ?????? Area of the rectangle can be calculated using the formula: ?????? × ????? Create a Rectangle class with the class implementation in a file named rectangle.cpp and the class declaration in a file named rectangle.h (or rectangle.hpp) with  private data members for double parameters: ‘length’, ‘width’  a default constructor which has no parameters  an overloaded constructor which takes in a double parameter for ‘length’ followed by a double parameter for ‘width’  accessors and mutators for ‘length’ named getLength(…) and setLength(…), and ‘width’ named getWidth(…) and setWidth(…)  member functions to return a double for calculated parameters: area( ), diagonal( ) and perimeter( )  member function to return a bool for the state of the rectangle being square (its length is equal to its width) named isSquare(…)

5. Default constructors for all shapes should initialize the private data members to a value of unity (i.e. 1.0). Development Diary For this project, you must complete the following tasks in the order that they are described:

 [12 pts] Full-coverage test driver. Driver should call all functionality and print out the state of the object after each change to the internal state. This test driver should print the expected value and the actual result.

 [16 pts] Circle class fully implemented to the specifications provided in the problem description.

 [18 pts] Triangle class fully implemented to the specifications provided in the problem description.

 [24 pts] Rectangle class fully implemented to the specifications provided in the problem description.

 [14 pts] Sufficient and clear class divisions (with main() responsible for I/O only)

 [8 pts] Clear, easy-to-read code (e.g. class declarations in .h files, class definitions in .cpp files, working makefile, etc.) 

[8 pts] Development “diary” (report) that details design and implementation of each class, as well as the project as a whole. Should include a reflection of the process as a whole upon completion of the project (identify the challenges, lessons learned, ways to improve in the future, etc.)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;
#include <cmath>
class Circle{ //hpp
private:
//private
double radius;
const int PIE= 3.141592;
public:
//constructor
Circle();
Circle(double rad);
//mutators
void setRadius(double rad);
//accessors
double getRadius();
//other functions
double getDiameter();
double getArea();
double getCircumference();
};
Circle::Circle(){ //cpp file
radius=0.0;
}
Circle::Circle(double rad){
radius=rad;
}
void Circle::setRadius(double rad){
radius=rad;
}
double Circle::getRadius(){
return radius;
}
double Circle::getDiameter(){
return radius*2;
}
double Circle::getArea(){
return (PIE*(radius*radius));
}
double Circle::getCircumference(){
double circum= 2*(PIE*radius);
return circum;
}
class Rectangle{
private:
double length;
double width;
public:
Rectangle();
Rectangle(double l, double w);
void setLength(double l);
void setWidth(double w);
double getLength();
double getWidth();
double getArea();
double getDiagnol();
double getParameter();
bool isSquare();
};
Rectangle::Rectangle(){
length=0;
width=0;
}
Rectangle::Rectangle(double l, double w){
length=l;
width=w;
}
void Rectangle::setLength(double l){
length=l;
}
void Rectangle::setWidth(double w){
width=w;
}
double Rectangle::getLength(){
return length;
}
double Rectangle::getWidth(){
return width;
}
double Rectangle::getArea(){
return length*width;
}
double Rectangle::getDiagnol(){
double c=sqrt(length*length+width*width);
return c;
}

double Rectangle::getParameter(){
return 2*(length*width);
}
bool Rectangle::isSquare(){
if(length==width){
return true;
}
else {
return false;
}
}
class Triangle{
private:
double base;
double height;
public:
Triangle();
Triangle(double b, double h);
void setBase(double b);
void setHeight(double h);
double getBase();
double getHeight();
double getParameter();
double getArea();

};

Triangle::Triangle(){
base=0.0;
height=0.0;
}
Triangle::Triangle(double b, double h){
base=b;
height=h;
}
void Triangle::setBase(double b){
base =b;
}
void Triangle::setHeight(double h){
height=h;
}
double Triangle::getBase(){
return base;
}
double Triangle::getHeight(){
return height;
}
double Triangle::getParameter(){
double p;
p= (base+height)/2;
return p;
}
double Triangle::getArea(){
return (0.5)*(base*height);
}
int main()
{
Circle c(2.00);
cout<<"Circle"<<endl;
cout<<"Area: "<<c.getArea()<<endl;
cout<<"Circumference: "<<c.getCircumference()<<endl;
cout<<"Diameter: "<<c.getDiameter()<<endl;
cout<<endl;
Rectangle r(2.00,3.00);
cout<<"Rectangle"<<endl;
cout<<"Area: "<<r.getArea()<<endl;
cout<<"Parameter: "<<r.getParameter()<<endl;
cout<<"Diagonal: "<<r.getDiagnol()<<endl;
cout<<"Is Square: "<<r.isSquare()<<endl;
cout<<endl;
Triangle t(2.00,3.00);
cout<<"Triangle"<<endl;
cout<<"Area: "<<t.getArea()<<endl;
cout<<"Parameter: "<<t.getParameter()<<endl;

return 0;
}

OUTPUT:

IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW

PLEASE GIVE A THUMBS UP

Add a comment
Know the answer?
Add Answer to:
Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectang...

    java language Problem 3: Shape (10 points) (Software Design) Create an abstract class that represents a Shape and contains abstract method: area and perimeter. Create concrete classes: Circle, Rectangle, Triangle which extend the Shape class and implements the abstract methods. A circle has a radius, a rectangle has width and height, and a triangle has three sides. Software Architecture: The Shape class is the abstract super class and must be instantiated by one of its concrete subclasses: Circle, Rectangle, or...

  • Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The clas...

    Pure Abstract Base Class Project. Define a class called BasicShape which will be a pure abstract class. The class will have one protected data member that will be a double called area. It will provide a function called getArea which should return the value of the data member area. It will also provide a function called calcArea which must be a pure virtual function. Define a class called Circle. It should be a derived class of the BasicShape class. This...

  • You will be creating a driver class and 5 class files for this assignment. The classes...

    You will be creating a driver class and 5 class files for this assignment. The classes are Shape2D (the parent class), Circle, Triangle, and Rectangle (all children of Shape2D) and Square (child of Rectangle). Be sure to include a message to the user explaining the purpose of the program before any other printing to the screen. Within the driver class, please complete the following tasks: Instantiate a Circle object with 1 side and a radius of 4; print it Update...

  • I would like help and there are three different classes in the coding.. 14.11 Prog11 Inheritance(PayrollOvertime)...

    I would like help and there are three different classes in the coding.. 14.11 Prog11 Inheritance(PayrollOvertime) Create three files to submit: • Payroll class.java -Base class definition • PayrollOvertime.jave - Derived class definition • ClientClass.java - contains main() method Implement the two user define classes with the following specifications: Payroll class (the base class) (4 pts) • 5 data fields(protected) o String name - Initialized in default constructor to "John Doe" o int ID - Initialized in default constructor to...

  • Please write in dr java Here is the driver: import java.util.*; public class SquareDriver { public...

    Please write in dr java Here is the driver: import java.util.*; public class SquareDriver { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); String input =""; System.out.println("Welcome to the easy square program"); while(true) { System.out.println("Enter the length of the side of a square or enter QUIT to quit"); try { input = keyboard.nextLine(); if(input.equalsIgnoreCase("quit")) break; int length = Integer.parseInt(input); Square s = new Square(); s.setLength(length); s.draw(); System.out.println("The area is "+s.getArea()); System.out.println("The perimeter is "+s.getPerimeter()); } catch(DimensionException e)...

  • IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand...

    IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand the Application The assignment is to first create a class calledTripleString.TripleStringwill consist of threeinstance attribute strings as its basic data. It will also contain a few instance methods to support that data. Once defined, we will use it to instantiate TripleString objects that can be used in our main program. TripleString will contain three member strings as its main data: string1, string2, and string3....

  • Purpose: The purpose of this lab is for you to design and implement several classes that...

    Purpose: The purpose of this lab is for you to design and implement several classes that use Inheritance. The problem: The program must handle a collection of different 2-dimensional shapes: triangles, rectangles and circles. All shapes have a color (use a Stringl and are either filled or not (use a boolean). All shapes must calculate and return their perimeter, and area. toStrina) for all shapes must implement the standardized formatting for inheritance. You are required to implement each of the...

  • Project Objectives: To develop ability to write void and value returning methods and to call them...

    Project Objectives: To develop ability to write void and value returning methods and to call them -- Introduction: Methods are commonly used to break a problem down into small manageable pieces. A large task can be broken down into smaller tasks (methods) that contain the details of how to complete that small task. The larger problem is then solved by implementing the smaller tasks (calling the methods) in the correct order. This also allows for efficiencies, since the method can...

  • Using C++, this assignment uses two classes which utilize the concept of aggregation. One class will...

    Using C++, this assignment uses two classes which utilize the concept of aggregation. One class will be called TimeOff. This class makes use of another class called NumDays. Then you will create a driver (main) that will handle the personnel records for a company and generate a report. TimeOff class will keep track of an employee’s sick leave, vacation, and unpaid time off. It will have appropriate constructors and member functions for storing and retrieving data in any of the...

  • C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab...

    C++ Lab 9B Inheritance Class Production Worker Create a project C2010Lab9b; add a source file Lab9b.cpp to the project. Copy and paste the code is listed below: Next, write a class named ProductionWorker that is derived from the Employee class. The ProductionWorker class should have member variables to hold the following information: Shift (an integer) Hourly pay rate (a double) // Specification file for the ProductionWorker Class #ifndef PRODUCTION_WORKER_H #define PRODUCTION_WORKER_H #include "Employee.h" #include <string> using namespace std; class ProductionWorker...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT