Question
(((
Using Only The mentioned Concepts Solve the following question in DETAILS “ Take your time but don’t disappoint me plleeaasseee”:
1- Control structure (if/if else/while/for/switch/do while/ break continue)
2- Functions
3- Arrays
4- pointers and strings
5- classes
6- file processing
)))
if it was a program i need to see the code printed on computer and the output too please .
10. Write a C++code that include two classes: Rectangle and Triangle as shown below: #include <iostream> using namespace std;
height- h; private: double height; double base; Write the class function members details, then use these classes to compare t
10. Write a C++code that include two classes: Rectangle and Triangle as shown below: #include using namespace std; KUWAIT UNIVERSITY Name Computer Engineering Department ENG-200: Programming Language for Engineers Review Questions for the Final-SPRING 2019 Dr. Ayed Salman class rectangle public double getarea return width length void setwidth (double w) width w void setlength (double I) length ; private double width; double length; class triangle public: double getarea 0 return base height 05 void setbase (double b) bases b% void setheight (double h)
height- h; private: double height; double base; Write the class function members details, then use these classes to compare the distance between a rectangle with height 10 cm, width 20 cm, and a triangle with base 20 cm and height 15 cm.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Note: Could you plz go through this code and let me know if u need any changes in this.Thank You
_________________

#include <iostream>
#include <iomanip>
#include <ctime>
#include <cstdlib>
using namespace std;

class rectangle
{
private :
double width;
   double length;  
public :  
rectangle(double width,double length)
{
    this->width=width;
    this->length=length;
   }
   double getArea()
   {
      return width*length;
   }
   void setLength(double len)
   {
      this->length=len;
   }
   void setWidth(double wid)
   {
      this->width=wid;
   }
   double getLength()
   {
      return length;
   }
   double getWidth()
   {
      return width;
   }
     
  
};


class triangle
{
private :
   double base;
   double height;
public :  
triangle(double base,double height)
{
   this->base=base;
   this->height=height;
   }
   double getArea()
   {
       return 0.5*base*height;
   }
   void setBase(double b)
   {
       this->base=b;
   }
   void setHeight(double h)
   {
       this->height=h;
   }
   double getHeight()
   {
       return height;
   }
   double getBase()
   {
       return base;
   }
};
int main()
{
rectangle r(10,20);
cout<<"Area of rectangle:"<<r.getArea()<<endl;
  
triangle t(20,15);
cout<<"Area of triangle:"<<t.getArea()<<endl;

return 0;
}

_______________________

Output:

CAProgram Files (x86ハDev-CppMínGw64binRectangleTriangleclassesArea.exe Area of rectangle :200 Area of triangle :150 rocess ex

_________________________Thank You

Add a comment
Know the answer?
Add Answer to:
((( Using Only The mentioned Concepts Solve the following question in DETAILS “ Take your time but don’t disappoint me plleeaasseee”: 1- Control structure (if/if else/while/for/switch/do while/ brea...
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
  • Hello I have a question. I would like to check if the code follows this requirement....

    Hello I have a question. I would like to check if the code follows this requirement. Rectangle.h - A complete Rectangle Class including both declaration and definition appRectangle,cpp separate in two different files the class definition and implementation Code: rectangle.h // Rectangle class declaration. class Rectangle { private: double width; double length; public: void setWidth(double); void setLength(double); double getWidth() const; double getLength() const; double getArea() const; }; //************************************************** // setWidth assigns a value to the width member. * //************************************************** void...

  • Create a Java Project in Eclipse with the following: Include the Rectangle class supplied below. Override...

    Create a Java Project in Eclipse with the following: Include the Rectangle class supplied below. Override the toString method for Rectangle. Override the equals method for Rectangle. Implement the comparable Interface for Rectangle (Compare by area) Rectangle class: public class Rectangle {       private double length;    private double width;       public Rectangle(double l, double w)    {        length = l;        width = w;    }       public double getLength()    {   ...

  • m The interface Measurable is defined as the following: /** An interface for methods that return...

    m The interface Measurable is defined as the following: /** An interface for methods that return the perimeter and area of an object. */ public interface Measurable { public double getPerimeter(); public double getArea(); } The class Rectangle implements the interface. The incomplete program is written as follows: 1 public class Rectangle 2 { private double width; private double height; public Rectangle(double w, double h) { width = w; height h; } { 3 4 5 6 7 8 9...

  • 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...

  • I need help with a java error Question: Consider a graphics system that has classes for...

    I need help with a java error Question: Consider a graphics system that has classes for various figures—say, rectangles, boxes, triangles, circles, and so on. For example, a rectangle might have data members’ height, width, and center point, while a box and circle might have only a center point and an edge length or radius, respectively. In a well-designed system, these would be derived from a common class, Figure. You are to implement such a system. The class Figure is...

  • C++ Practice: Answer Whichever you can & it'll help a lot. Thank you! Question 1. Implement...

    C++ Practice: Answer Whichever you can & it'll help a lot. Thank you! Question 1. Implement the constructors and member function of each of the classes (Marks 15) class Fraction{ private: int numerator; int denominator; public: Fraction(int, int); float fractionValue();//determines the value of numerator/denominator }; class Problem{ private: Fraction f[3]; public: Problem(int, int, int, int, int, int); Fraction largestFraction();//Returns the fraction having largest fraction value }; Question 2: In the following Inheritance problem #include<iostream> #include<string> using namespace std; class Animal{...

  • JAVA PROGRAM USING ECLIPSE. THE FIRST IMAGE IS THE INSTRUCTIONS, THE SECOND IS THE OUTPUT TEST...

    JAVA PROGRAM USING ECLIPSE. THE FIRST IMAGE IS THE INSTRUCTIONS, THE SECOND IS THE OUTPUT TEST CASES(WHAT IM TRYING TO PRODUCE) BELOW THOSE IMAGES ARE THE .JAVA FILES THAT I HAVE CREATED. THESE ARE GeometircObject.Java,Point.java, and Tester.Java. I just need help making the Rectangle.java and Rectangle2D.java classes. GeometricObject.Java: public abstract class GeometricObject { private String color = "white"; // shape color private boolean filled; // fill status protected GeometricObject() { // POST: default shape is unfilled blue this.color = "blue";...

  • Question 1 1 pts Which of the following is not a valid class name in Java?...

    Question 1 1 pts Which of the following is not a valid class name in Java? O MyClass MyClass1 My_Class MyClass# Question 2 1 pts Which of the following statements is False about instance variables and methods? Instance variables are usually defined with private access modifier. Instance variables are defined inside instance methods. Instance methods are invoked on an object of the class that contains the methods. A class can have more than one instance variables and methods. Question 3...

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