Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question
  • Please write in your own original code. Example output is attached
  •  
  • Objective
    • Create a class hierarchy by defining an abstract Shape class and concrete classes pertaining to various shapes: CircleSphereCylinderSquareCubeTriangle and Tetrahedron.
  • Related SLO
    • Develop properly structured multifile programs with automatic compilation.
    • Use classes, polymorphism and inheritance in C++.
  • Instructions
    1. Download the following starter file: https://laulima.hawaii.edu/x/6rw8eB
      • Right-click on the link above > Save link as
    2. Rename LastnameFirstname22.cpp so that Lastname is your own last name and Firstname is your own first name.
    3. Create a makefile named makefile that will automatically compile, link, and create an executable for this assignment.
      • IMPORTANT: Be sure to use g++ as the compiler NOT gcc as we are now programming in C++.
      • Example makefile using g++ here
      • There are no extra .h or .cpp needed for this assignment.
      • Do NOT submit a makefile with any other name.
    4. The starter file contains code for an abstract class definition named Shape, a derived class definition named Circle, main() driver program, and example output.
    5. Here is what you need to do:
      1. From the abstract Shape class, derive concrete classes named Square and Triangle.
      2. From class Circle, derive concrete classes Sphere and Cylinder.
      3. From class Square, derive concrete class Cube.
      4. From class Triangle, derive concrete class Tetrahedron.
    6. Here is a visual representation of the class hierarchy: Shape / | \ / Square \ / | \ / Cube Triangle Circle \ / \ Tetrahedron / \ Sphere Cylinder
    7. The abstract Shape class defines the following virtual functions:
      1. virtual char* name() const - returns the name of the class
      2. virtual void printDetails() const - display the area, or surface area & volume of the object
      3. virtual void inputData() - ask the user for the radius, side, and/or height of the object and set the appropriate data member(s)
      4. virtual double area() const - returns the area or surface area of the object
      5. virtual double volume() const - returns the volume of the object
    8. For each derived class, implement all applicable virtual functions. Applicable meaning not all virtual functions will appear in all derived classes. For instance, Circle, Square, and Triangle will not have volume.
      1. Any data members that will be used in a child class should be declared as protected, for all other data members, use private.
      2. Error checking and correction is not required for the data members.
      3. After defining a class, do two things:
        1. Uncomment the line in main() for the corresponding class
        2. Increase the value of the NUM symbolic constant by 1
        The shape will be added to the menu array and the corresponding menu option will be shown when the program runs.
      4. Work in steps and define one class at a time and it ensure it works before moving on to the next.
    9. The calculations associated with each derived shape are as follows:
      These also give some indication of which virtual functions are implemented in each class.
      • π = 3.14
      • r = radius
      • s = side
      • Circle
        • circle's area = πr2
      • Sphere
        • sphere's surface area = 4πr2
        • sphere's volume = (4πr3) / 3
      • Cylinder
        • cylinder's surface area = 2πrh + 2πr2
        • cylinder's volume = πr2h
      • Square
        • square's area = s2
      • Cube
        • cube's surface area = 6s2
        • cube's volume = s3
      • Triangle
        • equilateral triangle's area = s* sqrt(3)/4
      • Tetrahedron
        • regular tetrahedron's surface area = s* sqrt(3)
        • regular tetrahedron's volume = s3 * sqrt(2)/12
      • For square root, use the sqrt() function, the starter file already has the necessary include.
    10. Be sure to have the usual program header at the top that contains the program description, author information, etc.
      Comments are not required for this assignment other than the description at the top.
    11. NOTE: The main error students make with this assignment is to repeat data unnecessarily. The point of inheritance is to be a "lazy" programmer and not re-invent the wheel. For example, if the base class Circle has a radius protected data member, the derived class Sphere does NOT need a radius because it already inherited radius from Circle. Keep this concept in mind when writing your code.
Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
0
Enter the Circle's radius: 10
The Circle's area = 314
Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
1
Enter the Sphere's radius: 20
The Sphere's surface area = 5024
The Sphere's volume = 33493.3
Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
2
Enter the Cylinder's radius: 30
Enter the Cylinder's height: 40
The Cylinder's surface area = 13188
The Cylinder's volume = 113040
Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
3
Enter the Square's side: 50
The Square's area = 2500
Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
expand button
Transcribed Image Text:Select an object from the menu (enter 7 to quit). 0. Circle 1. Sphere 2. Cylinder 3. Square 4. Cube 5. Triangle 6. Tetrahedron 0 Enter the Circle's radius: 10 The Circle's area = 314 Select an object from the menu (enter 7 to quit). 0. Circle 1. Sphere 2. Cylinder 3. Square 4. Cube 5. Triangle 6. Tetrahedron 1 Enter the Sphere's radius: 20 The Sphere's surface area = 5024 The Sphere's volume = 33493.3 Select an object from the menu (enter 7 to quit). 0. Circle 1. Sphere 2. Cylinder 3. Square 4. Cube 5. Triangle 6. Tetrahedron 2 Enter the Cylinder's radius: 30 Enter the Cylinder's height: 40 The Cylinder's surface area = 13188 The Cylinder's volume = 113040 Select an object from the menu (enter 7 to quit). 0. Circle 1. Sphere 2. Cylinder 3. Square 4. Cube 5. Triangle 6. Tetrahedron 3 Enter the Square's side: 50 The Square's area = 2500 Select an object from the menu (enter 7 to quit). 0. Circle 1. Sphere 2. Cylinder 3. Square 4. Cube 5. Triangle 6. Tetrahedron
4
Enter the Cube's side: 60
The Cube's surface area = 21600
The Cube's volume = 216000
Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
5
Enter the Triangle's side: 70
The Triangle's area = 2121.76
Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
6
Enter the Tetrahedron's side: 80
The Tetrahedron's surface area = 11085.1
The Tetrahedron's volume = 60339.8
Select an object from the menu (enter 7 to quit).
0. Circle
1. Sphere
2. Cylinder
3. Square
4. Cube
5. Triangle
6. Tetrahedron
expand button
Transcribed Image Text:4 Enter the Cube's side: 60 The Cube's surface area = 21600 The Cube's volume = 216000 Select an object from the menu (enter 7 to quit). 0. Circle 1. Sphere 2. Cylinder 3. Square 4. Cube 5. Triangle 6. Tetrahedron 5 Enter the Triangle's side: 70 The Triangle's area = 2121.76 Select an object from the menu (enter 7 to quit). 0. Circle 1. Sphere 2. Cylinder 3. Square 4. Cube 5. Triangle 6. Tetrahedron 6 Enter the Tetrahedron's side: 80 The Tetrahedron's surface area = 11085.1 The Tetrahedron's volume = 60339.8 Select an object from the menu (enter 7 to quit). 0. Circle 1. Sphere 2. Cylinder 3. Square 4. Cube 5. Triangle 6. Tetrahedron
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education