cube.cpp 1 #include "cube.h" 2 3 4 5 cube.h 1 2 3 4 6 7 8 9 Tester.cpp 9 10 11 12 13 14 15 16 17 1 #include 2 #include 3 using namespace std; 4 5 #include "cube.h" 6 7 8 18 19 #ifndef CUBE H #define CUBE H 20 21 // Write your functions here #endif int main() { } cout << "cube (2.5): << cube (2.5) << endl; cout << "Expected: 15.625" << endl; cout << "cube (7): " << cube (7) << endl; cout << "Expected: 343" << endl; "1 cout << "cube (9.8): << cube (9.8) << endl; cout << "Expected: 941.1920000000002" << endl; cout << "cube (5.9): " << cube (5.9) << endl; cout << "Expected: 205.37900000000002" << endl; cout << "cube (9): << cube (9) << endl; cout << "Expected: 729" << endl; "I cout << "cube (2): " << cube (2) << endl; cout << "Expected: 8" << endl;

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Need some help writing functions for this problem.

Write a pair of functions cube which return the cube of their arguments.

## C++ Code Implementation

This example illustrates the basic use of C++ header and source files to calculate the cube of different numbers. The project consists of three files: `cube.cpp`, `cube.h`, and `Tester.cpp`.

### cube.cpp

```cpp
#include "cube.h"

// Write your functions here
```

This is the source file where functions are to be implemented. Currently, it includes `cube.h`, but the function definitions are to be added by the user.

### cube.h

```cpp
#ifndef CUBE_H
#define CUBE_H

#endif
```

This is the header file using include guards (`#ifndef`, `#define`, `#endif`) to prevent multiple inclusions. It's set up to be expanded with function declarations.

### Tester.cpp

```cpp
#include <iostream>
#include <iomanip>
using namespace std;

#include "cube.h"

int main()
{
    cout << "cube(2.5): " << cube(2.5) << endl;
    cout << "Expected: 15.625" << endl;
    cout << "cube(7): " << cube(7) << endl;
    cout << "Expected: 343" << endl;
    cout << "cube(9.8): " << cube(9.8) << endl;
    cout << "Expected: 941.1920000000002" << endl;
    cout << "cube(5.9): " << cube(5.9) << endl;
    cout << "Expected: 205.37900000000002" << endl;
    cout << "cube(9): " << cube(9) << endl;
    cout << "Expected: 729" << endl;
    cout << "cube(2): " << cube(2) << endl;
    cout << "Expected: 8" << endl;
}
```

This file performs several tests to calculate the cube of various numbers using a function expected to be defined in `cube.cpp`. It includes:

- `#include <iostream>` and `#include <iomanip>` for basic input/output and formatting.
- Multiple `cout` statements to display calculated cube values along with their expected results.

### Explanation

- **Headers and Guards**: The header guard in `cube.h` helps in preventing the file from being included multiple times, which can lead to errors.
- **Main Function**: The `main` function in `Tester
Transcribed Image Text:## C++ Code Implementation This example illustrates the basic use of C++ header and source files to calculate the cube of different numbers. The project consists of three files: `cube.cpp`, `cube.h`, and `Tester.cpp`. ### cube.cpp ```cpp #include "cube.h" // Write your functions here ``` This is the source file where functions are to be implemented. Currently, it includes `cube.h`, but the function definitions are to be added by the user. ### cube.h ```cpp #ifndef CUBE_H #define CUBE_H #endif ``` This is the header file using include guards (`#ifndef`, `#define`, `#endif`) to prevent multiple inclusions. It's set up to be expanded with function declarations. ### Tester.cpp ```cpp #include <iostream> #include <iomanip> using namespace std; #include "cube.h" int main() { cout << "cube(2.5): " << cube(2.5) << endl; cout << "Expected: 15.625" << endl; cout << "cube(7): " << cube(7) << endl; cout << "Expected: 343" << endl; cout << "cube(9.8): " << cube(9.8) << endl; cout << "Expected: 941.1920000000002" << endl; cout << "cube(5.9): " << cube(5.9) << endl; cout << "Expected: 205.37900000000002" << endl; cout << "cube(9): " << cube(9) << endl; cout << "Expected: 729" << endl; cout << "cube(2): " << cube(2) << endl; cout << "Expected: 8" << endl; } ``` This file performs several tests to calculate the cube of various numbers using a function expected to be defined in `cube.cpp`. It includes: - `#include <iostream>` and `#include <iomanip>` for basic input/output and formatting. - Multiple `cout` statements to display calculated cube values along with their expected results. ### Explanation - **Headers and Guards**: The header guard in `cube.h` helps in preventing the file from being included multiple times, which can lead to errors. - **Main Function**: The `main` function in `Tester
Expert Solution
Step 1

A pair of functions cube which returns the cube of their arguments.

Solution :


#include <"cube.h"> 
//cube() function 
int cube(int num) {
    int c;
    c=num*num*num;
    return c;
    } 
    //cube() function 
    double cube(double num) { 
        double c;
    c=num*num*num;
    return c;
    }

 

 
steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
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.
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education