
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
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: Circle, Sphere, Cylinder, Square, Cube, Triangle and Tetrahedron.
- Related SLO
- Develop properly structured multifile programs with automatic compilation.
- Use classes, polymorphism and inheritance in C++.
- Instructions
- Download the following starter file: https://laulima.hawaii.edu/x/6rw8eB
- Right-click on the link above > Save link as
- Rename LastnameFirstname22.cpp so that Lastname is your own last name and Firstname is your own first name.
- 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.
- The starter file contains code for an abstract class definition named Shape, a derived class definition named Circle, main() driver program, and example output.
- Here is what you need to do:
- From the abstract Shape class, derive concrete classes named Square and Triangle.
- From class Circle, derive concrete classes Sphere and Cylinder.
- From class Square, derive concrete class Cube.
- From class Triangle, derive concrete class Tetrahedron.
- Here is a visual representation of the class hierarchy: Shape / | \ / Square \ / | \ / Cube Triangle Circle \ / \ Tetrahedron / \ Sphere Cylinder
- The abstract Shape class defines the following virtual functions:
- virtual char* name() const - returns the name of the class
- virtual void printDetails() const - display the area, or surface area & volume of the object
- virtual void inputData() - ask the user for the radius, side, and/or height of the object and set the appropriate data member(s)
- virtual double area() const - returns the area or surface area of the object
- virtual double volume() const - returns the volume of the object
- 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.
- Any data members that will be used in a child class should be declared as protected, for all other data members, use private.
- Error checking and correction is not required for the data members.
- After defining a class, do two things:
- Uncomment the line in main() for the corresponding class
- Increase the value of the NUM symbolic constant by 1
- Work in steps and define one class at a time and it ensure it works before moving on to the next.
- 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 = s2 * sqrt(3)/4
- Tetrahedron
- regular tetrahedron's surface area = s2 * 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.
- 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. - 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.

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

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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 2 steps

Knowledge Booster
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
- Implement a nested class composition relationship between any two class types from the following list: Advisor Вook Classroom Department Friend Grade School Student Teacher Tutor Write all necessary code for both classes to demonstrate a nested composition relationship including the following: a. one encapsulated data member for each class b. inline default constructor using constructor delegation for each class c. inline one-parameter constructor for each class d. inline accessors for all data members e. inline mutators for all data membersarrow_forward!! E! 4 2 You are in process of writing a class definition for the class Book. It has three data attributes: book title, book author, and book publisher. The data attributes should be private. In Python, write an initializer method that will be part of your class definition. The attributes will be initialized with parameters that are passed to the method from the main program. Note: You do not need to write the entire class definition, only the initializer method lili lilıarrow_forwardIn C++ Create a new project named lab8_1. You will be implementing two classes: A Book class, and a Bookshelf class. The Bookshelf has a Book object (actually 3 of them). You will be able to choose what Book to place in each Bookshelf. Here are their UML diagrams Book class UML Book - author : string- title : string- id : int- count : static int + Book()+ Book(string, string)+ setAuthor(string) : void+ setTitle(string) : void+ print() : void+ setID() : void And the Bookshelf class UML Bookshelf - book1 : Book- book2 : Book- book3 : Book + Bookshelf()+ Bookshelf(Book, Book, Book)+ setBook1(Book) : void+ setBook2(Book) : void+ setBook3(Book) : void+ print() : void Some additional information: The Book class also has two constructors, which again offer the option of declaring a Book object with an author and title, or using the default constructor to set the author and title later, via the setters . The Book class will have a static member variable…arrow_forward
- create a class in python with a constructor To create instances of the user defined class and practice applying them. Practice implementing loops. Part 1 Instructions:Create a class called BankAccount with the following variables: balancenameaccount_id Create 1 constructor for the class BankAccount (with or without parameters, your choice, but only 1): def __init_(self, name, account_id, balance)def __init_(self) Create the following methods in the BankAccount class: def viewAccountInfo() //prints all account information def withdraw(self, amount) //withdraws from the balance def deposit(self, amount) //deposits to the balance Your task after your class has been created: Create two objects, "personal" and "joint_account"with initial balances of:personal = $1000joint_account = $3000Use the constructor to create the objects. Create a program that prompts the user which account they would like to access personal or jointWhich account would you like to access? 1. Personal2. Joint…arrow_forwardInheritance and polmorphism: In Java, Using Classes, desine an online address book to keep track of the names , addresses phone numbers, and birthdays of family members, close friends, and certain business associates. Your program should be able to handle a maximum of 500 entries. A. Define the class Address that can store a street address, city, state, and zip code. Use the appropriae methods to print and store the address. Also, use consructors to automatically initialize the data members. B. Define the class ExtPerson using the class Person (designed in chapter 8, example 8-8), the class Date, and the class Address. Add a data member to the class to claddify the person as a family member, friend, or business associate. Also, add a data member to store the phone number. Add (or override) methods to print and store the appropriate informatiom. Use constructors to automatically omotoa;ize the data members. C. Define the class AddressBook using previously defined classes. An object of…arrow_forwardPLEASE CODE IN PYTHON PLEASE USE THE CLASS FUNCTION A sphere is a geometric shape that could be compared to a ball. Create an Sphere class given the following design: A sphere has a radius, referred to as r, which extends from the center to the surface. The volume of a sphere is computed as 4πr^3/3 The surface area of a sphere is computed as 4πr2 Write appropriate client code to test the class.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education